1+ import { LegendList } from "@legendapp/list/react-native" ;
12import type { ProjectEntry } from "@t3tools/contracts" ;
23import { SymbolView } from "../../components/AppSymbol" ;
34import { memo , useCallback , useEffect , useMemo , useRef , useState } from "react" ;
4- import { ActivityIndicator , FlatList , Pressable , RefreshControl , View } from "react-native" ;
5+ import { ActivityIndicator , Platform , Pressable , RefreshControl , View } from "react-native" ;
56import { useSafeAreaInsets } from "react-native-safe-area-context" ;
67
78import { AppText as Text } from "../../components/AppText" ;
89import { PierreEntryIcon } from "../../components/PierreEntryIcon" ;
910import { cn } from "../../lib/cn" ;
1011import { IOS_NAV_BAR_HEIGHT } from "../../lib/layoutMetrics" ;
11- import { NATIVE_LIQUID_GLASS_SUPPORTED } from "../../native/native-glass" ;
1212import {
1313 buildFileTree ,
1414 flattenFileTree ,
@@ -17,8 +17,6 @@ import {
1717} from "./fileTree" ;
1818
1919const fileTreeCache = new WeakMap < ReadonlyArray < ProjectEntry > , ReadonlyArray < FileTreeNode > > ( ) ;
20- const FILE_TREE_INITIAL_RENDER_COUNT = 20 ;
21- const FILE_TREE_RENDER_BATCH_SIZE = 12 ;
2220const OPTIMISTIC_SELECTION_TIMEOUT_MS = 1_000 ;
2321
2422function cachedFileTree ( entries : ReadonlyArray < ProjectEntry > ) : ReadonlyArray < FileTreeNode > {
@@ -45,7 +43,8 @@ const FileTreeRow = memo(function FileTreeRow(props: {
4543 readonly selected : boolean ;
4644 readonly expanded : boolean ;
4745 readonly loaded : boolean ;
48- readonly onPressDirectory : ( path : string ) => void ;
46+ readonly loading : boolean ;
47+ readonly onPressDirectory : ( path : string , expand : boolean ) => void ;
4948 readonly onPreviewFile ?: ( path : string ) => void ;
5049 readonly onPressFile : ( path : string ) => void ;
5150} ) {
@@ -62,7 +61,7 @@ const FileTreeRow = memo(function FileTreeRow(props: {
6261 } }
6362 onPress = { ( ) => {
6463 if ( node . kind === "directory" ) {
65- props . onPressDirectory ( node . path ) ;
64+ props . onPressDirectory ( node . path , ! props . expanded ) ;
6665 return ;
6766 }
6867 props . onPressFile ( node . path ) ;
@@ -97,7 +96,9 @@ const FileTreeRow = memo(function FileTreeRow(props: {
9796 >
9897 { node . name }
9998 </ Text >
100- { node . kind === "directory" && props . loaded ? (
99+ { node . kind === "directory" && props . expanded && props . loading ? (
100+ < ActivityIndicator size = "small" accessibilityLabel = { `Loading ${ node . name } ` } />
101+ ) : node . kind === "directory" && props . loaded ? (
101102 < Text className = "text-2xs font-t3-medium text-foreground-tertiary" >
102103 { node . children . length }
103104 </ Text >
@@ -110,10 +111,12 @@ export function FileTreeBrowser(props: {
110111 readonly entries : ReadonlyArray < ProjectEntry > ;
111112 readonly error : string | null ;
112113 readonly isPending : boolean ;
114+ readonly isRefreshing : boolean ;
113115 readonly searchQuery : string ;
114116 readonly searchTruncated : boolean ;
115117 readonly selectedPath : string | null ;
116118 readonly loadedDirectories : ReadonlySet < string > ;
119+ readonly loadingDirectories : ReadonlySet < string > ;
117120 readonly onLoadDirectory : ( path : string ) => void ;
118121 readonly onPreviewFile ?: ( path : string ) => void ;
119122 readonly onRefresh : ( ) => void ;
@@ -127,12 +130,13 @@ export function FileTreeBrowser(props: {
127130 const insets = useSafeAreaInsets ( ) ;
128131 // Native transparent-header height ≈ safe-area top + nav bar (~44). Matches the
129132 // observed adjustedContentInset bottom (~102) seen in the native trace.
130- const headerInset = NATIVE_LIQUID_GLASS_SUPPORTED ? insets . top + IOS_NAV_BAR_HEIGHT : 0 ;
133+ const headerInset = Platform . OS === "ios" ? insets . top + IOS_NAV_BAR_HEIGHT : 0 ;
131134 const {
132135 onLoadDirectory,
133136 onPreviewFile,
134137 onSelectFile,
135138 loadedDirectories,
139+ loadingDirectories,
136140 selectedPath : controlledSelectedPath ,
137141 } = props ;
138142 const controlledSelectedPathRef = useRef ( controlledSelectedPath ) ;
@@ -184,17 +188,21 @@ export function FileTreeBrowser(props: {
184188 [ ] ,
185189 ) ;
186190
187- const toggleDirectory = useCallback ( ( path : string ) => {
188- setExpandedPaths ( ( current ) => {
189- const next = new Set ( current ) ;
190- if ( next . has ( path ) ) {
191- next . delete ( path ) ;
192- } else {
193- next . add ( path ) ;
194- }
195- return next ;
196- } ) ;
197- } , [ ] ) ;
191+ const toggleDirectory = useCallback (
192+ ( path : string , expand : boolean ) => {
193+ if ( expand ) onLoadDirectory ( path ) ;
194+ setExpandedPaths ( ( current ) => {
195+ const next = new Set ( current ) ;
196+ if ( next . has ( path ) ) {
197+ next . delete ( path ) ;
198+ } else {
199+ next . add ( path ) ;
200+ }
201+ return next ;
202+ } ) ;
203+ } ,
204+ [ onLoadDirectory ] ,
205+ ) ;
198206 const handleSelectFile = useCallback (
199207 ( path : string ) => {
200208 if ( pendingSelectionTimeoutRef . current !== null ) {
@@ -219,6 +227,7 @@ export function FileTreeBrowser(props: {
219227 selected = { item . node . kind === "file" && item . node . path === selectedPath }
220228 expanded = { expandedPaths . has ( item . node . path ) }
221229 loaded = { loadedDirectories . has ( item . node . path ) }
230+ loading = { loadingDirectories . has ( item . node . path ) }
222231 onPressDirectory = { toggleDirectory }
223232 onPreviewFile = { onPreviewFile }
224233 onPressFile = { handleSelectFile }
@@ -229,36 +238,40 @@ export function FileTreeBrowser(props: {
229238 handleSelectFile ,
230239 onPreviewFile ,
231240 loadedDirectories ,
241+ loadingDirectories ,
232242 selectedPath ,
233243 toggleDirectory ,
234244 ] ,
235245 ) ;
236246
237- // SPIKE: render the FlatList as the screen's DIRECT content (no wrapping View), and
238- // mirror the Home ScrollView exactly — `contentInsetAdjustmentBehavior: "automatic"`
239- // with NO manual contentInset. iOS only applies the nav-bar top inset + scroll-edge
240- // blur to a scroll view in the screen's primary position; a scroll view buried in
241- // flex-1 Views is ignored, which is why the tree rendered under the header with no blur.
247+ const extraData = useMemo (
248+ ( ) => ( { expandedPaths, loadedDirectories, loadingDirectories, selectedPath } ) ,
249+ [ expandedPaths , loadedDirectories , loadingDirectories , selectedPath ] ,
250+ ) ;
251+
252+ // UIKit owns the header inset on every supported iOS version. Keep the
253+ // list as direct screen content so automatic inset adjustment can find it.
242254 return (
243- < FlatList
255+ < LegendList
256+ contentInsetStartAdjustment = { headerInset }
244257 alwaysBounceVertical
245258 className = "flex-1"
246259 data = { visibleNodes }
247260 keyExtractor = { ( item ) => item . node . path }
248- contentInsetAdjustmentBehavior = { NATIVE_LIQUID_GLASS_SUPPORTED ? "automatic" : "never" }
261+ contentInsetAdjustmentBehavior = { Platform . OS === "ios" ? "automatic" : "never" }
249262 scrollIndicatorInsets = {
250- NATIVE_LIQUID_GLASS_SUPPORTED
251- ? { top : headerInset , left : 0 , right : 0 , bottom : 0 }
252- : undefined
263+ Platform . OS === "ios" ? { top : headerInset , left : 0 , right : 0 , bottom : 0 } : undefined
253264 }
254265 keyboardDismissMode = "on-drag"
255266 keyboardShouldPersistTaps = "handled"
256- initialNumToRender = { FILE_TREE_INITIAL_RENDER_COUNT }
257- maxToRenderPerBatch = { FILE_TREE_RENDER_BATCH_SIZE }
258- updateCellsBatchingPeriod = { 16 }
259- windowSize = { 5 }
267+ estimatedItemSize = { 42 }
268+ recycleItems
269+ maintainVisibleContentPosition
270+ extraData = { extraData }
260271 contentContainerStyle = { { paddingTop : 8 , paddingBottom : 8 } }
261- refreshControl = { < RefreshControl refreshing = { props . isPending } onRefresh = { props . onRefresh } /> }
272+ refreshControl = {
273+ < RefreshControl refreshing = { props . isRefreshing } onRefresh = { props . onRefresh } />
274+ }
262275 renderItem = { renderItem }
263276 ListHeaderComponent = {
264277 < >
0 commit comments