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): 新建任务兼容双栏布局并对齐顶部按钮

Dashdde4f5e6d60b
diff --git a/apps/mobile/app/sessions/new.tsx b/apps/mobile/app/sessions/new.tsx
index f00b676955..e3ecac8fd9 100644
--- a/apps/mobile/app/sessions/new.tsx
+++ b/apps/mobile/app/sessions/new.tsx
@@ -52,6 +52,10 @@ import { Stack, useIsFocused, useLocalSearchParams, useNavigation, useRouter } f
import { NewTaskSelectionSheet } from '@/session/NewTaskSelectionSheet';
import { resolveWorkspacePickerFrame, type WorkspacePickerFrame } from '@/session/workspacePickerPlacement';
import { simpleScreenSafeAreaEdges } from '@/platform/chrome/SimpleStackHeader';
+import { NativeChromeBackButton } from '@/platform/chrome/NativeChromeBackButton';
+import { SystemNavigationBack, useSystemNavigationBack } from '@/platform/chrome/SystemNavigationBack';
+import { NewSessionLayout } from '@/session/NewSessionLayout';
+import { useSessionPaneLayout } from '@/session/ResidentHomeList';
import { readComposerEntry, useComposerDock } from '@/session/composerMorph';
import { useComposerPillOpen } from '@/session/useComposerPillOpen';
import { useComposerImageExpansion } from '@/session/useComposerImageExpansion';
@@ -472,9 +476,16 @@ interface WorktreeBranchCompatibilitySelection {
}
export default function NewRemoteSessionScreen() {
+ return <NewSessionLayout><NewRemoteSessionContent /></NewSessionLayout>;
+}
+
+function NewRemoteSessionContent() {
const styles = useThemedStyles(makeStyles);
const { colors } = useTheme();
const { t, i18n: i18nInstance } = useTranslation();
+ const paneLayout = useSessionPaneLayout();
+ const systemBack = useSystemNavigationBack();
+ const paneHeader = Platform.OS === 'ios' && paneLayout.persistent && !systemBack;
// Dev-only:把构建信息从全局浮层挪到这里的顶部展示(试 Fast Refresh)。
const buildLabel = __DEV__
? formatMobileBuildLabel(normalizeBuildInfo({
@@ -5041,8 +5052,12 @@ export default function NewRemoteSessionScreen() {
: draft.firstMessage.trim();
return (
- <SafeAreaView edges={composerDock.enabled ? ['left', 'right'] : simpleScreenSafeAreaEdges()} style={styles.safeArea} testID="newSession.screen">
- {Platform.OS === 'ios' ? (
+ <SafeAreaView edges={paneLayout.persistent
+ ? (composerDock.enabled ? ['top'] : ['top', 'bottom'])
+ : composerDock.enabled ? ['left', 'right'] : simpleScreenSafeAreaEdges()} style={styles.safeArea} testID="newSession.screen">
+ {Platform.OS === 'ios' && paneLayout.persistent ? (
+ <SystemNavigationBack label={t('shared.back')} onPress={handleBack} />
+ ) : Platform.OS === 'ios' ? (
<>
<Stack.Screen options={{ headerShown: true, headerBackVisible: false, headerShadowVisible: false, title: '', headerStyle: { backgroundColor: colors.surface }, headerTintColor: colors.textPrimary }} />
<Stack.Toolbar placement="left">
@@ -5060,9 +5075,11 @@ export default function NewRemoteSessionScreen() {
)}
style={styles.keyboard}
>
- <View style={[styles.screen, composerDock.enabled && { paddingHorizontal: composerGeometry.horizontalInset }]}>
- {Platform.OS !== 'ios' || buildLabel || creating ? <View style={styles.topBar}>
- {Platform.OS !== 'ios' ? <ScreenBackButton
+ <View style={[styles.screen, paneHeader && styles.paneScreen, composerDock.enabled && { paddingHorizontal: composerGeometry.horizontalInset }]}>
+ {Platform.OS !== 'ios' || paneHeader || buildLabel || creating ? <View style={[styles.topBar, paneHeader && styles.paneTopBar]}>
+ {paneHeader ? <NativeChromeBackButton
+ label={t('shared.back')} onPress={handleBack} testID="newSession.backButton"
+ /> : Platform.OS !== 'ios' ? <ScreenBackButton
hitSlop={12}
onPress={handleBack}
style={styles.backButton}
@@ -6198,6 +6215,14 @@ const makeStyles = (colors: ThemeColors) => StyleSheet.create({
justifyContent: 'space-between',
minHeight: 62,
},
+ // Match the embedded Home header: safe area + lg, then a 44pt button and md below.
+ paneScreen: {
+ paddingTop: spacing.lg,
+ },
+ paneTopBar: {
+ minHeight: navigationChrome.target + spacing.md,
+ paddingBottom: spacing.md,
+ },
buildLabel: {
color: colors.textTertiary,
flex: 1,
diff --git a/apps/mobile/src/__tests__/residentHomeList.test.tsx b/apps/mobile/src/__tests__/residentHomeList.test.tsx
index 7a5f18d922..c4e636f5a8 100644
--- a/apps/mobile/src/__tests__/residentHomeList.test.tsx
+++ b/apps/mobile/src/__tests__/residentHomeList.test.tsx
@@ -54,6 +54,35 @@ afterEach(() => {
state.divider = null; state.pan = {};
});
+// Unit regression: new-task routes must keep the existing sidebar usable. Older
+// coverage only visited [sessionId]; a wide /sessions/new was hidden with its
+// subscriptions paused. Exercise the real provider through creation and resize.
+it.each(['ios', 'android'])('keeps the sidebar active through new task → created task on %s', platform => {
+ state.platform = platform;
+ state.segments = ['sessions', 'new'];
+ const host = document.createElement('div'), root = createRoot(host); roots.push(root);
+ const select = vi.fn();
+ const render = () => act(() => root.render(<Scene detail homeSelect={select} detailSelect={select} />));
+ render();
+ expect(host.querySelector('[data-host]')?.getAttribute('data-pointer')).toBe('box-none');
+ expect(host.querySelector('[data-subscriptions]')?.getAttribute('data-subscriptions')).toBe('true');
+ expect(host.querySelector('[data-testid="session.paneDivider"]')).not.toBeNull();
+ act(() => (host.querySelector('[data-scroll]') as HTMLButtonElement).click());
+ const list = host.querySelector('[data-select]');
+ state.segments = ['sessions', '[sessionId]']; render();
+ expect(host.querySelector('[data-select]')).toBe(list);
+ expect(list?.textContent).toBe('240');
+ state.segments = ['sessions', 'new']; state.width = 430; render();
+ expect(host.querySelector('[data-host]')?.getAttribute('data-pointer')).toBe('none');
+ expect(host.querySelector('[data-subscriptions]')?.getAttribute('data-subscriptions')).toBe('false');
+ expect(host.querySelector('[data-testid="session.paneDivider"]')).toBeNull();
+ state.width = 1000; render();
+ expect(host.querySelector('[data-host]')?.getAttribute('data-pointer')).toBe('box-none');
+ expect(host.querySelector('[data-select]')).toBe(list);
+ act(() => (list as HTMLButtonElement).click());
+ expect(select).toHaveBeenCalledOnce();
+});
+
// Unit: real divider handlers + provider layout. User's 2026-10-23 request adds
// live bounded resizing; previous resident-list tests never drove a divider.
it('drags both panes together, clamps the bounds and retains width through route and orientation changes', () => {
diff --git a/apps/mobile/src/__tests__/sideChatTaskBoundary.test.tsx b/apps/mobile/src/__tests__/sideChatTaskBoundary.test.tsx
index 16fec2fbef..3fcd2443ec 100644
--- a/apps/mobile/src/__tests__/sideChatTaskBoundary.test.tsx
+++ b/apps/mobile/src/__tests__/sideChatTaskBoundary.test.tsx
@@ -200,7 +200,7 @@ describe('side chat task lifecycle', () => {
session: { id: 'next', canonicalDeviceId: 'canonical-host', deviceLinkDeviceId: 'old-host', deviceLinkDeviceName: 'Mac' },
searchFocusClientId: 'message-42',
} as unknown as RemoteSessionListItem;
- act(() => state.sidebar!.onSelectSession(target));
+ act(() => state.sidebar!.onSelectSession!(target));
expect(order).toEqual(['discard', 'navigate']);
expect(state.replaceParams).toHaveBeenCalledExactlyOnceWith({
deviceId: 'canonical-host', deviceName: 'Mac', sessionId: 'next', focusClientId: 'message-42',
diff --git a/apps/mobile/src/session/HomeNewTaskButton.tsx b/apps/mobile/src/session/HomeNewTaskButton.tsx
index cc097833c8..2ec546540b 100644
--- a/apps/mobile/src/session/HomeNewTaskButton.tsx
+++ b/apps/mobile/src/session/HomeNewTaskButton.tsx
@@ -5,6 +5,7 @@ import { HomeHeaderGlassButton } from './HomeHeaderGlassButton';
import { ComposerMorphSource } from './ComposerMorphSource';
import { useLiquidGlassAvailable } from './useLiquidGlassAvailable';
import { composerGeometry, type ComposerMorphOrigin } from './composerGeometry';
+import { useSessionPaneLayout } from './ResidentHomeList';
/** The circle and the compact composer pill are the same height, so the morph only stretches sideways. */
export const HOME_NEW_TASK_SIZE = composerGeometry.pillHeight;
@@ -21,12 +22,15 @@ export function HomeNewTaskButton({ onPress, bottomInset, disabled = false, morp
}) {
const { colors } = useTheme();
const { t } = useTranslation();
+ const paneLayout = useSessionPaneLayout();
// Liquid Glass: the untinted system glass circle (like the header buttons and
// the composer pill it grows into). Without it, keep the solid filled circle,
// since a plain chrome button has no surface of its own.
const glass = useLiquidGlassAvailable();
// Without morph the native shield stays out of the way and the button presses normally.
- return <ComposerMorphSource disabled={disabled || !morph} onAction={onPress} style={{
+ // The native morph guesses a full-window landing before the form mounts.
+ // Split layouts use the normal push so it never stretches over the list.
+ return <ComposerMorphSource disabled={disabled || !morph || paneLayout.persistent} onAction={onPress} style={{
position: 'absolute', right: composerGeometry.horizontalInset, bottom: bottomInset + composerGeometry.restingGap,
width: HOME_NEW_TASK_SIZE, height: HOME_NEW_TASK_SIZE,
}}>
diff --git a/apps/mobile/src/session/NewSessionLayout.tsx b/apps/mobile/src/session/NewSessionLayout.tsx
new file mode 100644
index 0000000000..0bca8bf273
--- /dev/null
+++ b/apps/mobile/src/session/NewSessionLayout.tsx
@@ -0,0 +1,65 @@
+import { useMemo, type ReactNode } from "react";
+import { StyleSheet, View } from "react-native";
+import {
+ PaneViewportProvider,
+ useAdaptiveWindow,
+} from "@/platform/AdaptiveWindowContext";
+import { useTheme } from "@/theme";
+import { MessageHistoryOverlay } from "./RecentMessageHistories";
+import { useSessionPaneLayout } from "./ResidentHomeList";
+import { SessionListDrawer } from "./SessionListDrawer";
+
+/** Keep the form mounted when the window changes between one and two panes. */
+export function NewSessionLayout({ children }: { children: ReactNode }) {
+ const window = useAdaptiveWindow();
+ const pane = useSessionPaneLayout();
+ const { colors } = useTheme();
+ const viewport = useMemo(
+ () => ({
+ ...pane.detail,
+ height: window.height,
+ }),
+ [
+ pane.detail.x,
+ pane.detail.y,
+ pane.detail.width,
+ pane.detail.height,
+ window.height,
+ ],
+ );
+
+ return (
+ <View style={[styles.root, { backgroundColor: colors.surface }]}>
+ <PaneViewportProvider value={viewport}>
+ <View
+ style={[
+ styles.root,
+ pane.persistent && {
+ marginLeft: pane.detail.x,
+ marginRight: Math.max(
+ 0,
+ window.width - pane.detail.x - pane.detail.width,
+ ),
+ },
+ ]}
+ >
+ {children}
+ </View>
+ </PaneViewportProvider>
+ <MessageHistoryOverlay enabled={false}>
+ <SessionListDrawer
+ currentSessionId=""
+ persistent={pane.persistent}
+ open={pane.persistent}
+ width={pane.sidebarWidth}
+ onClose={ignoreClose}
+ runNavigation={runNavigation}
+ />
+ </MessageHistoryOverlay>
+ </View>
+ );
+}
+
+const ignoreClose = () => undefined;
+const runNavigation = (action: () => void) => action();
+const styles = StyleSheet.create({ root: { flex: 1 } });
diff --git a/apps/mobile/src/session/ResidentHomeList.tsx b/apps/mobile/src/session/ResidentHomeList.tsx
index f68dca878f..6bcc94c717 100644
--- a/apps/mobile/src/session/ResidentHomeList.tsx
+++ b/apps/mobile/src/session/ResidentHomeList.tsx
@@ -61,7 +61,8 @@ export function ResidentHomeListProvider({ children }: { children: ReactNode })
// iOS Home keeps its list in its own route; Android draws it here on the home too.
const rootHome = Platform.OS !== 'ios';
const visible = (rootHome && homeRoute)
- || (persistent && segments[0] === 'sessions' && segments[1] === '[sessionId]');
+ || (persistent && segments[0] === 'sessions'
+ && (segments[1] === '[sessionId]' || segments[1] === 'new'));
const host = useRef<View>(null);
const mounted = useRef(false);
const [entry, setEntry] = useState<Entry | null>(null);
diff --git a/apps/mobile/src/session/SessionListDrawer.tsx b/apps/mobile/src/session/SessionListDrawer.tsx
index 87152cb8c8..6382488bc7 100644
--- a/apps/mobile/src/session/SessionListDrawer.tsx
+++ b/apps/mobile/src/session/SessionListDrawer.tsx
@@ -24,7 +24,8 @@ export function SessionListDrawer({ currentSessionId, persistent = false, newSes
newSessionInSystemBar?: boolean;
onClose(): void;
onClosed?(): void;
- onSelectSession(item: RemoteSessionListItem): void;
+ /** Without an override, Home uses its normal navigation and task history. */
+ onSelectSession?(item: RemoteSessionListItem): void;
runNavigation(action: () => void): void;
newSessionActionRef?: MutableRefObject<(() => void) | null>;
open: boolean;