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): pair native prominent button foreground with CTA tint (#5516)

Kirozeng09ea71d8574e
diff --git a/apps/mobile/src/__tests__/goalNativeForm.test.tsx b/apps/mobile/src/__tests__/goalNativeForm.test.tsx
index 7e72e7b6ce..6e75a7afa2 100644
--- a/apps/mobile/src/__tests__/goalNativeForm.test.tsx
+++ b/apps/mobile/src/__tests__/goalNativeForm.test.tsx
@@ -4,7 +4,7 @@ import { createRoot } from 'react-dom/client';
import { afterEach, expect, it, vi } from 'vitest';
import { ContextSheetGoalCreateForm, ContextSheetGoalView } from '@/session/ContextSheetGoalView.ios';
-const bridge = vi.hoisted(() => ({ props: new Map<string, any>() }));
+const bridge = vi.hoisted(() => ({ props: new Map<string, any>(), mode: 'light' }));
vi.mock('@expo/ui/swift-ui', async () => {
const React = await import('react');
const control = (p: any) => {
@@ -19,9 +19,12 @@ vi.mock('@expo/ui/swift-ui', async () => {
};
});
vi.mock('@expo/ui/swift-ui/modifiers', () => Object.fromEntries(
- ['buttonBorderShape', 'controlSize', 'accessibilityHint', 'accessibilityLabel', 'buttonStyle', 'contentShape', 'disabled', 'font', 'foregroundStyle', 'frame', 'lineLimit', 'pickerStyle', 'tag'].map(key => [key, (value: any) => ({ [key]: value })]).concat([['shapes', { rectangle: () => ({}) }] as any]),
+ ['buttonBorderShape', 'controlSize', 'accessibilityHint', 'accessibilityLabel', 'buttonStyle', 'contentShape', 'disabled', 'font', 'foregroundStyle', 'frame', 'lineLimit', 'pickerStyle', 'tag', 'tint'].map(key => [key, (value: any) => ({ [key]: value })]).concat([['shapes', { rectangle: () => ({}) }] as any]),
));
-vi.mock('@/theme', () => ({ navigationChrome: { target: 44 }, useTheme: () => ({ colors: {} }) }));
+vi.mock('@/theme', () => ({ navigationChrome: { target: 44 }, useTheme: () => ({ colors: {
+ cta: bridge.mode === 'dark' ? 'white' : 'black',
+ ctaText: bridge.mode === 'dark' ? 'black' : 'white',
+} }) }));
vi.mock('@/session/useLiquidGlassAvailable', () => ({ useLiquidGlassAvailable: () => true }));
vi.mock('react-i18next', () => ({ useTranslation: () => ({ t: (key: string) => key }) }));
vi.mock('@/session/ComposerNativeSection', () => ({ ComposerNativeSection: (p: any) => createElement('section', null, p.children) }));
@@ -29,7 +32,7 @@ vi.mock('@/session/goalStatusLabel', () => ({ goalReasonText: () => '', goalStat
Object.assign(globalThis, { IS_REACT_ACT_ENVIRONMENT: true });
const cleanup: Array<() => void> = [];
-afterEach(() => { cleanup.splice(0).forEach(fn => fn()); bridge.props.clear(); });
+afterEach(() => { cleanup.splice(0).forEach(fn => fn()); bridge.props.clear(); bridge.mode = 'light'; });
function mount(props: any = {}, component: any = ContextSheetGoalCreateForm) {
const root = createRoot(document.createElement('div'));
const onSetGoal = vi.fn();
@@ -68,3 +71,13 @@ it.each(['active', 'paused', 'blocked', 'usageLimited', 'completed'])('keeps sta
expect(!!control('goalResumeButton')).toBe(['paused', 'blocked', 'usageLimited'].includes(status));
expect(control('goalClearButton')).toBeDefined();
});
+
+it.each(['light', 'dark'])('pairs the goal label and busy indicator with the CTA in %s', mode => {
+ bridge.mode = mode;
+ const foreground = mode === 'dark' ? 'black' : 'white';
+ mount({ initial: { objective: '目标' } });
+ expect(control('goalStartButton').children.props.modifiers).toContainEqual({ foregroundStyle: foreground });
+ mount({ busy: true, initial: { objective: '目标' } });
+ expect(control('goalStartButton').children.props.modifiers).toContainEqual({ tint: foreground });
+ expect(control('goalStartButton').modifiers).toContainEqual({ disabled: true });
+});
diff --git a/apps/mobile/src/__tests__/nativeGlassControls.test.tsx b/apps/mobile/src/__tests__/nativeGlassControls.test.tsx
index ec0369fc8b..dafddbaec5 100644
--- a/apps/mobile/src/__tests__/nativeGlassControls.test.tsx
+++ b/apps/mobile/src/__tests__/nativeGlassControls.test.tsx
@@ -6,6 +6,10 @@ import { NativeChromeButton } from "../platform/chrome/NativeChromeButton.ios";
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 { PermissionGuideView } from "../remote-desktop/PermissionGuideView.ios";
+import type { NewTaskSelectionSheetProps } from "../session/NewTaskSelectionSheet";
const state = vi.hoisted(() => ({ glass: true, mode: "light" }));
vi.mock("@/theme", () => ({
@@ -20,12 +24,14 @@ vi.mock("@/theme", () => ({
iconStroke: { regular: 2 },
radius: { pill: 9999 },
typeScale: { body: 16 },
+ spacing: { md: 12 },
+ textStyles: { caption: {} },
useTheme: () => ({
mode: state.mode,
colors: {
textPrimary: "primary",
textSecondary: "secondary",
- cta: "cta",
+ cta: state.mode === "dark" ? "white" : "black",
ctaText: state.mode === "dark" ? "black" : "white",
destructive: "danger",
surfaceElevated: "surface",
@@ -38,6 +44,15 @@ vi.mock("@/session/useLiquidGlassAvailable", () => ({
vi.mock("react-i18next", () => ({
useTranslation: () => ({ t: (key: string) => key }),
}));
+vi.mock("@/session/ComposerSheet", () => ({
+ ComposerSheet: ({ children, footer }: any) => <div>{children}{footer}</div>,
+}));
+vi.mock("@/session/ComposerNativeRow", () => ({ ComposerNativeRow: () => null }));
+vi.mock("@/session/ComposerNativeSection", () => ({
+ ComposerNativeSection: ({ children }: any) => <div>{children}</div>,
+}));
+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>,
Image: () => null,
@@ -61,15 +76,20 @@ vi.mock("@expo/ui/swift-ui", () => {
HStack: Container,
VStack: Container,
RNHostView: Container,
- Text: Container,
+ Text: ({ children, modifiers }: any) => <span data-text-style={JSON.stringify(modifiers)}>{children}</span>,
+ Picker: Container,
+ Toggle: () => null,
+ Divider: () => null,
+ LabeledContent: Container,
Image: () => null,
Label: ({ title, modifiers }: any) => (
<span data-label-style={JSON.stringify(modifiers)}>{title}</span>
),
- ProgressView: () => <span role="progressbar" />,
+ ProgressView: ({ modifiers }: any) => <span role="progressbar" data-progress-style={JSON.stringify(modifiers)} />,
Button: ({ children, label, onPress, testID, modifiers = [] }: any) => (
<button
data-testid={testID}
+ data-button-style={JSON.stringify(modifiers)}
disabled={modifiers.some((m: any) => m.name === "disabled" && m.value)}
onClick={onPress}
>
@@ -95,14 +115,22 @@ vi.mock("@expo/ui/swift-ui/modifiers", () => {
"font",
"labelStyle",
"lineLimit",
+ "tint",
+ "pickerStyle",
+ "tag",
+ "listRowInsets",
+ "fixedSize",
+ "multilineTextAlignment",
+ "padding",
];
return {
...Object.fromEntries(
names.map((name) => [name, (value: any) => ({ name, value })]),
),
- shapes: { circle: () => "circle", capsule: () => "capsule" },
+ shapes: { circle: () => "circle", capsule: () => "capsule", roundedRectangle: () => "roundedRectangle" },
};
});
+Object.assign(globalThis, { IS_REACT_ACT_ENVIRONMENT: true });
const roots: ReturnType<typeof createRoot>[] = [];
afterEach(() => {
act(() => roots.splice(0).forEach((root) => root.unmount()));
@@ -245,6 +273,96 @@ it("keeps provider artwork inside a native button and prevents disabled activati
);
expect(host.querySelectorAll("button")).toHaveLength(1);
expect(host.querySelector('button [data-brand="original"]')).not.toBeNull();
+ // A duplicate foreground closer to the native label would override this
+ // disabled color even if the last modifier appears correct in a DOM mock.
+ expect(JSON.parse(host.querySelector("button")!.getAttribute("data-button-style")!)
+ .filter((modifier: any) => modifier.name === "foregroundStyle"))
+ .toEqual([{ name: "foregroundStyle", value: "secondary" }]);
act(() => host.querySelector("button")!.click());
expect(click).not.toHaveBeenCalled();
});
+
+it.each(["light", "dark"])("pairs prominent fill and foreground across native styles in %s", (mode) => {
+ state.mode = mode;
+ const foreground = mode === "dark" ? "black" : "white";
+ const fill = mode === "dark" ? "white" : "black";
+ for (const glass of [true, false]) {
+ state.glass = glass;
+ for (const options of [{}, { shape: "circle" as const }, { dimensions: { height: 44 } }]) {
+ let modifiers: any[] = [];
+ function Probe() {
+ modifiers = useNativeGlassButtonStyle({ ...options, prominent: true });
+ return null;
+ }
+ mount(<Probe />);
+ if ("shape" in options || "dimensions" in options) {
+ // Framed login controls own their label colors, including disabled ones.
+ expect(modifiers.some((m) => m.name === "foregroundStyle")).toBe(false);
+ expect(modifiers).toContainEqual(glass
+ ? { name: "glassEffect", value: expect.objectContaining({ glass: expect.objectContaining({ tint: fill }) }) }
+ : { name: "background", value: fill });
+ } else {
+ expect(modifiers).toContainEqual({ name: "foregroundStyle", value: foreground });
+ expect(modifiers).toContainEqual({ name: "tint", value: fill });
+ }
+ }
+ }
+});
+
+function directoryProps(overrides: Partial<NewTaskSelectionSheetProps> = {}): NewTaskSelectionSheetProps {
+ return {
+ page: "directory", busy: false, loading: false, error: null,
+ devices: [], selectedDeviceId: "", workspaces: [], workspaceKind: "project", workingDir: "/project",
+ path: "/project", parent: "/", drives: [], entries: [], showHidden: false,
+ onClose: vi.fn(), onBack: vi.fn(), onDevice: vi.fn(), onDialogue: vi.fn(),
+ onProject: vi.fn(), onBrowse: vi.fn(), onEnter: vi.fn(), onChoose: vi.fn(), onShowHidden: vi.fn(),
+ ...overrides,
+ };
+}
+
+it.each(["light", "dark"])("gives the current-folder label a contrasting color and keeps selection working in %s", (mode) => {
+ state.mode = mode;
+ const props = directoryProps();
+ const host = mount(<NewTaskSelectionSheet {...props} />);
+ const button = host.querySelector('[data-testid="newSession.remoteBrowseSelectCurrent"]')!;
+ expect(JSON.parse(button.querySelector("[data-text-style]")!.getAttribute("data-text-style")!))
+ .toContainEqual({ name: "foregroundStyle", value: mode === "dark" ? "black" : "white" });
+ act(() => (button as HTMLButtonElement).click());
+ expect(props.onChoose).toHaveBeenCalledExactlyOnceWith("/project");
+});
+
+it.each([{ busy: true }, { loading: true }, { error: "Unavailable" }, { path: "" }])("keeps unavailable folders unselectable: %j", (overrides) => {
+ const props = directoryProps(overrides);
+ const host = mount(<NewTaskSelectionSheet {...props} />);
+ const button = host.querySelector('[data-testid="newSession.remoteBrowseSelectCurrent"]') as HTMLButtonElement;
+ expect(button.disabled).toBe(true);
+ act(() => button.click());
+ expect(props.onChoose).not.toHaveBeenCalled();
+});
+
+it.each(["light", "dark"])("keeps footer text and loading indicator legible in %s", (mode) => {
+ state.mode = mode;
+ const foreground = mode === "dark" ? "black" : "white";
+ const host = mount(<ContextSheetFooterButton label="Confirm" onPress={vi.fn()} />);
+ expect(JSON.parse(host.querySelector("[data-text-style]")!.getAttribute("data-text-style")!))
+ .toContainEqual({ name: "foregroundStyle", value: foreground });
+ const busyHost = mount(<ContextSheetFooterButton label="Confirm" busy onPress={vi.fn()} />);
+ expect(busyHost.textContent).not.toContain("Confirm");
+ expect(JSON.parse(busyHost.querySelector('[role="progressbar"]')!.getAttribute("data-progress-style")!))
+ .toContainEqual({ name: "tint", value: foreground });
+ expect(busyHost.querySelector("button")!.disabled).toBe(true);
+});
+
+it.each(["light", "dark"])("pairs permission-guide primary labels without changing the secondary label in %s", (mode) => {
+ state.mode = mode;
+ for (const guideLabel of ["Open settings", undefined]) {
+ const host = mount(<PermissionGuideView title="Permissions" intro="Enable access" rows={[]}
+ guideLabel={guideLabel} pending={false} onGuide={vi.fn()} reconnectLabel="Reconnect" onReconnect={vi.fn()} />);
+ const buttons = [...host.querySelectorAll("button")];
+ buttons.forEach((button, index) => {
+ const primary = !guideLabel || index === 0;
+ expect(JSON.parse(button.querySelector("[data-text-style]")!.getAttribute("data-text-style")!))
+ .toContainEqual({ name: "foregroundStyle", value: primary ? (mode === "dark" ? "black" : "white") : "primary" });
+ });
+ }
+});
diff --git a/apps/mobile/src/platform/chrome/nativeGlassButtonStyle.ios.ts b/apps/mobile/src/platform/chrome/nativeGlassButtonStyle.ios.ts
index 422effa2ef..1ca0ef448a 100644
--- a/apps/mobile/src/platform/chrome/nativeGlassButtonStyle.ios.ts
+++ b/apps/mobile/src/platform/chrome/nativeGlassButtonStyle.ios.ts
@@ -1,6 +1,6 @@
import {
background, buttonBorderShape, buttonStyle, contentShape, controlSize,
- foregroundStyle, font, frame, glassEffect, shapes,
+ foregroundStyle, font, frame, glassEffect, shapes, tint,
} from '@expo/ui/swift-ui/modifiers';
import { useLiquidGlassAvailable } from '@/session/useLiquidGlassAvailable';
import { iconSize, navigationChrome, useTheme } from '@/theme';
@@ -29,6 +29,9 @@ export function useNativeGlassButtonStyle({
}
return [
buttonStyle(glass ? (prominent ? 'glassProminent' : 'glass') : (prominent ? 'borderedProminent' : 'bordered')),
+ // A light tint in Dark mode does not make SwiftUI's prominent label dark.
+ // Pair both colors here; custom labels also set ctaText inside the style.
+ ...(prominent ? [tint(colors.cta), foregroundStyle(colors.ctaText)] : []),
buttonBorderShape(shape),
controlSize('regular'),
frame({ minHeight: navigationChrome.target }),
diff --git a/apps/mobile/src/remote-desktop/PermissionGuideView.ios.tsx b/apps/mobile/src/remote-desktop/PermissionGuideView.ios.tsx
index 28eb861fe6..1ce6337806 100644
--- a/apps/mobile/src/remote-desktop/PermissionGuideView.ios.tsx
+++ b/apps/mobile/src/remote-desktop/PermissionGuideView.ios.tsx
@@ -103,6 +103,7 @@ export function PermissionGuideView(props: PermissionGuideViewProps) {
>
<Text
modifiers={[
+ foregroundStyle(colors.ctaText),
fixedSize({ horizontal: false, vertical: true }),
multilineTextAlignment("center"),
frame({ maxWidth: Infinity, minHeight: 24 }),
@@ -120,6 +121,7 @@ export function PermissionGuideView(props: PermissionGuideViewProps) {
>
<Text
modifiers={[
+ foregroundStyle(props.guideLabel ? colors.textPrimary : colors.ctaText),
fixedSize({ horizontal: false, vertical: true }),
multilineTextAlignment("center"),
frame({ maxWidth: Infinity, minHeight: 44 }),
diff --git a/apps/mobile/src/session/ContextSheet.ios.tsx b/apps/mobile/src/session/ContextSheet.ios.tsx
index 38d9d67b3d..2d5360bfa5 100644
--- a/apps/mobile/src/session/ContextSheet.ios.tsx
+++ b/apps/mobile/src/session/ContextSheet.ios.tsx
@@ -26,6 +26,7 @@ import {
pickerStyle,
shapes,
tag,
+ tint,
} from "@expo/ui/swift-ui/modifiers";
import { useTranslation } from "react-i18next";
import { View } from "react-native";
@@ -157,6 +158,7 @@ export function ContextSheetRow(props: ContextSheetRowProps) {
);
}
export function ContextSheetFooterButton(props: ContextSheetFooterButtonProps) {
+ const { colors } = useTheme();
const glassStyle = useNativeGlassButtonStyle({ prominent: true });
return (
<Button
@@ -168,7 +170,7 @@ export function ContextSheetFooterButton(props: ContextSheetFooterButtonProps) {
frame({ maxWidth: Infinity, minHeight: 44 }),
]}
>
- {props.busy ? <ProgressView /> : <Text>{props.label}</Text>}
+ {props.busy ? <ProgressView modifiers={[tint(colors.ctaText)]} /> : <Text modifiers={[foregroundStyle(colors.ctaText)]}>{props.label}</Text>}
</Button>
);
}
diff --git a/apps/mobile/src/session/ContextSheetGoalView.ios.tsx b/apps/mobile/src/session/ContextSheetGoalView.ios.tsx
index 38cc2f5ac5..8a031bc0ae 100644
--- a/apps/mobile/src/session/ContextSheetGoalView.ios.tsx
+++ b/apps/mobile/src/session/ContextSheetGoalView.ios.tsx
@@ -2,7 +2,7 @@ import { useNativeGlassButtonStyle } from "@/platform/chrome/nativeGlassButtonSt
import { useState, type ComponentProps } from 'react';
import { useTranslation } from 'react-i18next';
import { Button, DisclosureGroup, Picker, ProgressView, Text, TextField, useNativeState } from '@expo/ui/swift-ui';
-import { accessibilityHint, accessibilityLabel, buttonStyle, contentShape, disabled as disable, font, foregroundStyle, frame, lineLimit, pickerStyle, shapes, tag } from '@expo/ui/swift-ui/modifiers';
+import { accessibilityHint, accessibilityLabel, buttonStyle, contentShape, disabled as disable, font, foregroundStyle, frame, lineLimit, pickerStyle, shapes, tag, tint } from '@expo/ui/swift-ui/modifiers';
import { useTheme } from '@/theme';
import type { MobileGoalLimitsInput } from '@cindy/maker-shared/device-link-contract';
import type { ContextSheetGoalViewProps, ContextSheetGoalCreateForm as GoalCreateForm } from './ContextSheetGoalView';
@@ -53,7 +53,7 @@ export function ContextSheetGoalCreateForm({ busy, disabled = false, disabledHin
disable(busy || disabled || !objective.trim()),
...(disabled && disabledHint ? [accessibilityHint(disabledHint)] : []),
accessibilityLabel(t('interaction.contextSheet.startGoal')),
- ]}>{busy ? <ProgressView /> : <Text>{t('interaction.contextSheet.startGoal')}</Text>}</Button>
+ ]}>{busy ? <ProgressView modifiers={[tint(colors.ctaText)]} /> : <Text modifiers={[foregroundStyle(colors.ctaText)]}>{t('interaction.contextSheet.startGoal')}</Text>}</Button>
</Section>
</>;
}
diff --git a/apps/mobile/src/session/NewTaskSelectionSheet.ios.tsx b/apps/mobile/src/session/NewTaskSelectionSheet.ios.tsx
index a702a488a4..8139a79b12 100644
--- a/apps/mobile/src/session/NewTaskSelectionSheet.ios.tsx
+++ b/apps/mobile/src/session/NewTaskSelectionSheet.ios.tsx
@@ -33,7 +33,7 @@ export function NewTaskSelectionSheet(p: NewTaskSelectionSheetProps) {
modifiers={[...glassStyle, disabled(unavailable || !p.path || !!p.error)]}
testID="newSession.remoteBrowseSelectCurrent"
>
- <Text modifiers={[frame({ maxWidth: Infinity, minHeight: 44 })]}>{t('session.new.useCurrent')}</Text>
+ <Text modifiers={[foregroundStyle(colors.ctaText), frame({ maxWidth: Infinity, minHeight: 44 })]}>{t('session.new.useCurrent')}</Text>
</Button>
) : undefined}
>