Skip to content

Commit 7966342

Browse files
fix(mobile): releasing short of the thread feed's end no longer re-arms end following
Legend List's default maintainScrollAtEndThreshold (0.1 of the viewport) re-arms end following when a user scroll settles within that distance, so a feed pulled to its start edge 77.8pt from the end snapped back even with isAtEnd corrected. The feed now sets the threshold to 0, and the regression test drives the release through checkAtBottom and settleUserScroll with the feed's own configuration. AI-assisted; verified with the tests and tools listed above. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 6055493 commit 7966342

3 files changed

Lines changed: 59 additions & 21 deletions

File tree

‎apps/mobile/src/features/threads/ThreadFeed.tsx‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,10 @@ import {
277277
import { openSettings } from "../settings/settings-navigation";
278278
import { useSelectWorkspaceDetail } from "../layout/workspace/useSelectWorkspaceDetail";
279279
import { formatMessageTimestamp } from "./messageTimestamp";
280+
import {
281+
THREAD_FEED_MAINTAIN_SCROLL_AT_END,
282+
THREAD_FEED_MAINTAIN_SCROLL_AT_END_THRESHOLD,
283+
} from "./threadFeedEndFollow";
280284

281285
const WIDE_MARKDOWN_BLOCK_OPTIONS = {
282286
// iOS blockquotes and selectable text measure separately; definite bubble width matches UIKit's drawing width.
@@ -2646,11 +2650,6 @@ function DisclosureRow(props: {
26462650
);
26472651
}
26482652

2649-
const THREAD_FEED_MAINTAIN_SCROLL_AT_END = {
2650-
animated: false,
2651-
on: { dataChange: true, itemLayout: true, layout: true },
2652-
} as const;
2653-
26542653
export const ThreadFeed = memo(function ThreadFeed(props: ThreadFeedProps) {
26552654
const { listRef, onIsAtEndChange, onHeaderMaterialVisibilityChange } = props;
26562655
const workflowOpening = useWorkflowOpening(props.detailRef);
@@ -3671,6 +3670,7 @@ export const ThreadFeed = memo(function ThreadFeed(props: ThreadFeedProps) {
36713670
{...(usesNativeAutomaticInsets ? { contentInset: { top: anchorTopInset } } : {})}
36723671
freeze={props.freeze}
36733672
maintainScrollAtEnd={jumpReady ? false : THREAD_FEED_MAINTAIN_SCROLL_AT_END}
3673+
maintainScrollAtEndThreshold={THREAD_FEED_MAINTAIN_SCROLL_AT_END_THRESHOLD}
36743674
maintainVisibleContentPosition
36753675
data={groupedFeed}
36763676
extraData={listAppearanceData}

‎apps/mobile/src/features/threads/legendListAtEnd.test.ts‎

Lines changed: 46 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,23 @@ import * as NodeVM from "node:vm";
55

66
import { describe, expect, it } from "vite-plus/test";
77

8+
import {
9+
THREAD_FEED_MAINTAIN_SCROLL_AT_END,
10+
THREAD_FEED_MAINTAIN_SCROLL_AT_END_THRESHOLD,
11+
} from "./threadFeedEndFollow";
12+
813
const require = NodeModule.createRequire(import.meta.url);
914

10-
// checkAtBottom is internal to the patched bundle; expose it from the native build as seen on iOS.
11-
function loadPatchedCheckAtBottom() {
15+
interface ListInternals {
16+
readonly checkAtBottom: (ctx: unknown) => void;
17+
readonly settleUserScroll: (ctx: unknown) => void;
18+
}
19+
20+
// The end checks are internal to the patched bundle; expose them from the native build as seen on iOS.
21+
function loadPatchedListInternals(): ListInternals {
1222
const webBundlePath = require.resolve("@legendapp/list/react-native");
1323
const bundlePath = NodePath.join(NodePath.dirname(webBundlePath), "react-native.js");
14-
const source = `${NodeFS.readFileSync(bundlePath, "utf8")}\nmodule.exports.checkAtBottom = checkAtBottom;`;
24+
const source = `${NodeFS.readFileSync(bundlePath, "utf8")}\nmodule.exports.internals = { checkAtBottom, settleUserScroll };`;
1525
const inert: object = new Proxy(function () {}, {
1626
get: (_target, key) => (key === Symbol.toPrimitive ? () => "" : inert),
1727
apply: () => inert,
@@ -22,50 +32,59 @@ function loadPatchedCheckAtBottom() {
2232
get: (object, key) => (key in object ? Reflect.get(object, key) : inert),
2333
});
2434
const reactNative = withInertFallback({ Platform: withInertFallback({ OS: "ios" }) });
25-
const module = { exports: {} as { checkAtBottom?: (ctx: unknown) => void } };
35+
const module = { exports: {} as { internals?: ListInternals } };
2636
NodeVM.compileFunction(source, ["exports", "require", "module"], { filename: bundlePath })(
2737
module.exports,
2838
(id: string) => (id === "react-native" ? reactNative : inert),
2939
module,
3040
);
31-
const checkAtBottom = module.exports.checkAtBottom;
32-
if (!checkAtBottom) throw new Error(`checkAtBottom not found in ${bundlePath}`);
33-
return checkAtBottom;
41+
const internals = module.exports.internals;
42+
if (!internals) throw new Error(`list internals not found in ${bundlePath}`);
43+
return internals;
3444
}
3545

36-
const checkAtBottom = loadPatchedCheckAtBottom();
46+
const { checkAtBottom, settleUserScroll } = loadPatchedListInternals();
3747

3848
// iPhone 17 Pro thread feed: header inset 116, composer inset 142.5, rows 693.29,
3949
// so the end rests at -38.21 and the start at -116.
4050
const scrollLength = 874;
4151
const insetTop = 116;
4252
const insetBottom = 142.5;
53+
const contentSize = 835.79;
4354

44-
function isAtEnd(scroll: number, rowsLength = 835.79 - insetBottom) {
55+
function createFeedList(scroll: number, rowsLength = contentSize - insetBottom) {
4556
const values = new Map<string, unknown>([["totalSize", rowsLength]]);
46-
checkAtBottom({
57+
const ctx = {
4758
values,
4859
listeners: new Map(),
4960
scrollAxisGap: 0,
5061
state: {
5162
queuedInitialLayout: true,
52-
maintainingScrollAtEnd: true,
63+
didFinishInitialScroll: true,
5364
scroll,
5465
scrollLength,
66+
scheduledWork: { cancel: () => {}, has: () => false },
5567
props: {
5668
data: [{}],
5769
contentInset: { top: insetTop, bottom: insetBottom },
58-
maintainScrollAtEndThreshold: 0,
59-
onEndReachedThreshold: 0,
70+
maintainScrollAtEnd: THREAD_FEED_MAINTAIN_SCROLL_AT_END,
71+
maintainScrollAtEndThreshold: THREAD_FEED_MAINTAIN_SCROLL_AT_END_THRESHOLD,
72+
onEndReachedThreshold: 0.5,
6073
},
6174
},
62-
});
75+
};
76+
return { ctx, values };
77+
}
78+
79+
function isAtEnd(scroll: number, rowsLength?: number) {
80+
const { ctx, values } = createFeedList(scroll, rowsLength);
81+
checkAtBottom(ctx);
6382
return values.get("isAtEnd");
6483
}
6584

66-
describe("patched LegendList checkAtBottom", () => {
85+
describe("patched LegendList end detection in the thread feed", () => {
6786
it("does not report the start edge as the end when content overflows below the header inset", () => {
68-
expect(isAtEnd(835.79 - scrollLength)).toBe(true);
87+
expect(isAtEnd(contentSize - scrollLength)).toBe(true);
6988
expect(isAtEnd(-insetTop, 758 - insetBottom), "content that exactly fits").toBe(true);
7089

7190
expect(
@@ -74,4 +93,15 @@ describe("patched LegendList checkAtBottom", () => {
7493
).toBe(false);
7594
expect(isAtEnd(-114), "a feed just below its start edge is 75.8pt from its end").toBe(false);
7695
});
96+
97+
it("does not re-arm end following when a pull to the start edge is released", () => {
98+
const { ctx, values } = createFeedList(-insetTop);
99+
checkAtBottom(ctx);
100+
Object.assign(ctx.state, { userScrollContentSize: contentSize });
101+
settleUserScroll(ctx);
102+
checkAtBottom(ctx);
103+
104+
expect(values.get("isFollowingEnd")).toBe(false);
105+
expect(values.get("isWithinMaintainScrollAtEndThreshold")).toBe(false);
106+
});
77107
});
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
export const THREAD_FEED_MAINTAIN_SCROLL_AT_END = {
2+
animated: false,
3+
on: { dataChange: true, itemLayout: true, layout: true },
4+
} as const;
5+
6+
// Re-arm end following only at the end itself: a release short of it, such as pulling to
7+
// load earlier activity, must not snap back to the end.
8+
export const THREAD_FEED_MAINTAIN_SCROLL_AT_END_THRESHOLD = 0;

0 commit comments

Comments
 (0)