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): stabilize Android settings disclosure

WEIWEICurryd56bf9bc23e4
diff --git a/apps/mobile/app/settings.tsx b/apps/mobile/app/settings.tsx
index 66e0ce8ab7..e5653c74f8 100644
--- a/apps/mobile/app/settings.tsx
+++ b/apps/mobile/app/settings.tsx
@@ -601,8 +601,12 @@ export default function SettingsScreen() {
}
}, [auth.apiFetch, pushBusy, pushEnabled, t]);
- // 调试分组与首页列表共用同一套展开 / 收起过渡(listDisclosureTransition)。
- const debugDisclosure = useListDisclosureTransition();
+ // Android 10 上快速反向切换这组父卡片 layout + 多行 exiting 时会出现重叠 / 空白。
+ // 设置页在 Android 上同步重排,避免退出视图参与后续布局;保留 iOS 动画与原状态逻辑。
+ const debugDisclosureMotionEnabled = Platform.OS !== 'android';
+ const debugDisclosure = useListDisclosureTransition({
+ motionEnabled: debugDisclosureMotionEnabled,
+ });
const runDebugDisclosure = debugDisclosure.run;
const toggleDebug = useCallback(() => {
runDebugDisclosure(() => setDebugExpanded((value) => !value));
@@ -759,7 +763,10 @@ export default function SettingsScreen() {
/>
<ScrollView {...simpleScrollInsetProps} contentContainerStyle={styles.content} testID="settings.scroll">
- <ListDisclosureScope controller={debugDisclosure.controller}>
+ <ListDisclosureScope
+ controller={debugDisclosure.controller}
+ motionEnabled={debugDisclosureMotionEnabled}
+ >
{/* 账号头部:身份 + 连接状态一次性呈现,下面分组不再重复 */}
<View style={styles.headerCard} testID="settings.accountHeader">
<MobileUserAvatar imageUrl={auth.user?.avatar} name={overview.header.name} size="large" />
diff --git a/apps/mobile/src/__tests__/mobileSettings.test.ts b/apps/mobile/src/__tests__/mobileSettings.test.ts
index fb5a3a4365..775e4e74a5 100644
--- a/apps/mobile/src/__tests__/mobileSettings.test.ts
+++ b/apps/mobile/src/__tests__/mobileSettings.test.ts
@@ -40,6 +40,23 @@ describe('mobile settings overview', () => {
expect(source).not.toContain('LanguageOptionRow');
});
+ it('keeps Android debug disclosure synchronous so repeated toggles cannot retain exiting rows', () => {
+ const source = readTextLf(resolve(process.cwd(), 'app/settings.tsx'), 'utf8');
+
+ expect(source).toContain("const debugDisclosureMotionEnabled = Platform.OS !== 'android';");
+ expect(source).toContain([
+ 'useListDisclosureTransition({',
+ ' motionEnabled: debugDisclosureMotionEnabled,',
+ ' })',
+ ].join('\n'));
+ expect(source).toContain([
+ '<ListDisclosureScope',
+ ' controller={debugDisclosure.controller}',
+ ' motionEnabled={debugDisclosureMotionEnabled}',
+ ].join('\n'));
+ expect(source).toContain('runDebugDisclosure(() => setDebugExpanded((value) => !value));');
+ });
+
it('shows the server switch only in CindyDev and clears the old session before reloading', () => {
const settingsSource = readTextLf(
resolve(process.cwd(), 'app/settings.tsx'),
diff --git a/apps/mobile/src/session/listDisclosureTransition.tsx b/apps/mobile/src/session/listDisclosureTransition.tsx
index d0b59ea8fc..c4c514731b 100644
--- a/apps/mobile/src/session/listDisclosureTransition.tsx
+++ b/apps/mobile/src/session/listDisclosureTransition.tsx
@@ -78,16 +78,18 @@ const motionAllowed = () => getCachedReduceMotionEnabled() === false;
* layout effect 里)立刻执行 apply;窗口在动画结束后自动收回。系统「减弱动态效果」
* 开启、或列表不在屏上时直接执行。窗口逻辑见 listDisclosureController.ts。
*/
-export function useListDisclosureTransition() {
+export function useListDisclosureTransition({
+ motionEnabled = true,
+}: { motionEnabled?: boolean } = {}) {
const controller = useRef<DisclosureController>(createDisclosureController()).current;
/** nested:要切换的分组嵌在另一个分组块里(项目里的自动化组),块内的行也要让位。 */
const run = useCallback((apply: () => void, options?: { nested?: boolean }) => {
- runDisclosure(controller, apply, options?.nested ? 2 : 1, motionAllowed());
- }, [controller]);
+ runDisclosure(controller, apply, options?.nested ? 2 : 1, motionEnabled && motionAllowed());
+ }, [controller, motionEnabled]);
/** 分组标题的 onPressIn:手指按下即提前挂上动画,松手时直接执行。 */
const prepare = useCallback(() => {
- openDisclosureWindow(controller, 1, motionAllowed());
- }, [controller]);
+ openDisclosureWindow(controller, 1, motionEnabled && motionAllowed());
+ }, [controller, motionEnabled]);
useEffect(() => () => {
if (controller.timer) clearTimeout(controller.timer);
}, [controller]);
@@ -95,7 +97,15 @@ export function useListDisclosureTransition() {
}
/** 包住列表:持有开关状态,开关变化只重渲染挂动画的行。 */
-export function ListDisclosureScope({ children, controller }: { children: ReactNode; controller: DisclosureController }) {
+export function ListDisclosureScope({
+ children,
+ controller,
+ motionEnabled = true,
+}: {
+ children: ReactNode;
+ controller: DisclosureController;
+ motionEnabled?: boolean;
+}) {
const [level, setLevel] = useState<DisclosureLevel>(0);
useLayoutEffect(() => {
controller.setLevel = setLevel;
@@ -106,8 +116,8 @@ export function ListDisclosureScope({ children, controller }: { children: ReactN
commitRegisteredLevel(controller, level);
}, [level, controller]);
const prepare = useCallback((nested?: boolean) => {
- openDisclosureWindow(controller, nested ? 2 : 1, motionAllowed());
- }, [controller]);
+ openDisclosureWindow(controller, nested ? 2 : 1, motionEnabled && motionAllowed());
+ }, [controller, motionEnabled]);
return (
<DisclosurePrepareContext.Provider value={prepare}>
<DisclosureLevelContext.Provider value={level}>{children}</DisclosureLevelContext.Provider>