●RESET — Since 11/23, Reset in the iPhone preview opens your app like a fresh install●SONNET 4.5 — Sonnet 4.5 retires from the Claude API on 11/30, 6 days left. Check which model your AI features call●AUTH TAB — Expo users report Android apps being killed while the sign-in tab is open●NEW — New: Archive or delete? Where to draw the line when tidying projects●2.5 ROUTE — From 12/1, Gemini 2.5 requests reroute to newer models at new rates. 7 days left●COCOAPODS — With CocoaPods Trunk going read-only, developers are weighing a move to SwiftPM for Expo apps●RESET — Since 11/23, Reset in the iPhone preview opens your app like a fresh install●SONNET 4.5 — Sonnet 4.5 retires from the Claude API on 11/30, 6 days left. Check which model your AI features call●AUTH TAB — Expo users report Android apps being killed while the sign-in tab is open●NEW — New: Archive or delete? Where to draw the line when tidying projects●2.5 ROUTE — From 12/1, Gemini 2.5 requests reroute to newer models at new rates. 7 days left●COCOAPODS — With CocoaPods Trunk going read-only, developers are weighing a move to SwiftPM for Expo apps
Why Only the First Page of Your Carousel Is Blank at Launch, and How to Make FlatList Start on the Right Page
My wallpaper app opened on an empty first page. Swiping showed page two just fine, and swiping back left page one empty again. The pager had been told where to start before it knew its own size. Here is the Android fix and the Expo FlatList pattern that closes the same gap.
I was trying out an update of my wallpaper app on a test phone when the main screen came up as one flat color. No wallpaper, no spinner. I swiped left and page two appeared instantly. I swiped back, and page one was still empty.
As an indie developer, my first instinct was the network. A slow connection, a corrupted cache, a bad URL. But once I traced it, the first page had not failed to load an image. The page itself had never been built. Everything went wrong before the image library was even involved.
The real cause was timing. I was telling the pager which page to start on before it had measured itself, so the binding for that first page was simply skipped. What follows is the Android fix I actually shipped, and the way the same gap shows up, and closes, in the Expo code that Rork tends to generate.
What was actually happening
Three symptoms lined up:
Only the page meant to appear first was empty at launch
Swiping drew page two and beyond normally
Swiping forward and back again did not bring page one back
That last one was the giveaway. If swiping proves the image path works, but page one still never returns, the problem sits upstream of image loading. It sits where the pager decides which pages to build.
On Android, I was passing the start position to ViewPager2 synchronously, right after creating the screen. The adapter had not finished measuring itself. The pager accepted the jump, but the bind for the page it jumped to fell through the cracks. Every later page got bound fresh on swipe, which is why everything else looked fine.
The Android fix I shipped
The change itself was almost embarrassingly small. I moved the position call to after layout.
// Before: position set synchronously right after the screen is created.// The adapter has not been measured yet, so the initial page bind is skipped.viewPager.setAdapter(adapter);viewPager.setCurrentItem(adapter.getStartPosition(), false);// After: queue it with post so it runs once measure/layout has completed.viewPager.setAdapter(adapter);viewPager.post(() -> viewPager.setCurrentItem(adapter.getStartPosition(), false));
Anything handed to post goes onto that view's message queue and runs after a full measure and layout pass. Swapping the order was enough for the first page to be built properly.
What made me pause was the thought that the same ordering mistake could live elsewhere. I added an item to my iOS checklist: look for any place that hands UIPageViewController its first page inside viewDidLoad. I have not seen the symptom on iOS. It is a preventive check, based on the fact that the same screen structure invites the same ordering mistake.
A pager gets its position only after it knows its size. That is the one ordering rule I now settle before writing any carousel, on any platform.
✦
Thank you for reading this far.
Continue Reading
What follows includes implementation code, benchmarks, and practical content we hope you'll find useful. This site runs without ads — server and development costs are supported entirely by members like you. If it's been helpful, we'd be truly grateful for your support.
WHAT YOU'LL LEARN
✦When the first page of a pager stays blank at launch, you will know to suspect when the position was handed over, not the image loading, and save yourself the wrong investigation
✦You can rebuild a horizontal FlatList so that initialScrollIndex arrives only after the width is known, and have it open on the intended page on any device or split-screen layout
✦You will be able to drop in a small dev-only watcher that tells you within seconds whether a layout change has quietly brought the blank page back
Secure payment via Stripe · Cancel anytime
✦
Unlock This Article
Get full access to the rest of this article. Buy once, read anytime. This site is ad-free — your support goes directly toward keeping it running.
When Rork builds a carousel, it usually comes out as a horizontal FlatList with pagingEnabled. The timing problem shows up here too, wearing different clothes.
Here is the version I see most often. It calls scrollToIndex from a ref right after mount, to jump back to the page the user last viewed.
// ❌ Can leave page one blank, or never leave the first item, at launchimport { useEffect, useRef } from "react";import { FlatList, Image, useWindowDimensions } from "react-native";type Wallpaper = { id: string; uri: string };export function WallpaperCarousel({ items, startIndex,}: { items: Wallpaper[]; startIndex: number;}) { const listRef = useRef<FlatList<Wallpaper>>(null); const { width } = useWindowDimensions(); useEffect(() => { // Right after mount, no page positions have been measured yet. // With neither getItemLayout nor onScrollToIndexFailed, dev builds stop with // "scrollToIndex should be used in conjunction with getItemLayout or onScrollToIndexFailed" listRef.current?.scrollToIndex({ index: startIndex, animated: false }); }, [startIndex]); return ( <FlatList ref={listRef} data={items} horizontal pagingEnabled keyExtractor={(w) => w.id} renderItem={({ item }) => ( <Image source={{ uri: item.uri }} style={{ width, height: "100%" }} /> )} /> );}
There are three holes stacked on top of each other:
The position arrives too early.useEffect runs right after commit, before FlatList has measured its children
There is no way to compute positions. Without getItemLayout, FlatList cannot know where unrendered pages are. Dev builds stop with the message in the comment above; release builds just fail to scroll, silently
The width comes from the whole screen.useWindowDimensions gives you the device width. Put the carousel inside padding or a split-screen pane, and the page width and the snap unit drift apart, so it stops halfway between pages
The third one is the hardest to notice. On a phone in full screen, the two widths match, so the bug only surfaces once you add margins or run in split view.
Measure first, then hand over the first page
In the fixed version, the View wrapping the carousel measures its real width, and the FlatList is not rendered at all until that width is known. The start position is no longer pushed in later through a ref. It goes into the very first render as initialScrollIndex.
// ✅ Measure the frame, then render FlatList with the start page in its first renderimport { useCallback, useState } from "react";import { ActivityIndicator, FlatList, Image, LayoutChangeEvent, StyleSheet, View,} from "react-native";type Wallpaper = { id: string; uri: string };export function WallpaperCarousel({ items, startIndex,}: { items: Wallpaper[]; startIndex: number;}) { const [pageWidth, setPageWidth] = useState(0); const onLayout = useCallback((e: LayoutChangeEvent) => { // Round so sub-pixel jitter does not trigger endless re-renders const w = Math.round(e.nativeEvent.layout.width); setPageWidth((prev) => (prev === w ? prev : w)); }, []); // Rendering before data arrives would lock initialScrollIndex to the first item const ready = pageWidth > 0 && items.length > 0; const safeIndex = Math.min(Math.max(startIndex, 0), Math.max(items.length - 1, 0)); return ( <View style={styles.frame} onLayout={onLayout}> {!ready ? ( <ActivityIndicator size="large" style={StyleSheet.absoluteFill} /> ) : ( <FlatList // Rebuild when the width changes (rotation, split-screen) key={`carousel-${pageWidth}`} data={items} horizontal pagingEnabled showsHorizontalScrollIndicator={false} keyExtractor={(w) => w.id} initialScrollIndex={safeIndex} // Every page has the same width, so position is simple multiplication getItemLayout={(_, index) => ({ length: pageWidth, offset: pageWidth * index, index, })} // Build only the start page and its neighbours first initialNumToRender={1} windowSize={3} onScrollToIndexFailed={({ index }) => { // Should not fire while getItemLayout exists. If it does, log it // instead of silently snapping back to the first page. console.warn(`carousel: scrollToIndex failed at ${index}`); }} renderItem={({ item }) => ( <Image source={{ uri: item.uri }} style={{ width: pageWidth, height: "100%" }} resizeMode="cover" /> )} /> )} </View> );}const styles = StyleSheet.create({ frame: { flex: 1, backgroundColor: "#d9d9d9" },});
Here is the reasoning behind each choice:
Measure with onLayout because the frame defines the page. Use the frame width rather than the screen width, and the snap unit stays correct inside padding or split view
Do not render the list while the width is 0. With a zero width, getItemLayout puts every page at offset 0, and the list sticks to the first item
Do not render it while the data is empty either.initialScrollIndex is read only on the first render. If the list renders once with an empty array, data arriving later will not move it. This was the part I could not have learned from the docs alone
Put the width in the key. When rotation or split view changes the width, the list is rebuilt instead of keeping stale offsets. Rebuilding sends it back to startIndex, so if you want to keep the current page, hold it in the parent and pass it back in
Give the frame a background color. Even if the first image is late, the user sees a color that says something is coming, not a bare white screen. On Android, I set the page background and the image placeholder to the same color, and the "nothing is here" white disappeared
A watcher that only runs in dev builds
A blank page you fixed once tends to come back the day you touch the layout. So I added a small hook that, in dev builds only, checks whether the first page actually seen matches the one you asked for.
// Dev-only watcher for the initial pageimport { useCallback, useEffect, useRef } from "react";import type { ViewToken } from "react-native";export function useInitialPageWatch(expectedIndex: number, label: string) { const firstSeen = useRef<number | null>(null); const onViewableItemsChanged = useCallback( ({ viewableItems }: { viewableItems: ViewToken[] }) => { if (firstSeen.current !== null) return; const first = viewableItems.find((v) => v.isViewable)?.index; if (typeof first === "number") firstSeen.current = first; }, [] ); useEffect(() => { if (!__DEV__) return; // Give the first render and image swap a moment to settle const t = setTimeout(() => { if (firstSeen.current === null) { console.warn(`[${label}] no page visible after 1.5s`); } else if (firstSeen.current !== expectedIndex) { console.warn( `[${label}] first visible page was ${firstSeen.current}, expected ${expectedIndex}` ); } }, 1500); return () => clearTimeout(t); }, [expectedIndex, label]); return onViewableItemsChanged;}
On the FlatList side, pass the returned function as onViewableItemsChanged and add viewabilityConfig={{ itemVisiblePercentThreshold: 60 }}. Recreating onViewableItemsChanged on every render triggers a warning in dev builds, which is why the hook wraps it in useCallback.
In production it does nothing. Whenever I change the padding or frame around a carousel, I launch it once in the simulator and glance at the log. It takes a few seconds, so it feels less like a test and more like a habit.
Pitfalls I ran into
A few things tripped me up while rebuilding this:
Symptom
Cause
Fix
Stops between page two and three
Page width came from the screen, not the frame
Measure the frame with onLayout and use the same value in getItemLayout
Remembers the last page, but always opens on the first
FlatList rendered once before data arrived
Hold the list back until both width and data are ready
Stops halfway after rotation
Old offsets survived the width change
Include the width in the key and keep the current page in the parent
scrollToIndex warning in dev builds
Position requested without getItemLayout
If all pages share one width, always write getItemLayout
The same idea applies if you use react-native-pager-view. Pass the start page as initialPage from the beginning instead of calling setPage right after mount; that sidesteps the ordering problem. I went with FlatList because I wanted finer control over how paging feels, but whichever you choose, the rule I keep is the same: the position belongs in the first render.
What to check next
If you have a carousel in front of you right now, this is the order I'd suggest:
Log the frame width from onLayout once, next to the useWindowDimensions width. If they differ, that is very likely where your blank page or half-stop comes from
Search for any place that moves to the start page through a ref and scrollToIndex. Replace it with initialScrollIndex plus getItemLayout
Use the watcher above to confirm that FlatList is not rendering once before the data arrives
Each of these takes a few minutes. Even the first one alone is worth doing today.
When I finally realised that the culprit was the order of a single line, after suspecting image loading for so long, I felt relieved and a little sheepish at the same time. If this shortens the hunt for anyone staring at the same empty page, that would make me glad.
Share
Thank You for Reading
Rork Lab is ad-free, supported entirely by members like you. We publish practical guides daily with implementation code, benchmarks, and production-ready patterns. If you've found it useful, we'd love to have you on board.