Skip to content

Commit cf8f025

Browse files
fix(mobile): the thread feed glides to its end when the sidebar toggles on iOS
A new split width re-wraps every row in one commit, and holding the end moved everything above the last message by the change in height in a single frame. The Legend List patch now reports how far that hold moved the top visible row, but only just after the list's sizeChangeKey changes, so streaming growth still follows at once. ThreadFeed starts the list offset by that amount and animates it back over 280 ms. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent c7b56db commit cf8f025

3 files changed

Lines changed: 227 additions & 13 deletions

File tree

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

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,15 @@ import { ThreadInlineFilePreview } from "./ThreadInlineFilePreview";
143143
import { flattenThemeColor } from "../../lib/mobileTheme";
144144
import { PresentationSource } from "../../components/ui/NativePresentation";
145145
import { NativeScrollViewMarker } from "../../native/NativeScrollViewMarker";
146-
import Animated, { FadeIn, FadeInDown, type SharedValue } from "react-native-reanimated";
146+
import Animated, {
147+
FadeIn,
148+
FadeInDown,
149+
useAnimatedStyle,
150+
useSharedValue,
151+
withSequence,
152+
withTiming,
153+
type SharedValue,
154+
} from "react-native-reanimated";
147155
import { useUniwindTheme } from "../../lib/useUniwindTheme";
148156
import { FONT_FAMILIES } from "../../lib/fontFamilies";
149157
import { scopedThreadKey } from "../../lib/scopedEntities";
@@ -3291,6 +3299,22 @@ export const ThreadFeed = memo(function ThreadFeed(props: ThreadFeedProps) {
32913299
// oxlint-disable-next-line react/exhaustive-effect-dependencies -- Jumping to a different message whose row index is unchanged must still land the jump.
32923300
}, [jumpToMessageId, jumpIndex]);
32933301

3302+
// A new split width re-wraps every row in one commit, and the list keeps its end, so everything on
3303+
// screen jumps by the change in height above the top row. The list starts offset by that jump,
3304+
// which keeps the top row where it was, and glides back.
3305+
const reflowShift = useSharedValue(0);
3306+
const reflowShiftStyle = useAnimatedStyle(() => ({
3307+
transform: [{ translateY: reflowShift.value }],
3308+
}));
3309+
const easeEndHoldShift =
3310+
splitLayout && !reduceMotion
3311+
? (shift: number) => {
3312+
reflowShift.set(
3313+
withSequence(withTiming(-shift, { duration: 0 }), withTiming(0, { duration: 280 })),
3314+
);
3315+
}
3316+
: undefined;
3317+
32943318
const handleViewportLayout = (event: LayoutChangeEvent) => {
32953319
const nextWidth = Math.round(event.nativeEvent.layout.width);
32963320
const nextHeight = Math.round(event.nativeEvent.layout.height);
@@ -3653,9 +3677,12 @@ export const ThreadFeed = memo(function ThreadFeed(props: ThreadFeedProps) {
36533677
{/* In a split, rows only re-wrap in the render that hands the list its new width. A native
36543678
column resize would re-wrap them first, and the list would place the taller or shorter
36553679
rows at their old offsets until their measurements came back. */}
3656-
<View
3657-
className="flex-1"
3658-
style={splitLayout && viewportWidth > 0 ? { width: viewportWidth } : undefined}
3680+
<Animated.View
3681+
style={[
3682+
{ flex: 1 },
3683+
splitLayout && viewportWidth > 0 ? { width: viewportWidth } : null,
3684+
reflowShiftStyle,
3685+
]}
36593686
>
36603687
{/* oxlint-disable-next-line t3code/require-registered-list-scroll -- ThreadFeedScrollView is passed through the iOS-only spread below; the prop rejects undefined. */}
36613688
<KeyboardAwareLegendList
@@ -3675,6 +3702,9 @@ export const ThreadFeed = memo(function ThreadFeed(props: ThreadFeedProps) {
36753702
freeze={props.freeze}
36763703
maintainScrollAtEnd={jumpReady ? false : THREAD_FEED_MAINTAIN_SCROLL_AT_END}
36773704
maintainVisibleContentPosition
3705+
{...(easeEndHoldShift
3706+
? { onEndHoldShift: easeEndHoldShift, sizeChangeKey: viewportWidth }
3707+
: {})}
36783708
data={groupedFeed}
36793709
extraData={listAppearanceData}
36803710
renderItem={renderItem}
@@ -3744,7 +3774,7 @@ export const ThreadFeed = memo(function ThreadFeed(props: ThreadFeedProps) {
37443774
paddingRight: contentHorizontalPadding + contentRightInset,
37453775
}}
37463776
/>
3747-
</View>
3777+
</Animated.View>
37483778
{presentedFeed.length === 0 &&
37493779
!props.worktreeSetup &&
37503780
props.activeWorkStartedAt === null &&

‎patches/@[email protected]‎

Lines changed: 188 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,44 @@
1+
diff --git a/animated.d.ts b/animated.d.ts
2+
index c519061902a1fc47c7722a1ed2e6d9c3e971bfaa..f4f94bd09203ec6dc6bc9b2e6fd789ee72469b97 100644
3+
--- a/animated.d.ts
4+
+++ b/animated.d.ts
5+
@@ -282,6 +282,13 @@ interface LegendListSpecificProps<ItemT, TItemType extends string | undefined> {
6+
* @default false
7+
*/
8+
maintainScrollAtEnd?: boolean | MaintainScrollAtEndOptions;
9+
+ /**
10+
+ * T3 patch: called when a size change held the end and moved the top visible row on screen by
11+
+ * `shift` points (down is positive). Native only.
12+
+ */
13+
+ onEndHoldShift?: (shift: number) => void;
14+
+ /** T3 patch: a change marks a reflow, such as a new width, for `onEndHoldShift`. */
15+
+ sizeChangeKey?: string | number;
16+
/**
17+
* Distance threshold in percentage of screen size to trigger maintainScrollAtEnd.
18+
* @default 0.1
19+
diff --git a/react-native.d.ts b/react-native.d.ts
20+
index 983e937cf5c19134e949e0b2f609ba21541b77af..124bdd5243678a4d65f024841261861dd96d83f2 100644
21+
--- a/react-native.d.ts
22+
+++ b/react-native.d.ts
23+
@@ -282,6 +282,13 @@ interface LegendListSpecificProps<ItemT, TItemType extends string | undefined> {
24+
* @default false
25+
*/
26+
maintainScrollAtEnd?: boolean | MaintainScrollAtEndOptions;
27+
+ /**
28+
+ * T3 patch: called when a size change held the end and moved the top visible row on screen by
29+
+ * `shift` points (down is positive). Native only.
30+
+ */
31+
+ onEndHoldShift?: (shift: number) => void;
32+
+ /** T3 patch: a change marks a reflow, such as a new width, for `onEndHoldShift`. */
33+
+ sizeChangeKey?: string | number;
34+
/**
35+
* Distance threshold in percentage of screen size to trigger maintainScrollAtEnd.
36+
* @default 0.1
137
diff --git a/react-native.js b/react-native.js
2-
index 4af685dfb961eb0c8a4bf1ae9132c9304cf4fa4d..df4ead7ae4f03cd0fbcd99a3df7d95e15b1852b1 100644
38+
index 4af685dfb961eb0c8a4bf1ae9132c9304cf4fa4d..901dd035eafc3846e390dc006215a2977933ae5c 100644
339
--- a/react-native.js
440
+++ b/react-native.js
5-
@@ -1795,7 +1795,35 @@ function resolvePendingNativeMVCPAdjust(ctx, newScroll) {
41+
@@ -1795,7 +1795,51 @@ function resolvePendingNativeMVCPAdjust(ctx, newScroll) {
642
}
743
return false;
844
}
@@ -18,11 +54,16 @@ index 4af685dfb961eb0c8a4bf1ae9132c9304cf4fa4d..df4ead7ae4f03cd0fbcd99a3df7d95e1
1854
+ if (!shouldHoldEndOnSizeChange(ctx, dataChanged)) {
1955
+ return restore;
2056
+ }
57+
+ const { idsInView, indexByKey, positions } = ctx.state;
58+
+ const anchorId = idsInView.find((id) => indexByKey.get(id) !== void 0);
59+
+ const anchorIndex = anchorId === void 0 ? void 0 : indexByKey.get(anchorId);
60+
+ const anchorPosition = anchorIndex === void 0 ? void 0 : positions[anchorIndex];
2161
+ return () => {
2262
+ if (!shouldHoldEndOnSizeChange(ctx, dataChanged)) {
2363
+ restore == null ? void 0 : restore();
2464
+ return;
2565
+ }
66+
+ const scrollBefore = ctx.state.scroll;
2667
+ // Content that shrinks under an offset past its new end pulls the native offset back by itself.
2768
+ const endOffset = getScrollRangeEnd(ctx);
2869
+ if (ctx.state.scroll > endOffset) {
@@ -32,17 +73,50 @@ index 4af685dfb961eb0c8a4bf1ae9132c9304cf4fa4d..df4ead7ae4f03cd0fbcd99a3df7d95e1
3273
+ if (Math.abs(positionDiff) > MVCP_POSITION_EPSILON) {
3374
+ requestAdjust(ctx, positionDiff, adjustmentSource);
3475
+ }
76+
+ // T3 patch: how far holding the end moved the top visible row on screen, for a caller that
77+
+ // eases the jump. Reported only shortly after `sizeChangeKey` changes, so growth at the end
78+
+ // while streaming still follows at once.
79+
+ const onEndHoldShift = ctx.state.props.onEndHoldShift;
80+
+ const newAnchorIndex = anchorId === void 0 ? void 0 : ctx.state.indexByKey.get(anchorId);
81+
+ const newAnchorPosition = newAnchorIndex === void 0 ? void 0 : ctx.state.positions[newAnchorIndex];
82+
+ const inReflow = ctx.state.endHoldReflowUntil !== void 0 && Date.now() < ctx.state.endHoldReflowUntil;
83+
+ if (onEndHoldShift && inReflow && anchorPosition !== void 0 && newAnchorPosition !== void 0) {
84+
+ const shift = newAnchorPosition - anchorPosition - (ctx.state.scroll - scrollBefore);
85+
+ if (Math.abs(shift) > MVCP_POSITION_EPSILON) onEndHoldShift(shift);
86+
+ }
3587
+ };
3688
+}
3789
+function prepareDefaultMVCP(ctx, dataChanged, adjustmentSource) {
3890
var _a3, _b, _c;
3991
const state = ctx.state;
4092
const { idsInView, positions, props } = state;
93+
@@ -8366,6 +8410,8 @@ var LegendListInner = typedForwardRef(function LegendListInner2(props, forwarded
94+
ListHeaderComponent,
95+
maintainScrollAtEnd = false,
96+
maintainScrollAtEndThreshold = 0.1,
97+
+ onEndHoldShift,
98+
+ sizeChangeKey,
99+
maintainVisibleContentPosition: maintainVisibleContentPositionProp,
100+
numColumns: numColumnsProp = 1,
101+
overrideItemLayout,
102+
@@ -8625,7 +8671,12 @@ var LegendListInner = typedForwardRef(function LegendListInner2(props, forwarded
103+
const throttledOnScroll = useThrottledOnScroll(onScrollProp != null ? onScrollProp : noopOnScroll, scrollEventThrottle != null ? scrollEventThrottle : 0);
104+
const throttleScrollFn = scrollEventThrottle && onScrollProp ? throttledOnScroll : onScrollProp;
105+
const didAnchoredEndSpaceAnchorIndexChange = !isFirstLocal && !didDataChangeLocal && ((_r = state.props.anchoredEndSpace) == null ? void 0 : _r.anchorIndex) !== (anchoredEndSpace == null ? void 0 : anchoredEndSpace.anchorIndex);
106+
+ if (state.props.sizeChangeKey !== void 0 && sizeChangeKey !== state.props.sizeChangeKey) {
107+
+ state.endHoldReflowUntil = Date.now() + 500;
108+
+ }
109+
state.props = {
110+
+ onEndHoldShift,
111+
+ sizeChangeKey,
112+
adaptiveRender: experimental_adaptiveRender,
113+
alignItemsAtEnd,
114+
alignItemsAtEndPaddingEnabled: useAlignItemsAtEndPadding,
41115
diff --git a/react-native.mjs b/react-native.mjs
42-
index 9ebfddc183a9b202d35c990a387c9b628feeb185..c414a49e866ecab1393645101fb67d55530a7d00 100644
116+
index 9ebfddc183a9b202d35c990a387c9b628feeb185..cf3433ee2f84c8d923bf1200bb1ff1b640f557d4 100644
43117
--- a/react-native.mjs
44118
+++ b/react-native.mjs
45-
@@ -1774,7 +1774,35 @@ function resolvePendingNativeMVCPAdjust(ctx, newScroll) {
119+
@@ -1774,7 +1774,51 @@ function resolvePendingNativeMVCPAdjust(ctx, newScroll) {
46120
}
47121
return false;
48122
}
@@ -58,11 +132,16 @@ index 9ebfddc183a9b202d35c990a387c9b628feeb185..c414a49e866ecab1393645101fb67d55
58132
+ if (!shouldHoldEndOnSizeChange(ctx, dataChanged)) {
59133
+ return restore;
60134
+ }
135+
+ const { idsInView, indexByKey, positions } = ctx.state;
136+
+ const anchorId = idsInView.find((id) => indexByKey.get(id) !== void 0);
137+
+ const anchorIndex = anchorId === void 0 ? void 0 : indexByKey.get(anchorId);
138+
+ const anchorPosition = anchorIndex === void 0 ? void 0 : positions[anchorIndex];
61139
+ return () => {
62140
+ if (!shouldHoldEndOnSizeChange(ctx, dataChanged)) {
63141
+ restore == null ? void 0 : restore();
64142
+ return;
65143
+ }
144+
+ const scrollBefore = ctx.state.scroll;
66145
+ // Content that shrinks under an offset past its new end pulls the native offset back by itself.
67146
+ const endOffset = getScrollRangeEnd(ctx);
68147
+ if (ctx.state.scroll > endOffset) {
@@ -72,9 +151,114 @@ index 9ebfddc183a9b202d35c990a387c9b628feeb185..c414a49e866ecab1393645101fb67d55
72151
+ if (Math.abs(positionDiff) > MVCP_POSITION_EPSILON) {
73152
+ requestAdjust(ctx, positionDiff, adjustmentSource);
74153
+ }
154+
+ // T3 patch: how far holding the end moved the top visible row on screen, for a caller that
155+
+ // eases the jump. Reported only shortly after `sizeChangeKey` changes, so growth at the end
156+
+ // while streaming still follows at once.
157+
+ const onEndHoldShift = ctx.state.props.onEndHoldShift;
158+
+ const newAnchorIndex = anchorId === void 0 ? void 0 : ctx.state.indexByKey.get(anchorId);
159+
+ const newAnchorPosition = newAnchorIndex === void 0 ? void 0 : ctx.state.positions[newAnchorIndex];
160+
+ const inReflow = ctx.state.endHoldReflowUntil !== void 0 && Date.now() < ctx.state.endHoldReflowUntil;
161+
+ if (onEndHoldShift && inReflow && anchorPosition !== void 0 && newAnchorPosition !== void 0) {
162+
+ const shift = newAnchorPosition - anchorPosition - (ctx.state.scroll - scrollBefore);
163+
+ if (Math.abs(shift) > MVCP_POSITION_EPSILON) onEndHoldShift(shift);
164+
+ }
75165
+ };
76166
+}
77167
+function prepareDefaultMVCP(ctx, dataChanged, adjustmentSource) {
78168
var _a3, _b, _c;
79169
const state = ctx.state;
80170
const { idsInView, positions, props } = state;
171+
@@ -8345,6 +8389,8 @@ var LegendListInner = typedForwardRef(function LegendListInner2(props, forwarded
172+
ListHeaderComponent,
173+
maintainScrollAtEnd = false,
174+
maintainScrollAtEndThreshold = 0.1,
175+
+ onEndHoldShift,
176+
+ sizeChangeKey,
177+
maintainVisibleContentPosition: maintainVisibleContentPositionProp,
178+
numColumns: numColumnsProp = 1,
179+
overrideItemLayout,
180+
@@ -8604,7 +8650,12 @@ var LegendListInner = typedForwardRef(function LegendListInner2(props, forwarded
181+
const throttledOnScroll = useThrottledOnScroll(onScrollProp != null ? onScrollProp : noopOnScroll, scrollEventThrottle != null ? scrollEventThrottle : 0);
182+
const throttleScrollFn = scrollEventThrottle && onScrollProp ? throttledOnScroll : onScrollProp;
183+
const didAnchoredEndSpaceAnchorIndexChange = !isFirstLocal && !didDataChangeLocal && ((_r = state.props.anchoredEndSpace) == null ? void 0 : _r.anchorIndex) !== (anchoredEndSpace == null ? void 0 : anchoredEndSpace.anchorIndex);
184+
+ if (state.props.sizeChangeKey !== void 0 && sizeChangeKey !== state.props.sizeChangeKey) {
185+
+ state.endHoldReflowUntil = Date.now() + 500;
186+
+ }
187+
state.props = {
188+
+ onEndHoldShift,
189+
+ sizeChangeKey,
190+
adaptiveRender: experimental_adaptiveRender,
191+
alignItemsAtEnd,
192+
alignItemsAtEndPaddingEnabled: useAlignItemsAtEndPadding,
193+
diff --git a/react-native.web.d.ts b/react-native.web.d.ts
194+
index 358fcd7faa598af8a4382719b7e7198b3ce04588..d36440a103ddee67b15e9c287781ce7720560900 100644
195+
--- a/react-native.web.d.ts
196+
+++ b/react-native.web.d.ts
197+
@@ -309,6 +309,13 @@ interface LegendListSpecificProps<ItemT, TItemType extends string | undefined> {
198+
* @default false
199+
*/
200+
maintainScrollAtEnd?: boolean | MaintainScrollAtEndOptions;
201+
+ /**
202+
+ * T3 patch: called when a size change held the end and moved the top visible row on screen by
203+
+ * `shift` points (down is positive). Native only.
204+
+ */
205+
+ onEndHoldShift?: (shift: number) => void;
206+
+ /** T3 patch: a change marks a reflow, such as a new width, for `onEndHoldShift`. */
207+
+ sizeChangeKey?: string | number;
208+
/**
209+
* Distance threshold in percentage of screen size to trigger maintainScrollAtEnd.
210+
* @default 0.1
211+
diff --git a/react.d.ts b/react.d.ts
212+
index 358fcd7faa598af8a4382719b7e7198b3ce04588..d36440a103ddee67b15e9c287781ce7720560900 100644
213+
--- a/react.d.ts
214+
+++ b/react.d.ts
215+
@@ -309,6 +309,13 @@ interface LegendListSpecificProps<ItemT, TItemType extends string | undefined> {
216+
* @default false
217+
*/
218+
maintainScrollAtEnd?: boolean | MaintainScrollAtEndOptions;
219+
+ /**
220+
+ * T3 patch: called when a size change held the end and moved the top visible row on screen by
221+
+ * `shift` points (down is positive). Native only.
222+
+ */
223+
+ onEndHoldShift?: (shift: number) => void;
224+
+ /** T3 patch: a change marks a reflow, such as a new width, for `onEndHoldShift`. */
225+
+ sizeChangeKey?: string | number;
226+
/**
227+
* Distance threshold in percentage of screen size to trigger maintainScrollAtEnd.
228+
* @default 0.1
229+
diff --git a/reanimated.d.ts b/reanimated.d.ts
230+
index 5b568f2d39783dd257e97e4727c45373cac41165..bc74fb4d3359deddc3b8bca929337734162c55f9 100644
231+
--- a/reanimated.d.ts
232+
+++ b/reanimated.d.ts
233+
@@ -283,6 +283,13 @@ interface LegendListSpecificProps<ItemT, TItemType extends string | undefined> {
234+
* @default false
235+
*/
236+
maintainScrollAtEnd?: boolean | MaintainScrollAtEndOptions;
237+
+ /**
238+
+ * T3 patch: called when a size change held the end and moved the top visible row on screen by
239+
+ * `shift` points (down is positive). Native only.
240+
+ */
241+
+ onEndHoldShift?: (shift: number) => void;
242+
+ /** T3 patch: a change marks a reflow, such as a new width, for `onEndHoldShift`. */
243+
+ sizeChangeKey?: string | number;
244+
/**
245+
* Distance threshold in percentage of screen size to trigger maintainScrollAtEnd.
246+
* @default 0.1
247+
diff --git a/section-list.d.ts b/section-list.d.ts
248+
index 94edf333f0d0a140534421f3c72886eb8a48c130..8d96b82054163d73d2ed763c36a6baa2eb0880b0 100644
249+
--- a/section-list.d.ts
250+
+++ b/section-list.d.ts
251+
@@ -339,6 +339,13 @@ interface LegendListSpecificProps<ItemT, TItemType extends string | undefined> {
252+
* @default false
253+
*/
254+
maintainScrollAtEnd?: boolean | MaintainScrollAtEndOptions;
255+
+ /**
256+
+ * T3 patch: called when a size change held the end and moved the top visible row on screen by
257+
+ * `shift` points (down is positive). Native only.
258+
+ */
259+
+ onEndHoldShift?: (shift: number) => void;
260+
+ /** T3 patch: a change marks a reflow, such as a new width, for `onEndHoldShift`. */
261+
+ sizeChangeKey?: string | number;
262+
/**
263+
* Distance threshold in percentage of screen size to trigger maintainScrollAtEnd.
264+
* @default 0.1

0 commit comments

Comments
 (0)