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): 对调项目滑动操作并统一任务按钮样式

Dash93427a8a0908
diff --git a/apps/mobile/docs/mobile-design-guide.md b/apps/mobile/docs/mobile-design-guide.md
index ddc1b57947..379ac2912a 100644
--- a/apps/mobile/docs/mobile-design-guide.md
+++ b/apps/mobile/docs/mobile-design-guide.md
@@ -221,7 +221,7 @@ function Foo() {
### iOS 外壳 vs Cindy 内容
-- **项目标题滑动(iOS / Android)**:仅标题整行横移,展开的子任务不随之移动。右滑露出「新建任务」,超过屏宽 55% 松手打开预填项目电脑与目录的新建页;发送后才创建任务。左滑露出「全部任务」「搜索」,必须点按,搜索限定当前项目并聚焦输入框。点标题继续展开/收起,已有滑开行时先收起操作;自定义排序仍为长按后纵向拖动。项目与任务共用滑动互斥注册表,滚动收行,左屏缘保留返回手势。动作沿用圆形到胶囊的形态,标题内按钮为 44pt,使用双模式 token,并通过标题的无障碍动作提供等价入口。只对有明确电脑和目录的项目启用,不把对话或 Cindy Make 聚合组视为单一目录。实现见 `src/session/SwipeableProjectHeader.tsx`、`HomeSurface.tsx`。
+- **项目标题滑动(iOS / Android)**:仅标题整行横移,展开的子任务不随之移动。左滑露出「新建任务」,超过屏宽 55% 松手打开预填项目电脑与目录的新建页;发送后才创建任务。右滑露出「全部任务」「搜索」,必须点按,搜索限定当前项目并聚焦输入框。点标题继续展开/收起,已有滑开行时先收起操作;自定义排序仍为长按后纵向拖动。项目与任务共用滑动互斥注册表,滚动收行,左屏缘保留返回手势。动作沿用普通任务的圆形到胶囊形态,按钮直径为 56pt,间距使用 spacing.md、图标使用 iconSize.swipeAction;使用双模式 token,并通过标题的无障碍动作提供等价入口。只对有明确电脑和目录的项目启用,不把对话或 Cindy Make 聚合组视为单一目录。实现见 `src/session/SwipeableProjectHeader.tsx`、`HomeSurface.tsx`。
- **任务/伙伴切换**:按左任务、右伙伴的顺序做同一套横向滑动转场,抽屉和标题下拉选择都复用 HomeModePanes;不重建已访问列表,不丢搜索或滚动位置。滑动用不回弹的临界阻尼弹簧(参数见 DESIGN.md §14.4),快速反向切换从当前位置继续;系统减弱动态效果或尚未取得该偏好时直接切换。滑动只用于 iOS;Android 顶栏画在各自页面里,滑动会带着顶栏一起走,因此保持直接切换。导航栏和顶部模糊固定不动,模糊由 HomeModePanes 统一绘制一层。
- **首页菜单提示点**:可见圆点直径 6pt,原生工具栏用同尺寸画布的有点/无点模板图,避免空的数字徽章被系统放大。图标位置、按钮外框和点击范围不随提示点出现而变化。
diff --git a/apps/mobile/src/__tests__/swipeableProjectHeader.test.tsx b/apps/mobile/src/__tests__/swipeableProjectHeader.test.tsx
index 2f2e81612f..9129063a52 100644
--- a/apps/mobile/src/__tests__/swipeableProjectHeader.test.tsx
+++ b/apps/mobile/src/__tests__/swipeableProjectHeader.test.tsx
@@ -1,48 +1,85 @@
// @vitest-environment jsdom
-import { act, createElement, type ReactNode } from 'react';
-import { createRoot, type Root } from 'react-dom/client';
-import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
-import { SwipeableProjectHeader } from '@/session/SwipeableProjectHeader';
-import { createSwipeRowRegistry } from '@/session/swipeRowRegistry';
+import { act, createElement, type ReactNode } from "react";
+import { createRoot, type Root } from "react-dom/client";
+import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
+import { SwipeableProjectHeader } from "@/session/SwipeableProjectHeader";
+import { createSwipeRowRegistry } from "@/session/swipeRowRegistry";
const native = vi.hoisted(() => ({
- props: null as any, offset: { value: 0 }, close: vi.fn(), reset: vi.fn(),
+ props: null as any,
+ offset: { value: 0 },
+ close: vi.fn(),
+ reset: vi.fn(),
}));
-vi.mock('react-native', async () => {
- const { createElement: el } = await import('react');
+vi.mock("react-native", async () => {
+ const { createElement: el } = await import("react");
return {
- View: ({ children }: { children?: ReactNode }) => el('div', null, children),
+ View: ({ children }: { children?: ReactNode }) => el("div", null, children),
Pressable: ({ children, accessibilityLabel, onPress }: any) =>
- el('button', { 'aria-label': accessibilityLabel, onClick: onPress }, children),
+ el(
+ "button",
+ { "aria-label": accessibilityLabel, onClick: onPress },
+ children,
+ ),
StyleSheet: { create: (value: unknown) => value },
useWindowDimensions: () => ({ width: 400 }),
};
});
-vi.mock('react-native-reanimated', async () => {
- const { View } = await import('react-native');
- return { default: { View }, useAnimatedStyle: (factory: () => unknown) => factory(),
- interpolate: () => 1 };
+vi.mock("react-native-reanimated", async () => {
+ const { View } = await import("react-native");
+ return {
+ default: { View },
+ useAnimatedStyle: (factory: () => unknown) => factory(),
+ interpolate: () => 1,
+ };
});
-vi.mock('@/platform/gestureHandler', async () => {
- const { createElement: el, Fragment, forwardRef, useImperativeHandle } = await import('react');
+vi.mock("@/platform/gestureHandler", async () => {
+ const {
+ createElement: el,
+ Fragment,
+ forwardRef,
+ useImperativeHandle,
+ } = await import("react");
return {
- SwipeDirection: { RIGHT: 'right', LEFT: 'left' },
+ SwipeDirection: { RIGHT: "right", LEFT: "left" },
ReanimatedSwipeable: forwardRef((props: any, ref) => {
native.props = props;
- useImperativeHandle(ref, () => ({ close: native.close, reset: native.reset }));
- return el(Fragment, null, props.renderLeftActions({}, native.offset),
- props.renderRightActions({}, native.offset), props.children);
+ useImperativeHandle(ref, () => ({
+ close: native.close,
+ reset: native.reset,
+ }));
+ return el(
+ Fragment,
+ null,
+ el(
+ "div",
+ { "data-side": "left" },
+ props.renderLeftActions({}, native.offset),
+ ),
+ el(
+ "div",
+ { "data-side": "right" },
+ props.renderRightActions({}, native.offset),
+ ),
+ props.children,
+ );
}),
};
});
-vi.mock('lucide-react-native', () => ({ List: () => null, Search: () => null, SquarePen: () => null }));
-vi.mock('react-i18next', async (importOriginal) => ({
- ...await importOriginal<typeof import('react-i18next')>(),
+vi.mock("lucide-react-native", () => ({
+ List: () => null,
+ Search: () => null,
+ SquarePen: () => null,
+}));
+vi.mock("react-i18next", async (importOriginal) => ({
+ ...(await importOriginal<typeof import("react-i18next")>()),
useTranslation: () => ({ t: (key: string) => key }),
}));
-vi.mock('@/theme', () => ({
- iconSize: { xl: 24 }, iconStroke: { regular: 2 },
- useTheme: () => ({ colors: {} }), useThemedStyles: (make: (colors: object) => unknown) => make({}),
+vi.mock("@/theme", () => ({
+ iconSize: { swipeAction: 23 },
+ iconStroke: { regular: 2 },
+ useTheme: () => ({ colors: {} }),
+ useThemedStyles: (make: (colors: object) => unknown) => make({}),
}));
Object.assign(globalThis, { IS_REACT_ACT_ENVIRONMENT: true });
@@ -50,19 +87,33 @@ let root: Root;
let host: HTMLDivElement;
let registry: ReturnType<typeof createSwipeRowRegistry>;
let destination: string;
-function render(projectKey = 'project-a') {
- act(() => root.render(createElement(SwipeableProjectHeader, {
- projectKey, registry,
- onNewTask: () => { destination = 'new'; },
- onOpenTasks: () => { destination = 'tasks'; },
- onSearch: () => { destination = 'search'; },
- children: 'Project',
- })));
+function render(projectKey = "project-a") {
+ act(() =>
+ root.render(
+ createElement(SwipeableProjectHeader, {
+ projectKey,
+ registry,
+ onNewTask: () => {
+ destination = "new";
+ },
+ onOpenTasks: () => {
+ destination = "tasks";
+ },
+ onSearch: () => {
+ destination = "search";
+ },
+ children: "Project",
+ }),
+ ),
+ );
}
beforeEach(() => {
- vi.clearAllMocks(); native.offset.value = 0;
- registry = createSwipeRowRegistry(); destination = 'home';
- host = document.createElement('div'); root = createRoot(host);
+ vi.clearAllMocks();
+ native.offset.value = 0;
+ registry = createSwipeRowRegistry();
+ destination = "home";
+ host = document.createElement("div");
+ root = createRoot(host);
});
afterEach(() => act(() => root.unmount()));
@@ -70,43 +121,56 @@ afterEach(() => act(() => root.unmount()));
// session-row tests cover archive/pin and classic Animated, not these navigation
// actions. Minimal failures: pull past the threshold then retract, or reuse an
// opened project row while a task row owns the same page registry.
-describe('project header navigation and swipe lifecycle', () => {
+// The requested side swap moves new-task and its full-swipe trigger to the right
+// panel; clicking the revealed left panel must still open tasks/search (unit).
+describe("project header navigation and swipe lifecycle", () => {
it.each([
- ['right', 260, 'new'],
- ['right', 100, 'home'],
- ['left', -260, 'home'],
- ])('only opens new-task on a released full right swipe (%s, %s)', (direction, end, target) => {
- render();
- act(() => native.props.onSwipeableOpenStartDrag());
- native.offset.value = 280;
- expect(destination).toBe('home');
- native.offset.value = Number(end);
- act(() => native.props.onSwipeableWillOpen(direction));
- expect(destination).toBe(target);
- if (target === 'new') {
- expect(native.close).toHaveBeenCalledOnce();
- expect(registry.closeOpenRow()).toBe(false);
- }
- });
-
- it.each([['newTask', 'new'], ['allTasks', 'tasks'], ['search', 'search']])(
- 'closes the revealed header before opening %s', (action, target) => {
+ ["left", -260, "new"],
+ ["left", -100, "home"],
+ ["right", 260, "home"],
+ ])(
+ "only opens new-task on a released full left swipe (%s, %s)",
+ (direction, end, target) => {
render();
act(() => native.props.onSwipeableOpenStartDrag());
- act(() => host.querySelector<HTMLButtonElement>(`[aria-label="devices.list.projectActions.${action}"]`)!.click());
+ native.offset.value = -280;
+ expect(destination).toBe("home");
+ native.offset.value = Number(end);
+ act(() => native.props.onSwipeableWillOpen(direction));
expect(destination).toBe(target);
- expect(native.close).toHaveBeenCalledOnce();
- expect(registry.closeOpenRow()).toBe(false);
+ if (target === "new") {
+ expect(native.close).toHaveBeenCalledOnce();
+ expect(registry.closeOpenRow()).toBe(false);
+ }
},
);
- it('shares mutual exclusion with task rows and does not clear their newer registration', () => {
+ it.each([
+ ["newTask", "new", "right"],
+ ["allTasks", "tasks", "left"],
+ ["search", "search", "left"],
+ ])("closes the revealed header before opening %s", (action, target, side) => {
+ render();
+ act(() => native.props.onSwipeableOpenStartDrag());
+ act(() =>
+ host
+ .querySelector<HTMLButtonElement>(
+ `[data-side="${side}"] [aria-label="devices.list.projectActions.${action}"]`,
+ )!
+ .click(),
+ );
+ expect(destination).toBe(target);
+ expect(native.close).toHaveBeenCalledOnce();
+ expect(registry.closeOpenRow()).toBe(false);
+ });
+
+ it("shares mutual exclusion with task rows and does not clear their newer registration", () => {
render();
const closeTask = vi.fn();
- registry.onRowOpen('task-a', closeTask);
+ registry.onRowOpen("task-a", closeTask);
act(() => native.props.onSwipeableOpenStartDrag());
expect(closeTask).toHaveBeenCalledOnce();
- registry.onRowOpen('task-b', closeTask);
+ registry.onRowOpen("task-b", closeTask);
expect(native.close).toHaveBeenCalledOnce();
act(() => native.props.onSwipeableClose());
act(() => root.render(null));
@@ -114,11 +178,11 @@ describe('project header navigation and swipe lifecycle', () => {
expect(closeTask).toHaveBeenCalledTimes(2);
});
- it('resets a recycled header and retires its previous open-row registration', () => {
+ it("resets a recycled header and retires its previous open-row registration", () => {
render();
act(() => native.props.onSwipeableOpenStartDrag());
native.reset.mockClear();
- render('project-b');
+ render("project-b");
expect(native.reset).toHaveBeenCalledOnce();
expect(registry.closeOpenRow()).toBe(false);
act(() => native.props.onSwipeableOpenStartDrag());
diff --git a/apps/mobile/src/session/SwipeableProjectHeader.tsx b/apps/mobile/src/session/SwipeableProjectHeader.tsx
index 4c29e7d510..94fc47239e 100644
--- a/apps/mobile/src/session/SwipeableProjectHeader.tsx
+++ b/apps/mobile/src/session/SwipeableProjectHeader.tsx
@@ -1,18 +1,32 @@
-import { memo, useCallback, useEffect, useRef, type ReactNode } from 'react';
-import { Pressable, StyleSheet, View, useWindowDimensions } from 'react-native';
-import Animated, { interpolate, useAnimatedStyle, type SharedValue } from 'react-native-reanimated';
-import { List, Search, SquarePen, type LucideIcon } from 'lucide-react-native';
-import { useTranslation } from 'react-i18next';
-import { ReanimatedSwipeable, SwipeDirection, type SwipeableMethods } from '@/platform/gestureHandler';
-import type { SwipeRowRegistry } from './swipeRowRegistry';
-import { iconSize, iconStroke, useTheme, useThemedStyles, type ThemeColors } from '@/theme';
-import { radius, spacing } from '@/theme/tokens';
+import { memo, useCallback, useEffect, useRef, type ReactNode } from "react";
+import { Pressable, StyleSheet, View, useWindowDimensions } from "react-native";
+import Animated, {
+ interpolate,
+ useAnimatedStyle,
+ type SharedValue,
+} from "react-native-reanimated";
+import { List, Search, SquarePen, type LucideIcon } from "lucide-react-native";
+import { useTranslation } from "react-i18next";
+import {
+ ReanimatedSwipeable,
+ SwipeDirection,
+ type SwipeableMethods,
+} from "@/platform/gestureHandler";
+import type { SwipeRowRegistry } from "./swipeRowRegistry";
+import {
+ iconSize,
+ iconStroke,
+ useTheme,
+ useThemedStyles,
+ type ThemeColors,
+} from "@/theme";
+import { radius, spacing } from "@/theme/tokens";
-// The project header is 56pt high; 44pt actions retain a full touch target.
-const ACTION_SIZE = 44;
-const GAP = spacing.sm;
-const LEADING_WIDTH = ACTION_SIZE + GAP * 2;
-const TRAILING_WIDTH = ACTION_SIZE * 2 + GAP * 3;
+// Match the floating circular actions in SwipeableSessionRow on both platforms.
+const ACTION_SIZE = 56;
+const GAP = spacing.md;
+const LEADING_WIDTH = ACTION_SIZE * 2 + GAP * 3;
+const TRAILING_WIDTH = ACTION_SIZE + GAP * 2;
interface Props {
projectKey: string;
@@ -25,7 +39,12 @@ interface Props {
/** Only wraps the header, so expanded tasks never move with the project swipe. */
export const SwipeableProjectHeader = memo(function SwipeableProjectHeader({
- projectKey, registry, onNewTask, onOpenTasks, onSearch, children,
+ projectKey,
+ registry,
+ onNewTask,
+ onOpenTasks,
+ onSearch,
+ children,
}: Props) {
const { t } = useTranslation();
const { colors } = useTheme();
@@ -39,11 +58,14 @@ export const SwipeableProjectHeader = memo(function SwipeableProjectHeader({
methods.current?.reset();
return () => registry.onRowClose(rowKey);
}, [registry, rowKey]);
- const run = useCallback((action: () => void) => {
- registry.onRowClose(rowKey);
- close();
- action();
- }, [close, registry, rowKey]);
+ const run = useCallback(
+ (action: () => void) => {
+ registry.onRowClose(rowKey);
+ close();
+ action();
+ },
+ [close, registry, rowKey],
+ );
return (
<ReanimatedSwipeable
@@ -53,33 +75,61 @@ export const SwipeableProjectHeader = memo(function SwipeableProjectHeader({
childrenContainerStyle={styles.surface}
// Leave the screen edge available to native back navigation.
hitSlop={{ left: -spacing.xl }}
- overshootRight={false}
+ overshootLeft={false}
onSwipeableOpenStartDrag={() => registry.onRowOpen(rowKey, close)}
onSwipeableClose={() => registry.onRowClose(rowKey)}
onSwipeableWillOpen={(direction) => {
- // Release only. Left swipes always require an explicit action tap.
- if (direction === SwipeDirection.RIGHT && (translation.current?.value ?? 0) >= width * 0.55) {
+ // Release only. Right swipes always require an explicit action tap.
+ if (
+ direction === SwipeDirection.LEFT &&
+ -(translation.current?.value ?? 0) >= width * 0.55
+ ) {
run(onNewTask);
}
}}
renderLeftActions={(_progress, offset) => {
translation.current = offset;
- return <View style={styles.leadingShell}>
- <ProjectAction icon={SquarePen} label={t('devices.list.projectActions.newTask')}
- onPress={() => run(onNewTask)} offset={offset} leading styles={styles}
- background={colors.cta} foreground={colors.ctaText} />
- </View>;
+ return (
+ <View style={styles.leadingShell}>
+ <ProjectAction
+ icon={List}
+ label={t("devices.list.projectActions.allTasks")}
+ onPress={() => run(onOpenTasks)}
+ offset={offset}
+ leading
+ styles={styles}
+ background={colors.swipeActionNeutral}
+ foreground={colors.swipeActionText}
+ />
+ <ProjectAction
+ icon={Search}
+ label={t("devices.list.projectActions.search")}
+ onPress={() => run(onSearch)}
+ offset={offset}
+ leading
+ styles={styles}
+ background={colors.swipeActionNeutral}
+ foreground={colors.swipeActionText}
+ index={1}
+ />
+ </View>
+ );
}}
renderRightActions={(_progress, offset) => {
translation.current = offset;
- return <View style={styles.trailingShell}>
- <ProjectAction icon={List} label={t('devices.list.projectActions.allTasks')}
- onPress={() => run(onOpenTasks)} offset={offset} styles={styles}
- background={colors.swipeActionNeutral} foreground={colors.swipeActionText} index={1} />
- <ProjectAction icon={Search} label={t('devices.list.projectActions.search')}
- onPress={() => run(onSearch)} offset={offset} styles={styles}
- background={colors.swipeActionNeutral} foreground={colors.swipeActionText} />
- </View>;
+ return (
+ <View style={styles.trailingShell}>
+ <ProjectAction
+ icon={SquarePen}
+ label={t("devices.list.projectActions.newTask")}
+ onPress={() => run(onNewTask)}
+ offset={offset}
+ styles={styles}
+ background={colors.cta}
+ foreground={colors.ctaText}
+ />
+ </View>
+ );
}}
>
{children}
@@ -87,7 +137,17 @@ export const SwipeableProjectHeader = memo(function SwipeableProjectHeader({
);
});
-function ProjectAction({ icon: Icon, label, onPress, offset, leading = false, index = 0, styles, background, foreground }: {
+function ProjectAction({
+ icon: Icon,
+ label,
+ onPress,
+ offset,
+ leading = false,
+ index = 0,
+ styles,
+ background,
+ foreground,
+}: {
icon: LucideIcon;
label: string;
onPress(): void;
@@ -100,39 +160,66 @@ function ProjectAction({ icon: Icon, label, onPress, offset, leading = false, in
}) {
const animatedStyle = useAnimatedStyle(() => {
const revealed = Math.max(0, leading ? offset.value : -offset.value);
- const progress = Math.min(1, revealed / (leading ? LEADING_WIDTH : TRAILING_WIDTH));
+ const progress = Math.min(
+ 1,
+ revealed / (leading ? LEADING_WIDTH : TRAILING_WIDTH),
+ );
return {
- opacity: interpolate(progress, [0.15, 0.7], [0, 1], 'clamp'),
- transform: [{ scale: interpolate(progress, [0.15, 1], [0.5, 1], 'clamp') }],
- width: leading ? Math.max(ACTION_SIZE, revealed - GAP * 2) : ACTION_SIZE,
+ opacity: interpolate(progress, [0.15, 0.7], [0, 1], "clamp"),
+ transform: [
+ { scale: interpolate(progress, [0.15, 1], [0.5, 1], "clamp") },
+ ],
+ width: leading ? ACTION_SIZE : Math.max(ACTION_SIZE, revealed - GAP * 2),
};
});
- return <Animated.View style={[styles.action, { backgroundColor: background },
- leading ? { left: GAP } : { right: GAP + index * (ACTION_SIZE + GAP) }, animatedStyle]}>
- <Pressable accessibilityLabel={label} accessibilityRole="button" onPress={onPress}
- style={styles.pressable}>
- <View style={styles.icon}>
- <Icon size={iconSize.xl} strokeWidth={iconStroke.regular} color={foreground} />
- </View>
- </Pressable>
- </Animated.View>;
+ return (
+ <Animated.View
+ style={[
+ styles.action,
+ { backgroundColor: background },
+ leading ? { left: GAP + index * (ACTION_SIZE + GAP) } : { right: GAP },
+ animatedStyle,
+ ]}
+ >
+ <Pressable
+ accessibilityLabel={label}
+ accessibilityRole="button"
+ onPress={onPress}
+ style={styles.pressable}
+ >
+ <View style={styles.icon}>
+ <Icon
+ size={iconSize.swipeAction}
+ strokeWidth={iconStroke.regular}
+ color={foreground}
+ />
+ </View>
+ </Pressable>
+ </Animated.View>
+ );
}
-const makeStyles = (colors: ThemeColors) => StyleSheet.create({
- surface: { backgroundColor: colors.surface },
- leadingShell: { width: LEADING_WIDTH, overflow: 'visible' },
- trailingShell: { width: TRAILING_WIDTH, overflow: 'visible' },
- action: {
- borderRadius: radius.pill,
- height: ACTION_SIZE,
- position: 'absolute',
- top: '50%',
- marginTop: -ACTION_SIZE / 2,
- overflow: 'hidden',
- },
- pressable: { flex: 1 },
- icon: {
- alignItems: 'center', justifyContent: 'center',
- position: 'absolute', top: 0, bottom: 0, right: 0, width: ACTION_SIZE,
- },
-});
+const makeStyles = (colors: ThemeColors) =>
+ StyleSheet.create({
+ surface: { backgroundColor: colors.surface },
+ leadingShell: { width: LEADING_WIDTH, overflow: "visible" },
+ trailingShell: { width: TRAILING_WIDTH, overflow: "visible" },
+ action: {
+ borderRadius: radius.pill,
+ height: ACTION_SIZE,
+ position: "absolute",
+ top: "50%",
+ marginTop: -ACTION_SIZE / 2,
+ overflow: "hidden",
+ },
+ pressable: { flex: 1 },
+ icon: {
+ alignItems: "center",
+ justifyContent: "center",
+ position: "absolute",
+ top: 0,
+ bottom: 0,
+ left: 0,
+ width: ACTION_SIZE,
+ },
+ });