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): keep rewind actions reachable on short viewports

davidbda2cbc19d18
diff --git a/apps/mobile/app/sessions/[sessionId].tsx b/apps/mobile/app/sessions/[sessionId].tsx
index 40a4e8bd0e..ebd27b5a49 100644
--- a/apps/mobile/app/sessions/[sessionId].tsx
+++ b/apps/mobile/app/sessions/[sessionId].tsx
@@ -9006,6 +9006,7 @@ export default function SessionScreen() {
onCancel={() => setRewindState({ kind: 'idle' })}
onConfirm={() => void confirmRewind()}
state={rewindState}
+ bottomOverlayHeight={bottomOverlayHeight}
topOverlayHeight={topOverlayHeight}
/>
diff --git a/apps/mobile/src/__tests__/rewindPreviewLayout.test.ts b/apps/mobile/src/__tests__/rewindPreviewLayout.test.ts
index 5ddfbff289..b87e4fe079 100644
--- a/apps/mobile/src/__tests__/rewindPreviewLayout.test.ts
+++ b/apps/mobile/src/__tests__/rewindPreviewLayout.test.ts
@@ -1,5 +1,5 @@
import { describe, expect, it } from 'vitest';
-import { buildRewindPreviewLayout } from '@/session/rewindPreviewLayout';
+import { buildRewindPreviewLayout, rewindPreviewMaxHeight } from '@/session/rewindPreviewLayout';
describe('rewindPreviewLayout', () => {
it('compacts file rows on iPhone SE width', () => {
@@ -45,4 +45,20 @@ describe('rewindPreviewLayout', () => {
visibleFileCount: 3,
});
});
+
+ it('reserves space for fixed overlays on a short viewport', () => {
+ expect(rewindPreviewMaxHeight({
+ bottomOverlayHeight: 92,
+ screenHeight: 320,
+ topOverlayHeight: 58,
+ })).toBe(154);
+ });
+
+ it('does not produce a negative panel height when overlays consume the viewport', () => {
+ expect(rewindPreviewMaxHeight({
+ bottomOverlayHeight: 220,
+ screenHeight: 320,
+ topOverlayHeight: 120,
+ })).toBe(0);
+ });
});
diff --git a/apps/mobile/src/session/RewindPreviewPanel.tsx b/apps/mobile/src/session/RewindPreviewPanel.tsx
index e96ca920e9..bd898c22d6 100644
--- a/apps/mobile/src/session/RewindPreviewPanel.tsx
+++ b/apps/mobile/src/session/RewindPreviewPanel.tsx
@@ -1,5 +1,6 @@
import {
ActivityIndicator,
+ ScrollView,
StyleSheet,
View,
useWindowDimensions,
@@ -9,7 +10,7 @@ import type { TFunction } from 'i18next';
import { Text } from '@/components/AppText';
import { MainWindowActionGroup } from '@/components/MobilePrimitives';
import type { RewindPreviewState } from '@/session/rewindPreview';
-import { buildRewindPreviewLayout } from '@/session/rewindPreviewLayout';
+import { buildRewindPreviewLayout, rewindPreviewMaxHeight } from '@/session/rewindPreviewLayout';
import { fontWeight, lineHeight, useTheme, useThemedStyles, type ThemeColors } from '@/theme';
import { radius, spacing, typeScale } from '@/theme/tokens';
@@ -17,6 +18,7 @@ interface RewindPreviewPanelProps {
state: RewindPreviewState;
committing?: boolean;
topOverlayHeight?: number;
+ bottomOverlayHeight?: number;
onCancel(): void;
onConfirm(): void;
}
@@ -25,13 +27,14 @@ export function RewindPreviewPanel({
state,
committing,
topOverlayHeight = 0,
+ bottomOverlayHeight = 0,
onCancel,
onConfirm,
}: RewindPreviewPanelProps) {
const styles = useThemedStyles(makeStyles);
const { colors } = useTheme();
const { t } = useTranslation();
- const { width: screenWidth } = useWindowDimensions();
+ const { height: screenHeight, width: screenWidth } = useWindowDimensions();
if (state.kind === 'idle') return null;
const canConfirm = state.kind === 'default' || state.kind === 'empty';
@@ -42,12 +45,18 @@ export function RewindPreviewPanel({
fileCount,
screenWidth,
});
+ const maxHeight = rewindPreviewMaxHeight({
+ bottomOverlayHeight,
+ screenHeight,
+ topOverlayHeight,
+ });
return (
<View
style={[
styles.container,
{
+ maxHeight,
marginHorizontal: layout.containerMarginHorizontal,
marginTop: Math.max(spacing.sm, topOverlayHeight + spacing.sm),
padding: layout.containerPadding,
@@ -55,62 +64,68 @@ export function RewindPreviewPanel({
]}
testID="rewind.panel"
>
- <View style={styles.header}>
- <View style={styles.headerText}>
- <Text style={styles.title}>{title}</Text>
- {detail ? <Text style={styles.detail}>{detail}</Text> : null}
+ <ScrollView
+ contentContainerStyle={styles.scrollContent}
+ nestedScrollEnabled
+ showsVerticalScrollIndicator
+ style={styles.scroll}
+ >
+ <View style={styles.header}>
+ <View style={styles.headerText}>
+ <Text style={styles.title}>{title}</Text>
+ {detail ? <Text style={styles.detail}>{detail}</Text> : null}
+ </View>
+ {state.kind === 'loading' ? <ActivityIndicator color={colors.textSecondary} /> : null}
</View>
- {state.kind === 'loading' ? <ActivityIndicator color={colors.textSecondary} /> : null}
- </View>
- {state.kind === 'default' ? (
- <View style={styles.fileList}>
- {state.filesChanged.slice(0, layout.visibleFileCount).map((file) => (
- <Text
- key={file}
- numberOfLines={1}
- selectable
- style={[styles.filePath, { minHeight: layout.fileRowMinHeight }]}
- >
- {file}
+ {state.kind === 'default' ? (
+ <View style={styles.fileList}>
+ {state.filesChanged.slice(0, layout.visibleFileCount).map((file) => (
+ <Text
+ key={file}
+ numberOfLines={1}
+ selectable
+ style={[styles.filePath, { minHeight: layout.fileRowMinHeight }]}
+ >
+ {file}
+ </Text>
+ ))}
+ {state.filesChanged.length > layout.visibleFileCount ? (
+ <Text style={styles.moreFiles}>{t('interaction.rewind.moreFiles', { count: state.filesChanged.length - layout.visibleFileCount })}</Text>
+ ) : null}
+ <Text style={styles.stats}>
+ {t('interaction.rewind.stats', { count: state.filesChanged.length, insertions: state.insertions, deletions: state.deletions })}
</Text>
- ))}
- {state.filesChanged.length > layout.visibleFileCount ? (
- <Text style={styles.moreFiles}>{t('interaction.rewind.moreFiles', { count: state.filesChanged.length - layout.visibleFileCount })}</Text>
- ) : null}
- <Text style={styles.stats}>
- {t('interaction.rewind.stats', { count: state.filesChanged.length, insertions: state.insertions, deletions: state.deletions })}
- </Text>
- </View>
- ) : null}
-
- {state.kind === 'empty' && state.note ? (
- <Text selectable style={styles.note}>{state.note}</Text>
- ) : null}
+ </View>
+ ) : null}
- {state.kind === 'error' ? (
- <Text selectable style={styles.errorText}>{state.errorText}</Text>
- ) : null}
+ {state.kind === 'empty' && state.note ? (
+ <Text selectable style={styles.note}>{state.note}</Text>
+ ) : null}
- {state.kind !== 'loading' ? (
- <MainWindowActionGroup
- cancelAction={{
- accessibilityLabel: state.kind === 'error' ? t('interaction.rewind.gotIt') : t('interaction.rewind.cancelAccessibility'),
- label: state.kind === 'error' ? t('interaction.rewind.gotIt') : t('interaction.rewind.cancel'),
- onPress: onCancel,
- testID: state.kind === 'error' ? 'rewind.dismissButton' : 'rewind.cancelButton',
- }}
- primaryActions={canConfirm ? [{
- accessibilityLabel: t('interaction.rewind.confirm'),
- disabled: committing,
- label: committing ? t('interaction.rewind.confirming') : t('interaction.rewind.confirm'),
- onPress: onConfirm,
- testID: 'rewind.confirmButton',
- tone: 'primary',
- }] : []}
- testID="rewind.actions"
- />
- ) : null}
+ {state.kind === 'error' ? (
+ <Text selectable style={styles.errorText}>{state.errorText}</Text>
+ ) : null}
+ {state.kind !== 'loading' ? (
+ <MainWindowActionGroup
+ cancelAction={{
+ accessibilityLabel: state.kind === 'error' ? t('interaction.rewind.gotIt') : t('interaction.rewind.cancelAccessibility'),
+ label: state.kind === 'error' ? t('interaction.rewind.gotIt') : t('interaction.rewind.cancel'),
+ onPress: onCancel,
+ testID: state.kind === 'error' ? 'rewind.dismissButton' : 'rewind.cancelButton',
+ }}
+ primaryActions={canConfirm ? [{
+ accessibilityLabel: t('interaction.rewind.confirm'),
+ disabled: committing,
+ label: committing ? t('interaction.rewind.confirming') : t('interaction.rewind.confirm'),
+ onPress: onConfirm,
+ testID: 'rewind.confirmButton',
+ tone: 'primary',
+ }] : []}
+ testID="rewind.actions"
+ />
+ ) : null}
+ </ScrollView>
</View>
);
}
@@ -138,8 +153,11 @@ const makeStyles = (colors: ThemeColors) => StyleSheet.create({
gap: spacing.md,
marginHorizontal: spacing.md,
marginTop: spacing.sm,
+ overflow: 'hidden',
padding: spacing.md,
},
+ scroll: { flexShrink: 1, minHeight: 0 },
+ scrollContent: { gap: spacing.md },
header: { alignItems: 'center', flexDirection: 'row', gap: spacing.md },
headerText: { flex: 1, minWidth: 0 },
title: { color: colors.textPrimary, fontSize: typeScale.body, fontWeight: fontWeight.medium },
diff --git a/apps/mobile/src/session/rewindPreviewLayout.ts b/apps/mobile/src/session/rewindPreviewLayout.ts
index 20801b26cc..b4f9aeff2e 100644
--- a/apps/mobile/src/session/rewindPreviewLayout.ts
+++ b/apps/mobile/src/session/rewindPreviewLayout.ts
@@ -11,12 +11,20 @@ export interface RewindPreviewLayout {
visibleFileCount: number;
}
+export interface RewindPreviewViewportInput {
+ screenHeight: number;
+ topOverlayHeight?: number;
+ bottomOverlayHeight?: number;
+}
+
const DEFAULT_SCREEN_WIDTH = 390;
+const DEFAULT_SCREEN_HEIGHT = 844;
const COMPACT_WIDTH = 360;
const STANDARD_SPACE = 16;
const COMPACT_SPACE = 12;
const STANDARD_VISIBLE_FILES = 6;
const COMPACT_VISIBLE_FILES = 4;
+const PANEL_EDGE_GAP = 8;
/** 回退预览面板布局:compact 只由屏宽决定(操作区已收敛到 MainWindowActionGroup,不再输出按钮尺寸)。 */
export function buildRewindPreviewLayout(input: RewindPreviewLayoutInput): RewindPreviewLayout {
@@ -34,6 +42,14 @@ export function buildRewindPreviewLayout(input: RewindPreviewLayoutInput): Rewin
};
}
+/** Keeps the rewind panel inside the space between the fixed top and bottom overlays. */
+export function rewindPreviewMaxHeight(input: RewindPreviewViewportInput): number {
+ const screenHeight = normalizeDimension(input.screenHeight, DEFAULT_SCREEN_HEIGHT);
+ const topOverlayHeight = normalizeInset(input.topOverlayHeight);
+ const bottomOverlayHeight = normalizeInset(input.bottomOverlayHeight);
+ return Math.max(0, screenHeight - topOverlayHeight - bottomOverlayHeight - PANEL_EDGE_GAP * 2);
+}
+
function normalizeCount(value: number): number {
if (!Number.isFinite(value) || value <= 0) return 0;
return Math.floor(value);
@@ -42,3 +58,7 @@ function normalizeCount(value: number): number {
function normalizeDimension(value: number, fallback: number): number {
return Number.isFinite(value) && value > 0 ? value : fallback;
}
+
+function normalizeInset(value: number | undefined): number {
+ return typeof value === 'number' && Number.isFinite(value) && value > 0 ? value : 0;
+}