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): 修复任务列表滚入分组时短暂空白

Dash3ffa54982f98
diff --git a/apps/mobile/src/__tests__/homeAutomationWindow.test.tsx b/apps/mobile/src/__tests__/homeAutomationWindow.test.tsx
index ee82867642..b9921fab3e 100644
--- a/apps/mobile/src/__tests__/homeAutomationWindow.test.tsx
+++ b/apps/mobile/src/__tests__/homeAutomationWindow.test.tsx
@@ -65,10 +65,9 @@ it('bounds 200 recent runs before layout, while scrolling, and when reversing to
const { elements, onOpenSession } = renderChildren(200, anchor);
const rows = elements.filter(node => node.type === 'row');
expect(rows.length).toBeLessThanOrEqual(23);
- expect(rows.length).toBe(anchor < 0 ? 0 : anchor === 196 ? 15 : 23);
+ expect(rows.length).toBe(anchor === 196 ? 15 : 23);
const spacerHeight = elements.filter(node => node.type === 'view').reduce((sum, node) => sum + (node.props.style?.height ?? 0), 0);
expect(spacerHeight + rows.length * 60).toBe(200 * 60);
- if (anchor < 0) continue;
const first = rows[0];
first.props.onOpenSession(first.props.item);
expect(onOpenSession).toHaveBeenCalledWith(first.props.item);
@@ -80,6 +79,16 @@ it('bounds 200 recent runs before layout, while scrolling, and when reversing to
}
});
+// Regression: a 23-task folder entered the viewport as a full-height blank.
+// Existing cases only checked bounded mounting after measurement. Unit tier:
+// exercise the production renderer before any native layout/scroll callback.
+it('renders a 23-row group immediately instead of waiting for native measurement', () => {
+ const rows = renderChildren(23, -1).elements.filter(node => node.type === 'row');
+ expect(rows).toHaveLength(23);
+ expect(rows[0].props.item.session.id).toBe('s0');
+ expect(rows.at(-1)!.props.item.session.id).toBe('s22');
+});
+
it('preserves small previews and the view-all action for old runs', () => {
expect(renderChildren(5, -1).elements.filter(node => node.type === 'row')).toHaveLength(5);
const { elements } = renderChildren(200, -1, true);
@@ -156,7 +165,7 @@ it('connects native layout and scroll measurements through the real tracker to r
</Viewport.Provider>));
frame(200, 0);
expect(measure).not.toHaveBeenCalled();
- expect(rows()).toHaveLength(0);
+ expect(rows()).toHaveLength(23);
act(() => onLayout());
frame(200, 0);
expect(rows()).toHaveLength(23);
@@ -170,7 +179,9 @@ it('connects native layout and scroll measurements through the real tracker to r
frame(-11800, 12000);
expect(rows().at(-1)?.dataset.row).toBe('s199');
frame(-12000, 12200);
- expect(rows()).toHaveLength(0); // Fully outside the viewport.
+ // Leaving the viewport must not discard the last bounded window: a
+ // reverse scroll can reveal it before the JS update is delivered.
+ expect(rows().at(-1)?.dataset.row).toBe('s199');
frame(-11800, 12000);
expect(rows().at(-1)?.dataset.row).toBe('s199');
frame(200, 0);
diff --git a/apps/mobile/src/__tests__/homeProjectChildWindow.test.ts b/apps/mobile/src/__tests__/homeProjectChildWindow.test.ts
index e093a2688e..d0c22ff927 100644
--- a/apps/mobile/src/__tests__/homeProjectChildWindow.test.ts
+++ b/apps/mobile/src/__tests__/homeProjectChildWindow.test.ts
@@ -45,7 +45,7 @@ describe('home project child window', () => {
expect(anchor).toBe(36);
layout = { pageY: -3956 }; // The entire child area has actually left the screen.
react(prepare(), null);
- expect(anchor).toBe(-1);
+ expect(anchor).toBe(36);
layout = { pageY: -3800 }; // Reverse scrolling brings the final rows back.
react(prepare(), -1);
expect(anchor).toBe(48);
@@ -72,7 +72,7 @@ describe('home project child window', () => {
expect(initialRange.trailingSpacerHeight).toBeGreaterThan(0);
});
- it('keeps off-screen child content unmounted and anchors it once visible', () => {
+ it('skips anchor updates outside the viewport and locates children once visible', () => {
const childOffsets = buildHomeProjectChildOffsets(Array.from({ length: 112 }, () => 78));
expect(resolveHomeProjectChildAnchor({
diff --git a/apps/mobile/src/session/HomeSurface.tsx b/apps/mobile/src/session/HomeSurface.tsx
index 3e44c7a43e..9b47f2cabd 100644
--- a/apps/mobile/src/session/HomeSurface.tsx
+++ b/apps/mobile/src/session/HomeSurface.tsx
@@ -3715,9 +3715,10 @@ function HomeProjectWindowAnchorTracker({
});
},
(next, previous) => {
- // A temporarily unavailable native view is not evidence that its rows
- // left the viewport. Keep the last bounded window until measured again.
- if (next === null || next === previous) return;
+ // Keep the last bounded window when offscreen or unmeasurable. Clearing
+ // it leaves a blank until a later UI -> JS round trip on reverse scroll.
+ // The outer SectionList owns recycling of offscreen project blocks.
+ if (next === null || next < 0 || next === previous) return;
runOnJS(onAnchorChange)(next);
},
[childOffsets, onAnchorChange, projectHeaderHeight, projectLayoutRevision, projectRef, scrollY, viewportHeight],
@@ -3818,7 +3819,7 @@ function ProjectRow({
const textMode = useHomeRowDisplay().viewMode === 'text';
const projectRef = useAnimatedRef<View>();
const prepareDisclosure = useDisclosurePrepare();
- const [windowAnchor, setWindowAnchor] = useState(-1);
+ const [windowAnchor, setWindowAnchor] = useState(0);
const projectLayoutRevision = useSharedValue(0);
const estimatedChildHeights = useMemo(() => {
const expandedKeys = new Set(expandedAutomationGroups);
@@ -3828,11 +3829,10 @@ function ProjectRow({
() => buildHomeProjectChildOffsets(estimatedChildHeights),
[estimatedChildHeights],
);
- // Keep the common five-row preview unchanged. A large expanded group keeps
- // its complete estimated height as a spacer until native layout establishes
- // that its child area intersects the viewport. This avoids mounting an
- // off-screen child window just because the folder header entered the outer
- // SectionList render window.
+ // Render a bounded child window immediately, including before native layout
+ // is ready. A full-height placeholder here becomes visible when scrolling
+ // into a project before its measurement reaches JS. The outer SectionList
+ // still bounds mounted groups, and ordinary five-row previews are unchanged.
const windowingEnabled = shouldWindowHomeProjectChildren({
collapsed,
itemCount: visibleSessions.length,
@@ -3840,21 +3840,13 @@ function ProjectRow({
threshold: PROJECT_CHILD_WINDOW_THRESHOLD,
});
const scrollY = homeScrollY;
- const childContentHeight = estimatedChildOffsets[estimatedChildOffsets.length - 1] ?? 0;
const childWindow = windowingEnabled
- ? windowAnchor >= 0
- ? resolveHomeProjectChildWindow({
+ ? resolveHomeProjectChildWindow({
anchor: windowAnchor,
childOffsets: estimatedChildOffsets,
overscan: PROJECT_CHILD_WINDOW_OVERSCAN,
windowSize: PROJECT_CHILD_WINDOW_SIZE,
})
- : {
- end: 0,
- leadingSpacerHeight: 0,
- start: 0,
- trailingSpacerHeight: childContentHeight,
- }
: {
end: visibleSessions.length,
leadingSpacerHeight: 0,
@@ -4655,7 +4647,7 @@ function AutomationGroupChildren({
const childrenRef = useAnimatedRef<View>();
const layoutRevision = useSharedValue(0);
const headerHeight = useSharedValue(0);
- const [windowAnchor, setWindowAnchor] = useState(-1);
+ const [windowAnchor, setWindowAnchor] = useState(0);
const textMode = useHomeRowDisplay().viewMode === 'text';
const childOffsets = buildHomeProjectChildOffsets(visibleItems.map((child) => estimateHomeSessionRowHeight(child, textMode)));
const windowingEnabled = shouldWindowHomeProjectChildren({
@@ -4663,10 +4655,8 @@ function AutomationGroupChildren({
scrollTrackingAvailable: viewport !== null, threshold: PROJECT_CHILD_WINDOW_THRESHOLD,
});
const range = windowingEnabled
- ? windowAnchor >= 0
- ? resolveHomeProjectChildWindow({ anchor: windowAnchor, childOffsets,
+ ? resolveHomeProjectChildWindow({ anchor: windowAnchor, childOffsets,
overscan: PROJECT_CHILD_WINDOW_OVERSCAN, windowSize: PROJECT_CHILD_WINDOW_SIZE })
- : { start: 0, end: 0, leadingSpacerHeight: 0, trailingSpacerHeight: childOffsets.at(-1) ?? 0 }
: { start: 0, end: visibleItems.length, leadingSpacerHeight: 0, trailingSpacerHeight: 0 };
return (
<Reanimated.View ref={childrenRef} collapsable={false}
diff --git a/apps/mobile/src/session/homeProjectChildWindow.ts b/apps/mobile/src/session/homeProjectChildWindow.ts
index 312e3f6d45..cd93d9f149 100644
--- a/apps/mobile/src/session/homeProjectChildWindow.ts
+++ b/apps/mobile/src/session/homeProjectChildWindow.ts
@@ -50,9 +50,9 @@ export function findHomeProjectChildIndex(
}
/**
- * Keeps a large nested group as a spacer until its child area intersects the
- * viewport. This prevents an off-screen folder header from eagerly mounting a
- * complete child window during a grouping-mode switch.
+ * Finds the visible child anchor. A negative result means the group is outside
+ * the viewport; callers retain their bounded window until the outer list
+ * recycles the group so reverse scrolling never starts with an empty block.
*/
export function resolveHomeProjectChildAnchor(input: {
childOffsets: readonly number[];