Skip to content

Commit d3f8990

Browse files
refactor(mobile): lists use LegendList, FlatList is a restricted import
FlatList skipped require-registered-list-scroll and called renderScrollComponent as a plain function from a class render, outside the hooks NativeScrollView uses. Every mobile list now renders through LegendList, screen lists register with the header, and each list passes what its renderItem reads through extraData, since LegendList re-renders a row only when its item or extraData changes. The source viewer drops its VirtualizedList retry loop for jumps to unmeasured wrapped lines: LegendList's scrollToIndex lands on them directly. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 31eea88 commit d3f8990

13 files changed

Lines changed: 103 additions & 282 deletions

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

Lines changed: 21 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1+
import { LegendList, type LegendListRef } from "@legendapp/list/react-native";
12
import { settlePromise } from "@t3tools/client-runtime/state/runtime";
23
import { useAtomValue } from "@effect/atom-react";
34
import { AsyncResult } from "effect/reactivity";
45
import type { ComponentType } from "react";
56
import { useLayoutEffect, useRef, useState } from "react";
67
import {
7-
FlatList,
88
Platform,
99
Pressable,
1010
RefreshControl,
@@ -13,6 +13,7 @@ import {
1313
useWindowDimensions,
1414
View,
1515
} from "react-native";
16+
import { NativeScrollView } from "../../native/NativeScrollViewMarker";
1617
import { WebView } from "react-native-webview";
1718
import { useSafeAreaInsets } from "react-native-safe-area-context";
1819
import { AppText as Text } from "../../components/ui/AppText";
@@ -43,7 +44,6 @@ import {
4344
selectableSourceHtml,
4445
} from "./source-file-document";
4546
import { sourceHighlightAtom } from "./sourceHighlightingState";
46-
import { createSourceLineScroll } from "./source-file-scroll";
4747

4848
interface SourceFileSurfaceProps {
4949
readonly contents: string;
@@ -270,8 +270,7 @@ function JavaScriptSourceFileSurface(props: SourceFileSurfaceProps) {
270270
const { codeSurface, codeWordBreak } = useAppearanceCodeSurface();
271271
const { normalizedContents, lines, status, targetIndex, tokens } = useSourceFileModel(props);
272272
const selectableTokens = props.selectable ? boundedSelectableSourceTokens(tokens) : null;
273-
const listRef = useRef<FlatList<string>>(null);
274-
const [lineScroll] = useState(createSourceLineScroll);
273+
const listRef = useRef<LegendListRef>(null);
275274
const { isPullRefreshing, handlePullToRefresh } = useSourceFileRefresh(props.onRefresh);
276275
const refreshControl = props.onRefresh ? (
277276
<RefreshControl refreshing={isPullRefreshing} onRefresh={() => void handlePullToRefresh()} />
@@ -283,15 +282,21 @@ function JavaScriptSourceFileSurface(props: SourceFileSurfaceProps) {
283282
const usesTextSelection = props.selectable === true && !usesWebSelection;
284283

285284
// Layout effect so a pending jump is cancelled in the commit that swaps the file.
286-
// oxlint-disable-next-line t3code/no-unreasoned-state-sync -- scrolls the FlatList to the target line and cancels a pending jump when the file changes
285+
// oxlint-disable-next-line t3code/no-unreasoned-state-sync -- scrolls the list to the target line and cancels a pending jump when the file changes
287286
useLayoutEffect(() => {
288287
if (targetIndex === null || !usesLineList) {
289288
return;
290289
}
291-
lineScroll.scrollToLine(listRef.current, targetIndex);
292-
return lineScroll.cancel;
290+
const frame = requestAnimationFrame(() => {
291+
void listRef.current?.scrollToIndex({
292+
index: targetIndex,
293+
animated: false,
294+
viewPosition: 0.3,
295+
});
296+
});
297+
return () => cancelAnimationFrame(frame);
293298
// oxlint-disable-next-line react/exhaustive-effect-dependencies -- Opening another file at the same line index, or leaving selection mode, scrolls the remounted list to it.
294-
}, [lineScroll, props.path, targetIndex, usesLineList]);
299+
}, [props.path, targetIndex, usesLineList]);
295300

296301
const { onLongPressLine } = props;
297302
const renderLine = ({ item, index }: { item: string; index: number }) => (
@@ -385,33 +390,26 @@ function JavaScriptSourceFileSurface(props: SourceFileSurfaceProps) {
385390
) : null;
386391

387392
const list = (
388-
<FlatList
393+
<LegendList
389394
ref={listRef}
395+
// An embedded viewer sits inside another screen's scroll surface.
396+
renderScrollComponent={props.embedded ? undefined : NativeScrollView}
390397
contentInsetAdjustmentBehavior={usesAutomaticInsets ? "automatic" : "never"}
391398
automaticallyAdjustsScrollIndicatorInsets={usesAutomaticInsets}
392399
refreshControl={refreshControl}
393400
data={lines}
394401
keyExtractor={(_line, index) => String(index)}
395-
initialNumToRender={80}
396-
maxToRenderPerBatch={80}
397-
windowSize={12}
398-
{...(codeWordBreak
399-
? {}
400-
: {
401-
getItemLayout: (_data, index) => ({
402-
length: codeSurface.rowHeight,
403-
offset: codeSurface.rowHeight * index,
404-
index,
405-
}),
406-
})}
402+
extraData={{ tokens, targetIndex, codeSurface, codeWordBreak, onLongPressLine }}
403+
estimatedItemSize={codeSurface.rowHeight}
404+
getFixedItemSize={codeWordBreak ? undefined : () => codeSurface.rowHeight}
405+
drawDistance={codeSurface.rowHeight * 40}
406+
recycleItems
407407
contentContainerStyle={{
408408
minWidth: codeWordBreak ? undefined : "100%",
409409
paddingBottom: codeSurface.rowHeight,
410410
paddingTop: 8,
411411
}}
412412
renderItem={renderLine}
413-
onScrollToIndexFailed={lineScroll.onScrollToIndexFailed}
414-
onScrollBeginDrag={lineScroll.cancel}
415413
/>
416414
);
417415

‎apps/mobile/src/features/files/source-file-scroll.test.ts‎

Lines changed: 0 additions & 156 deletions
This file was deleted.

‎apps/mobile/src/features/files/source-file-scroll.ts‎

Lines changed: 0 additions & 66 deletions
This file was deleted.

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ function HomeScrollView(props: ComponentProps<typeof ScrollView>) {
240240
}
241241

242242
function renderHomeScrollView(props: ScrollViewProps) {
243-
// FlatList clones this with cells and ref; keep the marker inside their actual ScrollView.
243+
// The list passes its content and ref in these props; keep the marker inside the real ScrollView.
244244
return <HomeScrollView {...props} />;
245245
}
246246

‎apps/mobile/src/features/keyboard/CommandPalette.tsx‎

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { LegendList, type LegendListRef } from "@legendapp/list/react-native";
12
import { useAtomValue } from "@effect/atom-react";
23
import { uuidv4 } from "../../lib/uuid";
34
import { useNavigation } from "@react-navigation/native";
@@ -19,7 +20,6 @@ import {
1920
} from "@t3tools/shared/paletteSearch";
2021
import { useEffect, useMemo, useRef, useState } from "react";
2122
import {
22-
FlatList,
2323
KeyboardAvoidingView,
2424
Modal,
2525
Pressable,
@@ -240,7 +240,7 @@ export function CommandPalette(props: {
240240
const pendingAction = useRef<(() => void) | null>(null);
241241
const closing = useRef(false);
242242
const inputRef = useRef<TextInputInstance>(null);
243-
const listRef = useRef<FlatList<CommandPaletteResult>>(null);
243+
const listRef = useRef<LegendListRef>(null);
244244
const { width, height } = useWindowDimensions();
245245
// The palette floats above every column, so it keeps itself inside the window's side insets
246246
// and to one side of a book fold.
@@ -663,22 +663,23 @@ export function CommandPalette(props: {
663663
/>
664664
</View>
665665
</View>
666-
<FlatList
666+
{/* oxlint-disable-next-line t3code/require-registered-list-scroll -- The palette is a modal with no navigation header to register with. */}
667+
<LegendList
667668
ref={listRef}
668669
data={results}
669-
extraData={selectedKey}
670+
extraData={{
671+
selectedKey,
672+
firstMessageIndex,
673+
contentMatchByKey,
674+
query: search.query,
675+
}}
670676
keyboardShouldPersistTaps="handled"
671677
keyExtractor={(item) => item.key}
672-
getItemLayout={(_, index) => ({
673-
length: ROW_HEIGHT + (index === firstMessageIndex ? SECTION_LABEL_HEIGHT : 0),
674-
offset:
675-
ROW_HEIGHT * index +
676-
(firstMessageIndex !== -1 && index > firstMessageIndex
677-
? SECTION_LABEL_HEIGHT
678-
: 0),
679-
index,
680-
})}
681-
contentContainerClassName="pb-2"
678+
getFixedItemSize={(_, index) =>
679+
ROW_HEIGHT + (index === firstMessageIndex ? SECTION_LABEL_HEIGHT : 0)
680+
}
681+
recycleItems
682+
contentContainerStyle={{ paddingBottom: 8 }}
682683
ListEmptyComponent={
683684
<Text className="p-5 text-center text-foreground-muted">
684685
{search.isPending ? "Searching…" : "No results"}

0 commit comments

Comments
 (0)