Skip to content

armgit / cindy

Public Imported from GitHub
0

Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。

fix(mobile): preserve usable workspace popup space near the keyboard

david59810351eb5f
diff --git a/apps/mobile/app/sessions/new.tsx b/apps/mobile/app/sessions/new.tsx
index 9242f0d75e..a6891479d1 100644
--- a/apps/mobile/app/sessions/new.tsx
+++ b/apps/mobile/app/sessions/new.tsx
@@ -7,6 +7,7 @@ import { stripTrailingPathSeparators } from '@cindy/maker-shared/path-text';
import { takeRefinementContextTail } from '@cindy/voice-input-core';
import { Stack, useIsFocused, useLocalSearchParams, useRouter } from 'expo-router';
import { NewTaskSelectionSheet } from '@/session/NewTaskSelectionSheet';
+import { resolveWorkspacePickerFrame, type WorkspacePickerFrame } from '@/session/workspacePickerPlacement';
import { simpleScreenSafeAreaEdges } from '@/platform/chrome/SimpleStackHeader';
import Constants from 'expo-constants';
import { MOBILE_VISUAL_MOCK_ENABLED } from '@/config/env';
@@ -546,17 +547,16 @@ export default function NewRemoteSessionScreen() {
const [workspacePickerOpen, setWorkspacePickerOpen] = useState(false);
const workspacePickerHostRef = useRef<View>(null);
const workspacePickerAnchorRef = useRef<View>(null);
- const [workspacePickerFrame, setWorkspacePickerFrame] = useState<{
- left: number; bottom: number; width: number; maxHeight: number;
- } | null>(null);
+ const [workspacePickerFrame, setWorkspacePickerFrame] = useState<WorkspacePickerFrame | null>(null);
const measureWorkspacePicker = useCallback(() => {
if (nativeSelectionSheet || !workspacePickerOpen) return;
- workspacePickerAnchorRef.current?.measureInWindow((x, y, width) => {
- workspacePickerHostRef.current?.measureInWindow((hostX, hostY, _width, height) => {
- setWorkspacePickerFrame({
- left: x - hostX, bottom: hostY + height - y, width,
- maxHeight: Math.max(0, y - hostY - spacing.xs),
- });
+ workspacePickerAnchorRef.current?.measureInWindow((x, y, width, height) => {
+ workspacePickerHostRef.current?.measureInWindow((hostX, hostY, hostWidth, hostHeight) => {
+ setWorkspacePickerFrame(resolveWorkspacePickerFrame(
+ { x, y, width, height },
+ { x: hostX, y: hostY, width: hostWidth, height: hostHeight },
+ spacing.xs,
+ ));
});
});
}, [nativeSelectionSheet, workspacePickerOpen]);
@@ -5499,7 +5499,7 @@ export default function NewRemoteSessionScreen() {
)}
style={styles.keyboard}
>
- <View ref={workspacePickerHostRef} collapsable={false} onLayout={measureWorkspacePicker} style={styles.screen}>
+ <View style={styles.screen}>
{Platform.OS !== 'ios' || buildLabel || creating ? <View style={styles.topBar}>
{Platform.OS !== 'ios' ? <ScreenBackButton
hitSlop={12}
@@ -5513,6 +5513,7 @@ export default function NewRemoteSessionScreen() {
{creating ? <ActivityIndicator color={colors.textSecondary} /> : null}
</View> : null}
+ <View ref={workspacePickerHostRef} collapsable={false} onLayout={measureWorkspacePicker} style={{ flex: 1 }}>
<ScrollView style={{ flex: 1 }} contentContainerStyle={styles.bottomCluster}
onScrollBeginDrag={() => setWorkspacePickerOpen(false)}
keyboardShouldPersistTaps="handled" showsVerticalScrollIndicator={false}>
@@ -6012,6 +6013,12 @@ export default function NewRemoteSessionScreen() {
{/* Keep the floating panel inside its native touch bounds on Android. */}
{!nativeSelectionSheet && workspacePickerOpen && workspacePickerFrame ? (
<View style={[styles.workspacePickerPanel, workspacePickerFrame]} testID="newSession.workspacePickerPanel">
+ <ScrollView
+ nestedScrollEnabled
+ keyboardShouldPersistTaps="handled"
+ showsVerticalScrollIndicator
+ style={styles.workspaceProjectList}
+ >
<Pressable
accessibilityLabel={t('session.new.dialogueNoProject')}
accessibilityRole="button"
@@ -6028,12 +6035,7 @@ export default function NewRemoteSessionScreen() {
</Pressable>
<View style={styles.workspacePickerDivider} />
{recentWorkspaces.length > 0 ? (
- <ScrollView
- nestedScrollEnabled
- keyboardShouldPersistTaps="handled"
- showsVerticalScrollIndicator
- style={styles.workspaceProjectList}
- >
+ <View>
{recentWorkspaces.map((workspace) => {
const selected = draft.workspaceKind === 'project'
&& draft.workingDir.trim() === workspace.workingDir;
@@ -6059,7 +6061,7 @@ export default function NewRemoteSessionScreen() {
</Pressable>
);
})}
- </ScrollView>
+ </View>
) : (
<Text style={styles.workspaceEmptyText}>{t('session.new.noProjects')}</Text>
)}
@@ -6075,8 +6077,10 @@ export default function NewRemoteSessionScreen() {
<FolderPlus color={colors.textSecondary} size={iconSize.action} strokeWidth={iconStroke.regular} />
<Text style={styles.workspaceOptionText} numberOfLines={1}>{t('session.new.chooseOtherFolder')}</Text>
</Pressable>
+ </ScrollView>
</View>
) : null}
+ </View>
</View>
</ComposerKeyboardAvoidingView>
<ContextSheet
@@ -6589,12 +6593,11 @@ const makeStyles = (colors: ThemeColors) => StyleSheet.create({
zIndex: 20,
},
workspacePickerPanel: {
- // Anchored above the selector in the screen's native touch hierarchy.
+ // Positioned within the visible content host, outside the page ScrollView.
backgroundColor: colors.surfaceElevated,
borderColor: colors.border,
borderRadius: radius.container,
borderWidth: StyleSheet.hairlineWidth,
- marginBottom: spacing.xs,
padding: spacing.xs,
position: 'absolute',
zIndex: 20,
@@ -6607,7 +6610,6 @@ const makeStyles = (colors: ThemeColors) => StyleSheet.create({
},
workspaceProjectList: {
flexShrink: 1,
- maxHeight: 220,
},
workspaceOptionRow: {
alignItems: 'center',
diff --git a/apps/mobile/src/__tests__/newSession.test.ts b/apps/mobile/src/__tests__/newSession.test.ts
index ae882f7b10..debe18fd28 100644
--- a/apps/mobile/src/__tests__/newSession.test.ts
+++ b/apps/mobile/src/__tests__/newSession.test.ts
@@ -1383,6 +1383,38 @@ describe('new session model', () => {
expect(ancestors.map(node => node.openingElement.tagName.getText(source)))
.not.toContain('ScrollView');
expect(ancestors[0].openingElement.getText(source)).toContain('ref={workspacePickerHostRef}');
+ expect(ancestors[0].getText(source)).not.toContain('testID="newSession.backButton"');
+ });
+
+ it('scrolls every workspace action together so fixed rows cannot consume a short viewport', () => {
+ const source = ts.createSourceFile('new.tsx', readTextLf(
+ resolve(process.cwd(), 'app/sessions/new.tsx'), 'utf8',
+ ), ts.ScriptTarget.Latest, true, ts.ScriptKind.TSX);
+ const actionIds = new Set([
+ 'newSession.workspaceDialogueOption',
+ 'newSession.workspaceProjectOption',
+ 'newSession.workspaceBrowseOption',
+ ]);
+ const scrollParents: ts.JsxElement[] = [];
+ const visit = (node: ts.Node) => {
+ if (ts.isJsxElement(node) && node.openingElement.attributes.properties.some(
+ prop => ts.isJsxAttribute(prop) && prop.name.getText(source) === 'testID'
+ && prop.initializer && ts.isStringLiteral(prop.initializer)
+ && actionIds.has(prop.initializer.text),
+ )) {
+ for (let parent = node.parent; parent; parent = parent.parent) {
+ if (ts.isJsxElement(parent) && parent.openingElement.tagName.getText(source) === 'ScrollView') {
+ scrollParents.push(parent);
+ break;
+ }
+ }
+ }
+ ts.forEachChild(node, visit);
+ };
+ visit(source);
+ expect(scrollParents).toHaveLength(3);
+ expect(new Set(scrollParents).size).toBe(1);
+ expect(scrollParents[0].openingElement.getText(source)).toContain('styles.workspaceProjectList');
});
it('builds recent workspace quick picks from mirrored remote sessions', () => {
diff --git a/apps/mobile/src/__tests__/workspacePickerPlacement.test.ts b/apps/mobile/src/__tests__/workspacePickerPlacement.test.ts
new file mode 100644
index 0000000000..4be9619a3a
--- /dev/null
+++ b/apps/mobile/src/__tests__/workspacePickerPlacement.test.ts
@@ -0,0 +1,61 @@
+import { describe, expect, it } from 'vitest';
+import { resolveWorkspacePickerFrame } from '@/session/workspacePickerPlacement';
+
+const host = { x: 16, y: 112, width: 380, height: 700 };
+const anchor = { x: 24, y: 712, width: 364, height: 44 };
+
+describe('workspace picker placement (#5013)', () => {
+ it('keeps the popup above a low anchor and aligned to its measured width', () => {
+ expect(resolveWorkspacePickerFrame(anchor, host, 4)).toEqual({
+ left: 8, width: 364, bottom: 104, maxHeight: 336,
+ });
+ });
+
+ it('opens below a selector near the top bar instead of collapsing the list', () => {
+ const frame = resolveWorkspacePickerFrame({ ...anchor, y: host.y + 20 }, host, 4);
+ expect(frame.top).toBe(68);
+ expect(frame.maxHeight).toBe(336);
+ expect(frame.bottom).toBeUndefined();
+ });
+
+ it('uses the visible host when an expanded composer leaves neither side large enough', () => {
+ const frame = resolveWorkspacePickerFrame(
+ { ...anchor, y: host.y + 140 }, { ...host, height: 300 }, 4,
+ );
+ expect(frame.top).toBe(4);
+ expect(frame.maxHeight).toBe(292);
+ });
+
+ it('gives the entire viewport to scrollable options even below fixed-action height', () => {
+ const frame = resolveWorkspacePickerFrame(
+ { ...anchor, y: host.y + 24 }, { ...host, height: 100 }, 4,
+ );
+ expect(frame.top).toBe(4);
+ expect(frame.maxHeight).toBe(92);
+ });
+
+ it('repositions after keyboard resize without retaining an obsolete bottom offset', () => {
+ const before = resolveWorkspacePickerFrame(anchor, host, 4);
+ const after = resolveWorkspacePickerFrame(
+ { ...anchor, y: host.y + 12 }, { ...host, height: 420 }, 4,
+ );
+ expect(before.bottom).toBeDefined();
+ expect(after.bottom).toBeUndefined();
+ expect(after.top).toBe(60);
+ expect(after.maxHeight).toBe(336);
+ });
+
+ it('stays below the top bar and above the keyboard for scrolled and offscreen anchors', () => {
+ for (const height of [80, 180, 300, 420, 700]) {
+ for (const offset of [-80, 0, 20, height / 2, height - 44, height + 80]) {
+ const frame = resolveWorkspacePickerFrame(
+ { ...anchor, y: host.y + offset }, { ...host, height }, 4,
+ );
+ const top = frame.top ?? height - frame.bottom! - frame.maxHeight;
+ expect(top).toBeGreaterThanOrEqual(4);
+ expect(top + frame.maxHeight).toBeLessThanOrEqual(height - 4);
+ expect(frame.maxHeight).toBeGreaterThanOrEqual(72);
+ }
+ }
+ });
+});
diff --git a/apps/mobile/src/session/workspacePickerPlacement.ts b/apps/mobile/src/session/workspacePickerPlacement.ts
new file mode 100644
index 0000000000..6d324a7e96
--- /dev/null
+++ b/apps/mobile/src/session/workspacePickerPlacement.ts
@@ -0,0 +1,45 @@
+interface WindowRect {
+ x: number;
+ y: number;
+ width: number;
+ height: number;
+}
+
+export interface WorkspacePickerFrame {
+ left: number;
+ width: number;
+ top?: number;
+ bottom?: number;
+ maxHeight: number;
+}
+
+// Includes the two action rows, separators and the usual recent-project viewport.
+export const WORKSPACE_PICKER_MAX_HEIGHT = 336;
+
+/** Host is the visible content area below the top bar and above the keyboard. */
+export function resolveWorkspacePickerFrame(
+ anchor: WindowRect,
+ host: WindowRect,
+ gap: number,
+): WorkspacePickerFrame {
+ const viewportHeight = Math.max(0, host.height - gap * 2);
+ const maxHeight = Math.min(WORKSPACE_PICKER_MAX_HEIGHT, viewportHeight);
+ const anchorTop = Math.max(0, Math.min(anchor.y - host.y, host.height));
+ const anchorBottom = Math.max(0, Math.min(anchor.y - host.y + anchor.height, host.height));
+ const above = anchorTop - gap * 2;
+ const below = host.height - anchorBottom - gap * 2;
+ const horizontal = { left: anchor.x - host.x, width: anchor.width, maxHeight };
+
+ if (above >= maxHeight) {
+ return { ...horizontal, bottom: host.height - anchorTop + gap };
+ }
+ if (below >= maxHeight) {
+ return { ...horizontal, top: anchorBottom + gap };
+ }
+ // Neither side fits: shift within the visible host, rather than shrinking to
+ // the sliver above the anchor. All options share one scrollable viewport.
+ return {
+ ...horizontal,
+ top: Math.max(gap, Math.min(anchorTop - gap - maxHeight, host.height - gap - maxHeight)),
+ };
+}