Skip to content

fix: eliminate random list-mode row spacing on first render#140

Draft
Kallb123 with Copilot wants to merge 4 commits into
mainfrom
copilot/fix-media-library-spacing-issue
Draft

fix: eliminate random list-mode row spacing on first render#140
Kallb123 with Copilot wants to merge 4 commits into
mainfrom
copilot/fix-media-library-spacing-issue

Conversation

Copilot AI commented May 6, 2026

Copy link
Copy Markdown
Contributor

FlashList 2.0 hardcodes a 200 px default height estimate for unmeasured items. In list mode, rows are only 40–80 px tall, so the initial render positions every row 200 px apart — producing random-looking gaps that only normalise after items are measured through subsequent navigation.

Changes

  • MediaBrowserScreen.tsx — switches list mode from FlashList to React Native's FlatList with getItemLayout, which supplies the exact listRowHeight for every item index at construction time. This eliminates the height-estimation phase entirely, giving a correct layout from the very first render. Grid/poster mode continues to use FlashList unchanged.

  • MediaBrowserScreen.tsx — extracts a shared getItemHandlers useCallback containing the common isEditable / isShowAtRoot / isSelected / handlePress / onEditPress logic, removing duplication between the list-mode and grid-mode renderItem callbacks.

@Kallb123

Kallb123 commented May 6, 2026

Copy link
Copy Markdown
Owner

@copilot checks are failing

Copilot AI commented May 6, 2026

Copy link
Copy Markdown
Contributor Author

@copilot checks are failing

Fixed in commit 9b702a7. The TypeScript error was caused by using overrideItemLayout.size which doesn't exist in FlashList 2.0's public API (only span is exposed).

The root cause of the spacing bug is that FlashList 2.0 hardcodes a 200 px default height estimate for all unmeasured items — list mode rows are only 40–80 px, so the initial render shows every row 200 px apart. After measurement the gaps normalise, which is why navigating in and out of folders fixes it.

The fix replaces FlashList with React Native's FlatList + getItemLayout for list mode. FlatList uses natural flex flow (no height estimation needed) and getItemLayout supplies the exact row height for every index, giving a correct layout from the very first render. Grid/poster mode continues to use FlashList unchanged. The duplicated render logic was also consolidated into a shared getItemHandlers useCallback.

Copilot AI requested a review from Kallb123 May 6, 2026 22:28
@Kallb123 Kallb123 marked this pull request as draft May 7, 2026 05:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants