Skip to content

Commit 4df0c13

Browse files
jmeistrichclaudejuliusmarminge
authored
refactor: upgrade Legend List to 3.7.2 and drop our list workarounds (#28125)
Co-authored-by: Claude Opus 5.5 <[email protected]> Co-authored-by: Julius Marminge <[email protected]>
1 parent ea876cc commit 4df0c13

37 files changed

Lines changed: 657 additions & 4060 deletions

‎apps/mobile/src/components/ui/useBarInset.ts‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,13 @@ export function useContentTopInset(): number {
4848
return Platform.OS === "ios" ? (columnMetrics?.safeArea.top ?? insets.top) : 0;
4949
}
5050

51+
/** The content's bottom safe area on iOS, which a list with manual insets must add itself. */
52+
export function useContentBottomInset(): number {
53+
const insets = useSafeAreaInsets();
54+
const columnMetrics = useNativeColumnLayoutMetrics();
55+
return Platform.OS === "ios" ? (columnMetrics?.safeArea.bottom ?? insets.bottom) : 0;
56+
}
57+
5158
/** How much of the screen's bottom edge an AppBar `search` covers: iOS's bottom search toolbar. */
5259
export function useSearchToolbarInset(search: AppBarSearch | undefined): number {
5360
const { layout } = useAdaptiveWorkspaceLayout();

‎apps/mobile/src/features/files/FileTreeBrowser.tsx‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { Pressable, RefreshControl, View } from "react-native";
1010
import { AppText as Text } from "../../components/ui/AppText";
1111
import { PierreEntryIcon } from "../../components/PierreEntryIcon";
1212
import { cn } from "../../lib/cn";
13-
import { useContentTopInset } from "../../components/ui/useBarInset";
13+
import { useContentBottomInset, useContentTopInset } from "../../components/ui/useBarInset";
1414
import {
1515
buildFileTree,
1616
flattenFileTree,
@@ -122,6 +122,7 @@ export function FileTreeBrowser(props: {
122122
readonly selectedPathAtPress: string | null;
123123
} | null>(null);
124124
const headerInset = useContentTopInset();
125+
const bottomInset = useContentBottomInset();
125126
const {
126127
onLoadDirectory,
127128
onPreviewFile,
@@ -214,12 +215,12 @@ export function FileTreeBrowser(props: {
214215
return (
215216
<LegendList
216217
renderScrollComponent={NativeScrollView}
217-
contentInsetStartAdjustment={headerInset}
218+
contentInset={{ top: headerInset, bottom: bottomInset }}
218219
alwaysBounceVertical
219220
className="flex-1"
220221
data={visibleNodes}
221222
keyExtractor={(item) => item.node.path}
222-
contentInsetAdjustmentBehavior="automatic"
223+
contentInsetAdjustmentBehavior="never"
223224
automaticallyAdjustsScrollIndicatorInsets
224225
keyboardDismissMode="on-drag"
225226
keyboardShouldPersistTaps="handled"

‎apps/mobile/src/features/files/ZipArchiveView.test.tsx‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,10 @@ vi.mock("../../components/ui/AppBar", () => {
127127
}) => <div>{props.menus?.map((menu) => renderItems(menu.items))}</div>,
128128
};
129129
});
130-
vi.mock("../../components/ui/useBarInset", () => ({ useContentTopInset: () => 0 }));
130+
vi.mock("../../components/ui/useBarInset", () => ({
131+
useContentTopInset: () => 0,
132+
useContentBottomInset: () => 0,
133+
}));
131134
vi.mock("../../components/ui/AppSymbol", () => ({ SymbolView: () => null }));
132135
vi.mock("../../components/ui/Progress", () => ({ Progress: () => null }));
133136
vi.mock("../../components/PierreEntryIcon", () => ({ PierreEntryIcon: () => null }));

‎apps/mobile/src/features/files/ZipArchiveView.tsx‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import { Keyboard, Pressable, ScrollView, TextInput, View } from "react-native";
2121

2222
import { PierreEntryIcon } from "../../components/PierreEntryIcon";
2323
import { AppBar } from "../../components/ui/AppBar";
24-
import { useContentTopInset } from "../../components/ui/useBarInset";
24+
import { useContentBottomInset, useContentTopInset } from "../../components/ui/useBarInset";
2525
import { SymbolView } from "../../components/ui/AppSymbol";
2626
import { AppText as Text } from "../../components/ui/AppText";
2727
import { Button } from "../../components/ui/Button";
@@ -395,15 +395,16 @@ function ZipArchiveList(props: {
395395
return next;
396396
});
397397
const fileCount = archive.fileCount;
398+
const bottomInset = useContentBottomInset();
398399
return (
399400
<View className="flex-1 bg-sheet">
400401
<LegendList
401402
renderScrollComponent={NativeScrollView}
402-
contentInsetStartAdjustment={props.headerInset}
403+
contentInset={{ top: props.headerInset, bottom: bottomInset }}
403404
className="flex-1"
404405
data={rows}
405406
keyExtractor={(row) => `${row.node.entry ? "f" : "d"}:${row.node.path}`}
406-
contentInsetAdjustmentBehavior="automatic"
407+
contentInsetAdjustmentBehavior="never"
407408
automaticallyAdjustsScrollIndicatorInsets
408409
estimatedItemSize={44}
409410
recycleItems

‎apps/mobile/src/features/files/useFileTreeEntries.test.tsx‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,10 @@ vi.mock("react-native", () => ({
141141
vi.mock("react-native-safe-area-context", () => ({ useSafeAreaInsets: () => ({ top: 0 }) }));
142142
vi.mock("../../native/NativeScrollViewMarker", () => ({ NativeScrollView: Nothing }));
143143
vi.mock("../../native/native-layout-metrics", () => ({ useNativeColumnLayoutMetrics: () => null }));
144-
vi.mock("../../components/ui/useBarInset", () => ({ useContentTopInset: () => 0 }));
144+
vi.mock("../../components/ui/useBarInset", () => ({
145+
useContentTopInset: () => 0,
146+
useContentBottomInset: () => 0,
147+
}));
145148
vi.mock("@legendapp/list/react-native", () => ({
146149
LegendList: <T,>(props: {
147150
data: ReadonlyArray<T>;

‎apps/mobile/src/features/home/HomeScreen.tsx‎

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { useContentTopInset } from "../../components/ui/useBarInset";
12
import { usePaneRole } from "../../components/ui/Pane";
23
import { ScreenContent } from "../../components/ui/ScreenContent";
34
import { useActiveNewTask } from "../../state/active-new-task";
@@ -262,6 +263,7 @@ export function HomeScreen(props: HomeScreenProps) {
262263
const openSwipeableRef = useRef<SwipeableMethods | null>(null);
263264
const homeScrollGesture = useNativeGesture();
264265
const insets = useSafeAreaInsets();
266+
const contentTopInset = useContentTopInset();
265267
const emptyTopInset = useWorkspaceListEmptyTopInset();
266268
const { fabClearance } = useAndroidControlSizing();
267269
const screenMetrics = useNativeLayoutMetrics();
@@ -326,7 +328,7 @@ export function HomeScreen(props: HomeScreenProps) {
326328
useSearchScrollRestoration(searchMode, () => {
327329
if (restoredOffset === undefined) return;
328330
void listRef.current?.scrollToOffset({
329-
offset: restoredOffset - (Platform.OS === "ios" ? insets.top : 0),
331+
offset: restoredOffset - contentTopInset,
330332
animated: false,
331333
});
332334
});
@@ -347,7 +349,7 @@ export function HomeScreen(props: HomeScreenProps) {
347349
if (workspace)
348350
workspace.recordScrollOffset(
349351
"threads",
350-
Math.max(0, event.nativeEvent.contentOffset.y + (Platform.OS === "ios" ? insets.top : 0)),
352+
Math.max(0, event.nativeEvent.contentOffset.y + contentTopInset),
351353
);
352354
clearTimeout(activationTimerRef.current);
353355
activationTimerRef.current = setTimeout(
@@ -798,7 +800,7 @@ export function HomeScreen(props: HomeScreenProps) {
798800
onTouchStart={(event) => trackListTouches(event, true)}
799801
onTouchEnd={(event) => trackListTouches(event, false)}
800802
onTouchCancel={(event) => trackListTouches(event, false)}
801-
renderScrollComponent={renderHomeScrollView}
803+
renderScrollComponent={Platform.OS === "ios" ? renderHomeScrollView : undefined}
802804
data={threadListV2Items}
803805
renderItem={renderV2Item}
804806
keyExtractor={v2KeyExtractor}
@@ -829,17 +831,11 @@ export function HomeScreen(props: HomeScreenProps) {
829831
}
830832
ListEmptyComponent={v2ListEmpty}
831833
style={{ flex: 1 }}
832-
automaticallyAdjustsScrollIndicatorInsets
833-
// UIKit owns the bar's inset, so a minimizing bar and a resized column move
834-
// the list in the same frame as the bar.
835-
contentInsetAdjustmentBehavior="automatic"
836-
contentInsetStartAdjustment={Platform.OS === "ios" ? insets.top : 0}
837-
// RN scrollTo clamps against raw insets and ignores the automatic bar inset.
838-
scrollToOverflowEnabled
834+
automaticallyAdjustsScrollIndicatorInsets={Platform.OS === "ios"}
835+
contentInsetAdjustmentBehavior="never"
836+
contentInset={Platform.OS === "ios" ? { top: contentTopInset } : undefined}
839837
initialScrollOffset={
840-
initialScrollOffset > 0
841-
? initialScrollOffset - (Platform.OS === "ios" ? insets.top : 0)
842-
: undefined
838+
initialScrollOffset > 0 ? initialScrollOffset - contentTopInset : undefined
843839
}
844840
showsVerticalScrollIndicator={false}
845841
keyboardDismissMode="on-drag"
@@ -853,7 +849,7 @@ export function HomeScreen(props: HomeScreenProps) {
853849
(contentSideInsets?.right ?? 0) + (sidebarSurface ? 8 : 0) + androidListGutter,
854850
paddingBottom:
855851
Platform.OS === "ios"
856-
? iosBottomClearance - (columnMetrics?.safeArea.bottom ?? insets.bottom)
852+
? iosBottomClearance
857853
: (workspace?.bottomClearance ??
858854
Math.max(insets.bottom, 16) +
859855
(Platform.OS === "android" ? fabClearance : 88)),

‎apps/mobile/src/features/pull-requests/PullRequestRouteScreen.tsx‎

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -383,8 +383,7 @@ export function PullRequestRouteScreen({ route }: StaticScreenProps<PullRequestP
383383
requestedSection.current = next;
384384
scrollOffsets.current[next] = offset;
385385
currentScrollOffset.current = { tab: next, offset };
386-
// LegendList clamps to its measured rows, which leave out the short-tab minHeight below.
387-
scrollViews.current[next]?.getNativeScrollRef().scrollTo({ y: offset, animated: false });
386+
scrollViews.current[next]?.scrollToOffset({ offset, animated: false });
388387
setSection(next);
389388
};
390389
const tabContent = activityContent;
@@ -444,8 +443,10 @@ export function PullRequestRouteScreen({ route }: StaticScreenProps<PullRequestP
444443
filesContent.refresh();
445444
});
446445
const jumpToFiles = () => {
447-
scrollViews.current.overview?.scrollToOffset({
448-
offset: bodyY.current + filesY.current - contentTopInset,
446+
scrollViews.current.overview?.scrollToIndex({
447+
index: 0,
448+
viewPosition: 0,
449+
viewOffset: -filesY.current,
449450
animated: true,
450451
});
451452
pendingFilesJump.current = false;
@@ -602,13 +603,13 @@ export function PullRequestRouteScreen({ route }: StaticScreenProps<PullRequestP
602603
currentScrollOffset.current = { tab, offset };
603604
}}
604605
className="flex-1"
605-
renderScrollComponent={NativeScrollView}
606-
// UIKit owns the bar's inset, so a minimizing bar and a resized column
607-
// move the list in the same frame as the bar.
608-
contentInsetAdjustmentBehavior="automatic"
609-
contentInsetStartAdjustment={contentTopInset}
610-
// RN scrollTo clamps against raw insets and ignores the automatic bar inset.
611-
scrollToOverflowEnabled
606+
renderScrollComponent={Platform.OS === "ios" ? NativeScrollView : undefined}
607+
contentInsetAdjustmentBehavior="never"
608+
contentInset={
609+
Platform.OS === "ios"
610+
? { top: contentTopInset, bottom: contentBottomInset }
611+
: undefined
612+
}
612613
refreshControl={
613614
<RefreshControl
614615
refreshing={section === tab && pullRefresh.refreshing}
@@ -617,17 +618,19 @@ export function PullRequestRouteScreen({ route }: StaticScreenProps<PullRequestP
617618
}
618619
alwaysBounceVertical
619620
scrollsToTop={section === tab}
620-
onContentSizeChange={() => {
621+
onItemSizeChanged={({ itemKey }) => {
621622
if (
622623
tab !== "overview" ||
623624
section !== "overview" ||
625+
itemKey !== "overview:body" ||
624626
!pendingDescriptionJump.current
625627
)
626628
return;
627629
pendingDescriptionJump.current = false;
628-
// Collapse changes the scroll range; restore the heading after that layout commits.
629-
scrollViews.current.overview?.scrollToOffset({
630-
offset: bodyY.current + descriptionY.current - contentTopInset,
630+
scrollViews.current.overview?.scrollToIndex({
631+
index: 0,
632+
viewPosition: 0,
633+
viewOffset: -descriptionY.current,
631634
animated: false,
632635
});
633636
}}

‎apps/mobile/src/features/pull-requests/PullRequestsScreen.tsx‎

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -294,20 +294,16 @@ export function PullRequestsScreen(
294294
// to this tab. The thread list shows none either.
295295
showsVerticalScrollIndicator={Platform.OS !== "android"}
296296
recycleItems
297-
renderScrollComponent={NativeScrollView}
298-
// UIKit owns the bar's inset, so a minimizing bar and a resized column move
299-
// the list in the same frame as the bar.
300-
contentInsetAdjustmentBehavior="automatic"
297+
renderScrollComponent={Platform.OS === "ios" ? NativeScrollView : undefined}
298+
contentInsetAdjustmentBehavior="never"
299+
contentInset={Platform.OS === "ios" ? { top: contentTopInset } : undefined}
301300
// A plain offset: LegendList adds the list header to an index-based restore, which
302301
// landed every return one header lower.
303302
initialScrollOffset={
304303
initialScrollOffset > 0 ? initialScrollOffset - contentTopInset : undefined
305304
}
306-
contentInsetStartAdjustment={contentTopInset}
307305
contentContainerStyle={{
308-
paddingBottom:
309-
Math.max(bottomSafeArea, workspace.bottomClearance) -
310-
(Platform.OS === "ios" ? bottomSafeArea : 0),
306+
paddingBottom: Math.max(bottomSafeArea, workspace.bottomClearance),
311307
}}
312308
onScroll={(event) => {
313309
workspace.recordScrollOffset(
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { describe, expect, it } from "vite-plus/test";
2+
import { pullRequestTabOffset } from "./pullRequestTabScroll";
3+
4+
describe("pull request tab scroll", () => {
5+
it("keeps the header fixed while switching, even if the destination was scrolled deeply", () => {
6+
expect(pullRequestTabOffset(-100, 900, 200)).toBe(-100);
7+
expect(pullRequestTabOffset(75, 900, 200)).toBe(75);
8+
});
9+
it("resumes the destination body only when the shared header is already collapsed", () => {
10+
expect(pullRequestTabOffset(600, 900, 200)).toBe(900);
11+
expect(pullRequestTabOffset(600, 50, 200)).toBe(200);
12+
expect(pullRequestTabOffset(600, undefined, 200)).toBe(200);
13+
});
14+
it("retains the saved body offset when native scrolling rounds the collapsed header", () => {
15+
const headerEnd = 213.6666717529297 - 116;
16+
expect(pullRequestTabOffset(97.66666666666667, 800, headerEnd)).toBe(800);
17+
expect(pullRequestTabOffset(headerEnd - 1, 800, headerEnd)).toBe(headerEnd - 1);
18+
});
19+
});

‎apps/mobile/src/features/pull-requests/pullRequestTabScroll.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@ export function pullRequestTabOffset(
33
saved: number | undefined,
44
headerEnd: number,
55
) {
6-
return current < headerEnd ? current : Math.max(headerEnd, saved ?? headerEnd);
6+
return current < headerEnd - 0.5 ? current : Math.max(headerEnd, saved ?? headerEnd);
77
}

0 commit comments

Comments
 (0)