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): 约束 iOS 计划模式勾号布局 (#5598)

DavidShenXD44809ba24479
diff --git a/apps/mobile/app/sessions/[sessionId].tsx b/apps/mobile/app/sessions/[sessionId].tsx
index afbb3e8b33..cac499e0d6 100644
--- a/apps/mobile/app/sessions/[sessionId].tsx
+++ b/apps/mobile/app/sessions/[sessionId].tsx
@@ -9491,6 +9491,7 @@ export default function SessionScreen() {
}}
testID="session.contextSheetPlanRow"
trailing={planModeOn ? <Check color={colors.textPrimary} size={iconSize.md} strokeWidth={iconStroke.bold} /> : null}
+ trailingSize={iconSize.md}
/>
) : null}
<ContextSheetRow
diff --git a/apps/mobile/app/sessions/new.tsx b/apps/mobile/app/sessions/new.tsx
index 3b50e560f6..2977e328af 100644
--- a/apps/mobile/app/sessions/new.tsx
+++ b/apps/mobile/app/sessions/new.tsx
@@ -6497,6 +6497,7 @@ export default function NewRemoteSessionScreen() {
}}
testID="newSession.contextSheetPlanRow"
trailing={planModeOn ? <Check color={colors.textPrimary} size={iconSize.md} strokeWidth={iconStroke.bold} /> : null}
+ trailingSize={iconSize.md}
/>
) : null}
<ContextSheetRow
diff --git a/apps/mobile/src/__tests__/nativeGlassControls.test.tsx b/apps/mobile/src/__tests__/nativeGlassControls.test.tsx
index dafddbaec5..9fad787113 100644
--- a/apps/mobile/src/__tests__/nativeGlassControls.test.tsx
+++ b/apps/mobile/src/__tests__/nativeGlassControls.test.tsx
@@ -1,5 +1,5 @@
// @vitest-environment jsdom
-import { act, type ReactNode } from "react";
+import { act, useState, type ReactNode } from "react";
import { createRoot } from "react-dom/client";
import { afterEach, expect, it, vi } from "vitest";
import { NativeChromeButton } from "../platform/chrome/NativeChromeButton.ios";
@@ -7,7 +7,7 @@ import { LoginNativeButton } from "../components/LoginNativeButton.ios";
import { ShareImageNativeButton } from "../session/ShareImageNativeButton.ios";
import { useNativeGlassButtonStyle } from "../platform/chrome/nativeGlassButtonStyle.ios";
import { NewTaskSelectionSheet } from "../session/NewTaskSelectionSheet.ios";
-import { ContextSheetFooterButton } from "../session/ContextSheet.ios";
+import { ContextSheetFooterButton, ContextSheetRow } from "../session/ContextSheet.ios";
import { PermissionGuideView } from "../remote-desktop/PermissionGuideView.ios";
import type { NewTaskSelectionSheetProps } from "../session/NewTaskSelectionSheet";
@@ -54,7 +54,7 @@ vi.mock("@/session/ComposerNativeSection", () => ({
vi.mock("@/session/newSessionMessages", () => ({ newSessionText: (key: string) => key }));
vi.mock("@/components/AppText", () => ({ Text: ({ children }: any) => <span>{children}</span> }));
vi.mock("react-native", () => ({
- View: ({ children }: any) => <div>{children}</div>,
+ View: ({ children, style }: any) => <div data-rn-style={JSON.stringify(style)}>{children}</div>,
Image: () => null,
}));
vi.mock("lucide-react-native", () => {
@@ -73,8 +73,9 @@ vi.mock("@expo/ui", () => ({
vi.mock("@expo/ui/swift-ui", () => {
const Container = ({ children }: any) => <div>{children}</div>;
return {
- HStack: Container,
+ HStack: ({ children, modifiers }: any) => <div data-hstack-style={JSON.stringify(modifiers)}>{children}</div>,
VStack: Container,
+ Spacer: () => null,
RNHostView: Container,
Text: ({ children, modifiers }: any) => <span data-text-style={JSON.stringify(modifiers)}>{children}</span>,
Picker: Container,
@@ -127,7 +128,7 @@ vi.mock("@expo/ui/swift-ui/modifiers", () => {
...Object.fromEntries(
names.map((name) => [name, (value: any) => ({ name, value })]),
),
- shapes: { circle: () => "circle", capsule: () => "capsule", roundedRectangle: () => "roundedRectangle" },
+ shapes: { circle: () => "circle", capsule: () => "capsule", roundedRectangle: () => "roundedRectangle", rectangle: () => "rectangle" },
};
});
Object.assign(globalThis, { IS_REACT_ACT_ENVIRONMENT: true });
@@ -144,6 +145,47 @@ function mount(children: ReactNode) {
act(() => root.render(children));
return host;
}
+
+it.each(["light", "dark"])("keeps the context row label and hit area while toggling a sized trailing icon in %s", (mode) => {
+ state.mode = mode;
+ const onPress = vi.fn();
+ function PlanRow() {
+ const [selected, setSelected] = useState(false);
+ return <ContextSheetRow
+ icon={<span data-testid="plan-icon">icon</span>}
+ label="Plan mode"
+ onPress={() => { onPress(); setSelected((value) => !value); }}
+ trailing={selected ? <span data-testid="plan-check">✓</span> : null}
+ trailingSize={16}
+ />;
+ }
+ const host = mount(<PlanRow />);
+ const button = host.querySelector("button")!;
+ expect(host.querySelector('[data-testid="plan-check"]')).toBeNull();
+ act(() => button.click());
+ expect(button.textContent).toContain("Plan mode");
+ expect(host.querySelector('[data-testid="plan-icon"]')).not.toBeNull();
+ const trailing = host.querySelector('[data-testid="plan-check"]')!.parentElement!;
+ expect(JSON.parse(trailing.getAttribute("data-rn-style")!)).toMatchObject({ width: 16, height: 16 });
+ expect(JSON.parse(host.querySelector("[data-hstack-style]")!.getAttribute("data-hstack-style")!))
+ .toContainEqual({ name: "frame", value: expect.objectContaining({ minHeight: 44 }) });
+ act(() => button.click());
+ expect(button.textContent).toContain("Plan mode");
+ expect(host.querySelector('[data-testid="plan-check"]')).toBeNull();
+ expect(onPress).toHaveBeenCalledTimes(2);
+});
+
+it("lets custom trailing text keep its content size and preserves busy-row behavior", () => {
+ const props = { icon: <span>icon</span>, label: "Model", onPress: vi.fn() };
+ const host = mount(<ContextSheetRow {...props} trailing={<span data-testid="model-detail">A long model name</span>} />);
+ const detail = host.querySelector('[data-testid="model-detail"]')!;
+ expect(detail.textContent).toBe("A long model name");
+ expect(detail.parentElement!.hasAttribute("data-rn-style")).toBe(false);
+ const busyHost = mount(<ContextSheetRow {...props} busy trailing={<span>✓</span>} trailingSize={16} />);
+ expect(busyHost.querySelector('[role="progressbar"]')).not.toBeNull();
+ expect(busyHost.textContent).not.toContain("✓");
+ expect(busyHost.querySelector("button")!.disabled).toBe(true);
+});
it("prevents disabled glass actions", () => {
const click = vi.fn();
const host = mount(
diff --git a/apps/mobile/src/session/ContextSheet.ios.tsx b/apps/mobile/src/session/ContextSheet.ios.tsx
index 2d5360bfa5..2c1d907645 100644
--- a/apps/mobile/src/session/ContextSheet.ios.tsx
+++ b/apps/mobile/src/session/ContextSheet.ios.tsx
@@ -122,7 +122,13 @@ export function ContextSheetRow(props: ContextSheetRowProps) {
<ProgressView />
) : props.trailing && props.trailing !== "chevron" ? (
<RNHostView matchContents>
- <View>{props.trailing}</View>
+ {/* matchContents reads this RN View's bounds, not the nested icon's size. */}
+ <View style={props.trailingSize != null ? {
+ width: props.trailingSize,
+ height: props.trailingSize,
+ alignItems: 'center',
+ justifyContent: 'center',
+ } : undefined}>{props.trailing}</View>
</RNHostView>
) : props.trailing === "chevron" ? (
<Image size={iconSize.lg} systemName="chevron.right" />
diff --git a/apps/mobile/src/session/ContextSheet.tsx b/apps/mobile/src/session/ContextSheet.tsx
index bcf8bd41b1..ede03b3197 100644
--- a/apps/mobile/src/session/ContextSheet.tsx
+++ b/apps/mobile/src/session/ContextSheet.tsx
@@ -162,6 +162,8 @@ export interface ContextSheetRowProps {
onLongPress?: () => void;
/** 'chevron' 表示带二级视图;也可以传自定义 trailing 节点。 */
trailing?: 'chevron' | ReactNode;
+ /** 自定义尾部图标的方形承载尺寸;文字等尾部内容不传,继续按内容布局。 */
+ trailingSize?: number;
disabled?: boolean;
busy?: boolean;
accessibilityHint?: string;
@@ -179,6 +181,7 @@ export function ContextSheetRow({
onPress,
onLongPress,
trailing,
+ trailingSize,
disabled,
busy,
accessibilityHint,
@@ -212,7 +215,12 @@ export function ContextSheetRow({
<Text style={[styles.rowLabel, destructive && { color: colors.destructive }]}>{label}</Text>
)}
</View>
- <View style={styles.rowTrailing}>
+ <View style={[
+ styles.rowTrailing,
+ !busy && trailing && trailing !== 'chevron' && trailingSize != null
+ ? { width: trailingSize, height: trailingSize, justifyContent: 'center' as const }
+ : undefined,
+ ]}>
{busy ? (
<ActivityIndicator color={colors.textSecondary} size="small" />
) : trailing === 'chevron' ? (