Documentation comes from this release commit, without inheriting newer content. Commit: 35589c6fda.
Routing
Routes are file-based via expo-router. All files live in app/. Each route file imports a screen from @features/*/screens/ and re-exports it as the default export — no business logic in the routing layer.
Cross-group navigation (onboarding ↔ tutorial ↔ auth ↔ app) is entirely declarative: the root app/_layout.tsx wraps each group in <Stack.Protected guard={...}>.
Route tree
Route → screen mapping
There is no app/index.tsx — the root layout's <Stack.Protected> blocks decide which group is mounted as the entry, so no manual boot redirect is needed.
Screen orientation
Orientation is not a global app setting — each route-group layout declares what it needs via useOrientation from @core/orientation. A shared Zustand store resolves the winning request and calls expo-screen-orientation's lockAsync exactly once per actual change, so surfaces never race each other into rotation flicker.
Landscape locks to a concrete LANDSCAPE_RIGHT (not the ambiguous LANDSCAPE mask). On iOS 16+, a mask can be a no-op when the system cannot infer which way to rotate away from portrait.
An iPhone always opens portrait, however it is held, so its splash is portrait only. An iPad opens the way it is held. Both come from Info.plist (app.config.ts), which iOS reads to draw the launch image before any app code runs:
- iPhone:
UISupportedInterfaceOrientationslists onlyUIInterfaceOrientationPortrait(IPHONE_LAUNCH_ORIENTATIONS). With all four orientations listed, a phone held sideways showed the whole splash landscape. - iPad:
UISupportedInterfaceOrientations~ipadlists all four (IPAD_LAUNCH_ORIENTATIONS). - No
initialOrientation. That option writes one starting mask for iPhone and iPad alike; without it expo-screen-orientation starts each device from its own list.PORTRAIT_UPwould turn an iPad held sideways to portrait under the splash;DEFAULTlet an iPhone's window follow a phone held sideways while the JS splash was up. - Landscape still works. Info.plist only decides the launch; after that iOS asks the app delegate, and expo-screen-orientation's subscriber answers with the current lock (
launch-orientation.test.ts). - The lock stays while the app is in the background (our patch,
patches/expo-screen-orientation@58.0.3.patch). Upstream drops it on background, and the app then answers with its Info.plist default — portrait only on an iPhone. A full-screen ad that allows landscape only (AppLovin's video screen) is still up when a tap on its store button sends the player away, so iOS found no orientation the two shared and killed the app while snapshotting it (UIApplicationInvalidInterfaceOrientation). Coming back only re-applies the lock; the module is still registered.
On an upright iPad the first landscape screen switches the app to a letterbox (iPadOS 26). The patch patches/expo-screen-orientation@58.0.3.patch makes that switch a single turn:
- Upright iPad: the lock only announces the new mask (
setNeedsUpdateOfSupportedInterfaceOrientations) and lets iPadOS letterbox the app.- With an explicit
requestGeometryUpdate, iPadOS first turned the screen 90° and then folded it back into the letterbox, so the splash turned twice.
- With an explicit
- Any iPad on iOS 16+: the lock skips the legacy
UIDeviceorientation write. It disagreed with the mask and showed up as extra jumps.
That turn happens after the splash, on a phone as on an iPad, never under it. Turned under the splash, the launch image swung round on its way out (into the letterbox on an iPad, sideways on a phone), and the logo flashed round:
- The splash keeps the orientation it opened in (always portrait on an iPhone).
(app)and(tutorial)take landscape throughuseLandscapeAfterSplash. It asks for nothing until the splash has gone (splash-visibility-store), and with no request in the store no lock goes out. Past onboarding the splash itself waits for no lock (expectedSplashOrientationisnull). - The turn happens behind a dark cover.
LandscapeTurnCoveris a plain screen in the splash's colour, over the navigator and the banner and under the modals.- It is up from the first frame, so it is in place when the splash goes, and the Song List is never seen portrait.
- It fades out (250 ms) once the window is landscape; the open-app paywall then slides in landscape.
- It covers only a launch into a landscape group, only until the first landscape window. It keeps song previews quiet while up. It gives up 1.5 s after the splash in case the lock is declined.
- An iPhone always opens portrait, so its every launch into a landscape group turns once behind it. An iPad held landscape has no turn and never sees it.
- No request keeps the last lock. Under the splash an iPad's stack can be empty: the launch paywall's landscape overlay is the only request, and closing it before the splash goes used to fall back to portrait, so the window turned portrait and back. The store now skips the lock when nobody is asking (
orientation-store.ts).
Root-level modals that need a different orientation while visible (e.g. PaywallModal) pass ORIENTATION_PRIORITY.overlay so they win over the base layout. Pass null when hidden so the overlay request is cleared without unmounting the modal — route-group layouts do not release on unmount (that caused rotation flicker during group swaps; the incoming layout's request wins by recency instead):
The post-onboarding paywall opens in portrait over (onboarding); once dismissed and (tutorial) mounts, the tutorial layout's landscape request takes over. In-app paywall opens from the side tab already in landscape.
The open-app paywalls (session 2+ subscription, session 3 discount) are the one landscape offer that can open before the app is landscape. A phone with its rotation lock on launches the app portrait, and (app) issues its landscape lock in the same commit that mounts SessionPaywallHost. The host decides the launch as soon as purchases and Remote Config are in, but opens the offer only once the window is landscape.
The offer also waits for the launch's App Open step. From launch #2 on, a player past onboarding and the tutorial who has finished at least 4 songs (lifetime song_end) may get an AdMob App Open over the Song List (AppOpenHost, which reads the launch SessionPaywallHost records as useSessionStore.currentLaunch). The paywall opens only once useAppOpenLaunchStore.phase is done — the ad shown (and handed the screen back), skipped (not loaded within 5 s), blocked by its gates or failed; a launch that never tries one — App Open off, a subscriber, too few song starts — is done at once, and a step that has not started 15 s after the launch is known is marked done anyway. So the two never land on each other and a launch with no App Open waits for nothing.
The step can end wherever the player is, so the offer also waits for the Song List (/songs) with nothing covering it and no full-screen ad on it or still handing the screen back (launch-paywall.pure.ts). Until then it stays owed, and opens the next time all of that holds — back on the Song List after a song, say. The session-3 discount is marked shown only as it opens, so a player who quits before it never loses it. Rules: ad-trigger-logic.md §6.
Landscape paywalls also size their root from the window (PaywallLandscapeSettle), not from the <Modal>. A Modal first sizes its content from the device orientation, which a rotation lock holds at portrait. Left to the Modal, the offer showed as a narrow column until the Modal caught up.
Inside (app)/(tabs), SideTabBar is a left-positioned tab rail (tabBarPosition: "left") sized for landscape — unstable_settings.anchor is songs.
The rail announces every trip it starts to another feature — a tab, or the Keyboard launcher — through onSideTabNavigate. Shared UI cannot import a feature, so a feature that keeps state across those trips listens there; the song list clears its search on it (songs.md).
Immersive piano routes — keep-awake + system gesture deferral (iOS)
Bottom-edge Home / app-switcher deferral is app-wide — AppProviders enables it at bootstrap via setGameplayGestureDeferralEnabled and the local Expo module modules/screen-gesture-defer. It is not configured per Stack.Screen and not toggled from feature screens.
The play, learn, and keyboard stack screens additionally call useKeepGameplayAwake so the device does not auto-lock during an immersive session. play-result does not — the session is over and normal auto-lock is fine.
Transitions. /(app)/play and the entire /(tutorial) stack use animation: "fade" so the shared prepare loading card (PrepareLoadingOverlay) fades in/out rather than sliding over the previous screen. play-result and keyboard likewise fade. learn keeps the stack's own push, except a visit opened with reveal=1 (learnOpensWithReveal(route.params)), which opens in place with animation: "none" — see below.
See architecture.md § System gesture deferral for the deferral call chain and rebuild requirements.
Launch splash — two screens
- Native launch image — the piano keys alone (
assets/splash/splash-keys.pngthrough react-native-bootsplash, 192dp) on the starrySplashBackground. No wordmark, no tagline (withSplashBottomImageis no longer registered). - JS launch splash —
AppLaunchSplash, mounted from the root layout's first render. Once its backdrop and key art have decoded and fonts are in, it hides the native splash and plays the "Key ripple" intro (splash-ripple.pure.ts) off one clock, starting on the native frame: the keys, big and centred where the native image drew them, dip and light up one by one left → right, then glide up and shrink into place; MAGIC PIANO pops in letter by letter (judgement font, black stroke, gradient-03 sliced per letter); then "Headphone Recommended … NN%". The keys are one Skia canvas (SplashRippleKeys) cutting the glow-free artassets/splash/splash-keys-clean.pnginto five hand-traced key slices over the designer's vector glow; it is drawn under the native splash before the intro starts, so its image upload and shader compiles happen there. Reduced motion keeps the keys in place and only fades the text. The percentage is live, from the boot gatesuseHideSplashalready evaluates (splash-progress-store).
Intro, essential loading, then deferred FTUE work. The intro plays beside Remote Config's
fetch, cheap setup and the app-open chime. When it ends,
markSplashIntroDone starts the guarded SDK loading stage in
start-app-bootstrap.ts, behind the still splash.
The lifecycle facade owns gameplay warmups, catalog sync and MIDI/version prefetch through
AppStartupPolicy. If onboarding was incomplete
at launch, these tasks wait for both splash hidden and the first FTUE screen committed, then two
frame boundaries and idle. A returning launch starts them after the intro: its navigator waits
for RC and haptics (plus tracking/attribution behind a boot-time ATT prompt), and a completed
player's splash also waits for sampler/SFX launch warmups. RevenueCat and Crashlytics do not gate
navigation. Only the % moves while loading, drawn by Skia from shared values. The boot ceilings
(8 s services, 12 s hard) count from loading start. If the JS splash has not taken over within
SPLASH_TAKEOVER_GRACE_MS (2 s), loading starts behind the native splash and refuses a late
intro takeover. See App startup and lifecycle for lifecycle
transitions and restart behavior.
The splash store still decides when the splash may go. The boot gates live in it rather than in React state, so a gate closing re-renders only what reads it: the root layout hears selectAppReady, and the % takes its share straight into a shared value. It asks the JS splash to leave, and the JS splash fades out, and only then do releaseSplashCover, markSplashHidden and fn_after_splash_screen run (launch-splash-handoff). If the JS splash never took over, the native splash is hidden directly as before. The launch paywall waits for useSplashHidden(), because a native <Modal> would draw over the JS splash.
A dev build shows the native image twice: expo-dev-client puts it back up while it downloads the bundle. Release builds show it once.
Learn Mode entry — lock, guard and reveal
Learn Mode opens after four finished songs (song_end; the rule is in @core/learn-access, the full contract in songs.md). Three routing facts follow from it:
/learnis guarded in the screen.LearnModeScreenrenders nothing for a locked player and, once, pops back (router.back()), orrouter.replace("/songs")when there is nothing under it. Not a<Redirect>: inside this pushed screen it REPLACESlearnon the(app)stack with a fresh(tabs)route, leaving two live Song Lists. Every other lock (the Song List pill, the result's Learn tab) sits at a call site, so this one covers whatever reaches the route without passing one — a deep link, a stale path on the stack./learn?reveal=1plays the song reveal first. Therevealparam is only set by the "Learn Mode unlocked!" popup's Claim. That visit opens in place (animation: "none"), under the popup, which stays up until the path leaves/songs— so the popup hands straight to the reveal.LearnModeScreenshows the sharedSongRevealShowcaseforsongRevealHandoffMs(), then mounts Learn as usual (countdown, Stage 1); the body is told the screen has already arrived (useScreenEntered({ alreadyEntered: true })), so the countdown does not wait out the entrance backstop. It is decided once on mount; a visit without the param, or a song the catalog cannot show, goes straight in.- The popup is a root host.
LearnUnlockHostis mounted inapp/_layout.tsxnext toTutorialExitHost, so it outlives every screen. It opens only while the path is/songs, and Claim navigates to/learnfortwinkle-twinkle-little-starwithreveal=1andsongPlayType: "home".
Root layout — the only place guards live
Three things are co-located here on purpose:
- Font loading + splash dismissal — they need to run before the user sees any UI.
- Zustand reads for
hasCompletedandsession— selectors subscribe the root layout to those slices. <Stack.Protected>guards — each block is mounted only when its guard istrue. The router activates the first matching block, so order = priority.
Guard / redirect flow
<Stack.Protected> does the work that per-group <Redirect /> used to. When a guard flips from false to true, that block becomes the active stack and Expo Router transitions to its initial route automatically.
Guard priority
The subscription paywall opens after onboarding (finishWithPaywall() → dismiss → complete()), then the tutorial runs. Completing the tutorial mounts (app).
The guards are mutually exclusive by construction: if !hasCompleted is true the onboarding block wins; once onboarding and the paywall handoff finish, the tutorial guard takes over; then (app) mounts.
Zustand-driven transitions (no router calls needed)
Screens just mutate Zustand and let the root layout react. The only legitimate uses of router are:
- Intra-group navigation (push/pop inside the same stack): e.g.
router.push('/(auth)/sign-up')to swap between sign-in and sign-up.
Sign-in sequence (cross-layer)
Sign-out sequence
Adding a new route
-
Decide its location in the tree (auth-only? tab? modal?).
-
Add a file under
app/...that does only: -
If you need params, read them in the route file via
useLocalSearchParamsand pass them as props (seeapp/(app)/play.tsx). -
If the route needs auth, place it under
(app)/; the root layout's<Stack.Protected guard={hasCompleted && !!session}>already gates the entire group.
Adding a new top-level group
If you ever need a fourth top-level group (e.g. an (error) recovery stack), add a <Stack.Protected guard={...}> block to app/_layout.tsx and an app/(new-group)/_layout.tsx. Keep guards mutually exclusive — pick a Zustand flag that's true in exactly one of the blocks at a time.