Documentation comes from this release commit, without inheriting newer content. Commit: 35589c6fda.
Feature — Songs
Song list UI, preview playback, and monetisation surfaces. Reads the merged catalog from features/catalog and applies live lock state from @piano/user-library.
Files
The Song List is the repo's first feature on the three-layer rule (three-layer-architecture) — the reference migration for the next ones.
Route: app/(app)/(tabs)/songs.tsx.
Architecture
- UI never imports a service: no
@core/sdk,@core/iap,routeror entitlements call in a Song List.tsx. A press calls a flow-store action; a component selects display-ready values. - Store actions are the old screen callbacks moved verbatim. A press reads the list as it
stands at the tap (
readListAtTap), never a render's copy. Server data (IAP offerings) stays in React Query;useSongListViewis the one hook that joins it with the stores, each stage memoized on its own inputs so a price arriving keeps the preview queue's songs and the header's genres. - Services (
services/) hold no rule. Tests hand inFakeSongsServicesthroughsetSongsServices; the registry loads the composition root lazily, so a store test never pulls the SDK chain in.iap.purchasewrapsgetIapService()for the same reason.
Who re-renders on what:
song-list-render-ownership.contract.test.ts and song-card-reveal-render-free.contract.test.ts
pin this, and the flows are driven in song-list-flow-store.test.ts.
A card crossing the viewport edge runs no animation at all (the list's edge fade, see Reveal
below). A finished slide-in still shows up in the Profiler as a small View render with
state: settledStyle. That is Reanimated 4 writing the animation's final style back into the
Animated.View (FORCE_REACT_RENDER_FOR_SETTLED_ANIMATIONS, on by default, flushed every
500ms; the app sets no Reanimated static flags, see piano.md). It stops at that
view; SongRow below it never renders.
The list (Legend List v3)
SongList is an AnimatedLegendList
(@legendapp/list/reanimated, pinned to 3.6.0) with recycleItems on — Legend List leaves
recycling off by default. A card that scrolls off is re-bound to the next song instead of being
unmounted, so scrolling neither mounts heavy cards nor re-renders the whole list as FlatList's
moving window did. (The list was briefly @shopify/flash-list v2; the recycling-safe pieces
below carried over unchanged.)
- Fixed-height cells. Each cell is one row plus the gap under it
(
SONG_LIST_ROW_HEIGHT + spacing.md); the list has nogapof its own.getFixedItemSizereturns that same height, so Legend List places rows without measuring any. Rowistarts ati × rowStride, the geometry the reveal and the glide both use. - Pools by button type.
getItemTypeisresolveSongListItemType(song-list-item-row.utils.ts): the promo card is its own pool, and songs pool bydeal/ctaandlearnCta. A recycled cell is only re-bound to a row with the same buttons, so re-binding is a props update. Before this, a Play cell re-bound to a Premium row tore down the Play pill (and its Skia canvas) and mounted the Premium pill (its outlineMaskedViewand shine), which put about half the re-bind commits over 16ms. maintainVisibleContentPosition={false}. Legend List anchors on size changes by default; the list keeps FlatList's behaviour so the promo appearing or going never shifts the rows under the player.- Scroll offset.
sharedValues={{ scrollOffset: scrollYSv }}:AnimatedLegendListwrites its offset into the rows' shared value on the UI thread (from the scroll view's native events), so there is no workletonScrollhandler. The list'sref(LegendListRef) is the glide'sscrollToOffset. - Kept from FlatList:
viewabilityConfigCallbackPairs(built once),extraData,onRefresh, the drag and momentum handlers, andkey={listKey}(a filter remounts the list at its top). - A recycled card starts over for its new song. It keeps its component and shared values,
so everything read "once at mount" is re-derived when its key changes:
SongCardRevealcancels any running animation and re-derives its state for the new song (resolveSongCardRebind): a song already seen rests in place; one never seen slides in at once if it is on screen, or waits to the side until it scrolls in.SongTitleMarqueekeeps its measured fit together with the title it belongs to, so a re-bound row renders its own title's fit and ignores a width measured on the old one.- Already safe:
SongRow's card size (every card is the same size),PrimaryButton's layout cache, andImageCache(recyclingKey={track.id}).
Song card perf
What each card on screen no longer costs (DEV-reviewed for look, 2026-11):
- CTA pills paint no Skia.
SongRowpassesfill="lite"to everyPrimaryButton: the Play and Learn pills draw one native linear gradient (resolveLitePillFill) instead ofPlayPillFill/LearnPillFillcanvases, and Learn's gradient rim is a flat hairline. Close to the design, not exact — approved for performance. Every other screen keeps the full fill. - The Premium halo has a shadow path. Its two halo views get an opaque pill backing on iOS
(
IOS_SHADOW_PATH_BACKING), so Fabric draws the shadow from a rounded rect instead of rendering it off-screen every frame. - The shine sleeps off screen.
ButtonShinetakesactiveSv(the row's in-view flag viaPremiumButton.shineActiveSv) and parks while the cell is outside the viewport. - Fewer views and masks per card. The iap / deal glass is pre-mixed into its backing
(
compositeOver); the washes skip their own rounded clip inside the rim's inset (clipped={false}); the cover is rounded on the image itself;Iconis a singleImage. - The preview wave is a transform.
AudioWavebreathes byscaleY— noheightlayout or commit per frame.
Lock resolution
The remove-ads promo row (RemoveAdsPromoCard, at the row mon_pkg shop.noads_banner.position names — default 3, after the 2nd song — with the songs from there moved down one (promoInsertIndex); redesigned 2026-11-11) is a "folder tab" card. Its low left tab holds the Shop's no-ads art (ShopArt no-ads, with the pack's particles and its duration word — LIFETIME, or 1-DAY / 7-DAYS when the variant's banner sells a pass) and, for the lifetime pack, "+" and the bonus songs' covers over their "N VIP SONGS" sticker (ShopBonusCovers, still, like the No Ads popup) — the variant's noads.lifetime_bonus_songs, each with its bundled bonus-<id> art or its catalog cover. All of it is display-ready in the promo list item's art (promo-art-view.ts buildRemoveAdsPromoArt, built in useSongListView), sized by promo-card-art.ts (PROMO_ART_PHONE / _TABLET); the tab grows to hold the art (promoTabMetrics moves the step line past it). Then the "Play without interruption" pitch (shopLifetimeTitle gold → pink accent, TextOutlineRun) over "Remove popup ads forever", and the Shop-gold price pill (shopPriceFill / premiumLabel, 132pt / iPad 180pt like the song CTAs). IapPromoCardBackground draws it as one static Skia canvas at the card's measured width: the outline from the pure promo-card-shape.ts in a deep navy (noAdsBannerTab*), then the body (buildPromoSheenPath: its left edge is the step line carried down to the bottom; clipped to the card) running violet → navy → plum (noAdsBannerBody*) with a violet glow where it steps up and a shade along its bottom, and a 1pt rim (PROMO_RIM_WIDTH) lit warm at the top-right and cool at the bottom-left (promoRimAxis, noAdsBannerRim*). It shows only in a variant that sells No Ads (selectNoAdsBanner: the Shop is on) and while the player still sees ads, and it sells the lifetime pack of the variant's tier (com.piano.noads.lifetime for t1, com.piano.noadspack for t2), priced from the offerings (priceByProductId). A tap on the card or its pill buys it straight away — the flow store's buyRemoveAds → iap.buyNoAds opens the native payment sheet. There is no remove-ads modal: RemoveAdsModal, its host and useRemoveAdsStore were deleted on 2026-11-05 — and the pill spins (selectRemoveAdsPurchasing) until it settles; a completed purchase syncs entitlements, adsRemoved drops the row. It leaves once ads are off (lifetime, VIP or a running 1-day / 7-day pass) — it does not follow Remote Config enableIAP, which only switches single-song deals (remote-config-enable-iap.md).
Lifetime bonus songs (mon_pkg noads.lifetime_bonus_songs; PM 2026-11-09) have no look or lock of their own: they keep their sheet place and their sheet card (Free, video or VIP), and a tap does what the sheet says (play, a rewarded video, the VIP paywall). Owning a No Ads Lifetime pack (either tier) adds them to the player's owned songs (catalogSongsOwnedViaIap), and getSongLockState puts ownership before the premium and video flags, so they open with no video and no VIP. PM picks VIP songs for the list; free and video songs are handled the same way in case one slips in. The sheet's isIAP column is not used for this — it stays the single-song deal.
Lock flags on each row come from @piano/catalog lock rules evaluated against a LockContext (isVip + owned song ids from UserLibraryManager), not from stale catalog cache alone. Row display state (variant, CTA, IAP price, preview badge) is precomputed in useSongListView (song-list-view.ts) via buildSongRowViewModel before the list renders — SongRow is presentational only. SongListItemRow memoizes each cell so preview/purchase/promo-price updates and extraData churn do not re-render unrelated rows — a new view-model field is only seen by the row once areSongRowViewModelsEqual (song-list-item-row.utils.ts) compares it. A row's presses are the flow store's actions (song-list-flow-store.ts) — stable zustand references, so they never re-render a row — and each press reads the list as it stands at the tap (readListAtTap: catalog, lock snapshot, filters), so a tap's song_click (song_unlock_type, song_order) and the play guard's isPlayable read the current lock state, owned sources, list order and catalog, never the ones the row was first rendered with. Whether a row is previewing or purchasing it selects itself.
The header difficulty dropdown filters by five playable slugs (easy … impossible); tutorial is catalog-only and not a filter option — see catalog.md — Difficulty scale.
The header search is cleared when the side bar takes the player to another feature — a tab, or the Keyboard launcher (onSideTabNavigate) — so the full list is what they come back to. The field gives up its focus at the same time: iOS hands focus back to it when the list shows again, which would raise the keyboard over the emptied search. Difficulty and category stay as they were, and Play / Learn from the list keep the search.
Row meta column — difficulty, stars, trophy
The column between the title and the CTAs is the difficulty label stacked over four marks in one row: three stars, then the Learn Mode trophy.
The two answer different questions, so three gold stars beside a dim trophy is an ordinary row,
not a contradiction. The trophy is lit in the stars' gold (ratingStar) and dim in the stars'
empty grey (ratingStarEmpty) — SongRowTrophy,
sized and spaced off SCORE_MARK_SIZE / SCORE_MARK_GAP so it reads as the fourth of four.
A song with no Learn chart ("Coming soon") has no Challenge to pass and so shows a permanently
dim trophy.
Completion is read from useLearnProgressStore.bySongId once in SongsScreen and threaded
through buildSongRowViewModel as learnCompleted, exactly the way bestStarsBySongId is — no
row subscribes to the progress store itself.
isLearnSongCompleted answers from the
stored record alone (its passed holds the last stage of its own stageCount), so the list
never loads a chart to draw a trophy; a record saved before stage layouts existed carries no
stamp and is read on seven stages, the way the store's own normalize reads it.
The row is the one caller that wears the difficulty bare — DifficultyTag surface="bare"
drops the fill, the border and the pill padding and leaves the label. Every other caller keeps
what it had: surface="flat" (solid label, no MaskedView gradient — cheap enough for a list)
on SessionRecommendationCard / SongRevealMeta / TutorialPickSongCard, and the default
glass (blurred chip, gradient label) in PremiumUnlockModal and the play-screen headers. All
three surfaces keep the invisible widest-label sizer: it is what holds a column of tags to one
width, and with the pill gone it is the only thing doing so.
Preview playback
Auto-play and follow. On each visit the list plays up to five on-screen songs in turn through the shared preview stack (@core/audio/song-preview, useSongPreviewQueue). When a song starts — queued or tapped — its card glides to the middle of the list (clamped at the list's top and bottom) via usePlayingSongCentering, whose rules are in playing-song-centering.ts. The glide is one native animated scrollToOffset per song start, computed from the list's uniform cells (resolveSongListItemLayout). It is skipped while the player drags or flings. Rows a glide pushes off screen still count as on screen for the queue until the player's next drag, so a glide never costs the queue a song.
Who re-renders on a preview. The id of the song previewing lives in the songs store (useSongsStore.previewingId), mirrored from the preview service by followPreviewService while the list is focused (useFocusEffect), so a result's previews over it redraw none of its rows. Each row selects only its own yes/no (selectIsPreviewing) in SongListSongRow, inside the cell's SongCardReveal — SongListItemRow reads no store, so the reveal wrapper never re-renders on a preview, and usePlayingSongCentering follows the id through a store subscription. The screen holds no preview state: it uses useSongPreviewControls(), which has the same stop-on-leave rules as useSongPreview() but no id. A press that takes the screen over calls the flow store's stopPreview, which silences the preview and sets previewVisitEnded; SongList passes enabled: !previewVisitEnded to the queue, which ends the visit, and the next focus starts a new one. Every song card, and every CTA pill on one, has the same size, so the first one measured hands its size to the rest (createLayoutSizeCache, PrimaryButton's layoutCacheKey), and later rows draw their border and gradient on the first render instead of again after onLayout.
What sounds. A preview is fifteen seconds (PREVIEW_WINDOW_MS) of the song's own gameplay chart, synthesised through the piano sampler by ChartPreviewPlayer behind the one shared SongPreviewService (getSongPreviewService()). The row's ▶ badge renders only for songs with a bundled chart (hasSongPreview). Only one preview sounds at a time. subscribeBeats hears each note of it as it sounds (its strength, 0–1), kept apart from the preview events so the screens' preview state never sees a note; the tutorial's choose screen moves its playing cover with them. It stops when the screen loses focus, when the app goes to the background, when anything covers the screen (a paywall, an ad or a popup), or on the user's toggle.
Song Book motion
Everything below lives in src/features/songs/ and is used only by the Song Book. It runs only for rows on screen, and never commits React state on scroll or per frame.
- Viewport source.
SongsScreenwrites the list's scroll offset (AnimatedLegendList'ssharedValues.scrollOffset) and its height (onLayout) into shared values. It hands them to the rows throughSongListViewportContext(song-list-viewport-context.ts). Every row is the same height, so a row's top isindex × (rowHeight + gap), the same stride as the list's fixed-height cells. Nothing is measured per cell. - Reveal.
SongCardRevealwraps every row, the promo card included. The first time a card is 30% on screen, it slides in from 100pt to the right and fades up. The first screen of cards is staggered over 200ms. After that, the card stays at rest. The list's top and bottom edges fade instead (24pt at the top, 56pt at the bottom), so a card crossing the edge fades with its position and runs no animation. Nothing masks the scrolling list — a mask there is an off-screen pass over the whole list on every scroll frame. InsteadSongListEdgeFadefades the backdrop in over the two edges, which is the same picture: two strips, each a copy of the starfield (SongListBackdropArt) under a small staticMaskedView+LinearGradient, rasterized once. The copy lines up with the real backdrop from both views'onLayoutframes in the screen's content view (backdropFramein the songs store,resolveEdgeStripBackdropFrame), so it holds through the screen's transition. No strips while the list is shorter than both fades. It replaced an earlier per-card dim (0.5 off screen, brightening back), which ran an animation — and a ReanimatedsettledStylerender — every time a card crossed the edge. The maths is insong-card-reveal.ts. Which cards have already slid in is tracked per visit, at module scope, insong-card-seen.ts, soscheduleOnRNonly ever receives a module function. - No card gets stuck hidden. Visibility is recomputed from geometry on every scroll. An unmeasured list counts as "in view". A filter switch remounts the list and resets the offset to 0. An 800ms failsafe shows any on-screen card that has still not been revealed. The only hidden state is a card that has never been seen and is off screen.
- Preview border. The previewing row draws
SongCardPreviewBorderover its static rim: two comet heads lap the card every 8s, in the cyansongPreviewHighlight(rgba(0, 235, 244, 1)) with a matching inward glow. This is an SkSL shader ported from the Guitar app. - Title marquee.
SongTitleMarqueehandles a title too long for its row. While the row is on screen, it holds for 2.5s, scrolls across the overflow in 4.5s, holds again, then scrolls back. When the row leaves the screen, it settles back. Its measured fit is cached per title and text style for the app session (createSongTitleFitCache), so a long-title row renders once instead of again afteronLayout, and a recycled row shows its own title's fit from the first render. A measurement that finds the fit already on screen sets no state, so only a long title measured for the first time renders twice. Each title's full width is kept for the session too (titleTextWidths): a row showing a title already measured skips the hidden measuring copy and lays out oneText. - Reduced motion. Cards rest in place, titles stay tail-ellipsised, and the border's heads stay parked.
Entitlements
Purchases and ad-unlocks write through entitlements-actions.ts into UserLibraryManager (with dual-write to legacy PlayerData during migration). Catalog refreshes cannot revoke owned songs — delisted rows stay visible with delisted: true.
FTUE also grants free songs with acquire source "promo" (no rewarded ad):
- The tutorial gameplay song — unlocked by its catalog id as
TutorialGameplayScreenmounts (grantTutorialSong). - The song the player taps Get on the tutorial pick-song exit screen — unlocked in
TutorialPickSongScreenbeforependingPlaynavigation (script 1, and every public build). - The song the player taps Get on the Pick Your First Song screen (scripts 2, 3 and 4) — unlocked by
useChooseSongStore.pick. On the friendly arm (tutorial.free_songs3) every offered song is unlocked there; on the other arms (2) only the one picked. - The song the player taps Claim on the tutorial reward picker (
/(tutorial)/reward, the 2-free arms) — unlocked byuseRewardSongStore.claim, then played in full from the Song list. The song not claimed keeps its catalog lock (VIP, rewarded video, IAP).
All go through grantTutorialFreeSong → unlockSongEntitlement(..., "promo"), which flushes MMKV and best-effort syncs to Firestore when the user is signed in (guest library stays local-only). grantTutorialSong then refreshes the lock snapshot, so the Song list shows the song free without a remount.
Row CTAs — a rewarded video opens the mode it was watched from
Only where the ads arm says so (RC
mon_pkg, read by the monetization slice; see ad-trigger-logic.md) does a rewarded video open just the mode it was watched from: the arm'srv.per_mode, on inbalance, off infriendly(and so with no arm set) and the aggressive arms (final design, 10/11), and overridable per arm from the console.isRewardedUnlockPerMode()inrewarded-unlock-mode.tsasks the slice (setRewardedPerModeSource), and the Remote Config store's reading before the slice answers. Off,rewardedUnlockModenames no mode, so a video (earned or the no-fill courtesy) grants the song as before per-mode existed: a library record with nomodes, plus the legacy player record; and the unlock snapshot (mergeUnlockSnapshot) folds every one-mode record into both modes, so an install that leaves a per-mode arm loses nothing. The snapshot store re-reads once the slice has its arm and whenever the arm switches. The unlock sheet offers the video by the lock of the mode it was opened from (trackForMode), so after a Play video in a per-mode arm the Learn sheet still offers "Learn this song for free".
Two-video songs (var 2 / var 3)
mon_pkg rv.two_video_songs (PM 2026-11-11; [] until song-performance data picks songs)
lists rewarded-unlock songs that need two rewarded videos. Only aggressive (var 2) and
very_aggressive (var 3) read it (TwoVideoArmRules); every other arm needs one video and the
parser leaves a QA note. Each video (earned, or the no-fill courtesy; a video closed early does
not count) goes through runRewardedUnlock's countVideo →
useMonetizationStore.actions.countSongVideo → facade.countSongVideo, which keeps the count in
MMKV (monetization.rv2.<id>.<scope>, both since var 2/3 unlock both modes), so a player who
leaves at 1/2 needs one more next session. Video 1 grants nothing and opens nothing: the sheet
closes and the row reads 1/2; video 2 grants the song (unlockSongEntitlement) and opens it as a
one-video song does. The row's rewarded Play and Learn pills show the count on the video glyph
(VideoCounterIcon, "0/2" → "1/2", from rvVideoProgress / selectRvCounter via
buildSongRowViewModel's playAdCounter / learnAdCounter); a one-video song keeps the plain
glyph. The result-screen recommendation cards use the same flow but show no counter.
Each row carries a Learn slot and a Play slot, both precomputed in buildSongRowViewModel
(song-row-view-model.ts):
A paid row shows one CTA (PO, 27/10/2026): while its Play slot holds the gold Premium pill or
the IAP price pill, that pill is the only one on the row — no Learn, no "Coming soon", no lock
pill. The slot itself stays, empty, at the pills' width (learnSlotSpacer), so the difficulty and
stars sit in the same column as on every other row. Buying the song (the subscription, or that one song) clears its lock, and the slot comes
back by the rules above: Learn when the song ships a chart, Coming soon when it does not, the
grey lock pill while Learn Mode itself is still locked. The Song List row is the only way into a
locked song's Learn Mode — the result columns leave subscription-locked songs out — so Learn on
a paid song is now bought with it.
The other rows above describe the Learn slot once Learn Mode is open. While it is locked every charted free or rewarded row wears the lock pill, so the video offer waits behind it; "Coming soon" is unchanged.
resolveLearnCta (paid row → none; then no chart → comingSoon; then Learn Mode locked →
learnLocked; then the rules above) mirrors what the Play slot actually renders — including the
IAP buy pill displacing the video Play pill — and is the same helper SongsScreen.onPressLearn
calls, so the pill the player pressed and the flow that runs can never disagree.
On a rewarded row either CTA opens the same unlock sheet (PremiumUnlockModal) and defers
the same unlock_song rewarded placement to the sheet's onDismiss. Only the landing differs:
useRewardedSongUnlock's target carries a destination ("play" | "learn") that onUnlocked
hands back, and it is also the only mode the video opens:
unlockSongEntitlement(songId, …, "ads", rewardedUnlockMode(destination)).
- The library record keeps that mode (
OwnedSongRecord.modes,@piano/user-library), and the lock is asked per mode (getSongLockState(song, ctx, mode)). - The video clears the glyph from the CTA it was taken from only; the other mode asks for its own video, and a second video opens both.
- The no-fill courtesy unlock (no ad shown, song opened free) follows the same rule.
- A per-mode grant stays out of the legacy player record, which is read as owned in both modes.
- No
modesmeans both modes: every record written before this rule, purchases, VIP restores and tutorial gifts. Two devices' records combine their modes on sync, and both-mode wins.
The sheet's rewarded CTA is named after the CTA it was taken from ("Play this song for free" / "Learn this song for free"); its subtitle and glyph are identical.
Learn Mode's own result panel now honours the same offer. Its suggestion column is picked
and lock-enriched by the gameplay result's own hook
(useSessionResultSuggestions,
which useLearnResultSuggestions is a name over), so a locked ad-unlock pick wears the
video CTA there too, and both a card tap and the "Next song" pill run
useRewardedSongUnlock's unlockNow with the lit tab as the destination — no offer
sheet, because the panel is drawn in-tree and the ad can present straight away.
A locked song can no longer be opened from that panel without the video.
The panel itself is LearnResultPanel:
- Left column: the cup between the gameplay result's laurels, filled gold from the
bottom in ten steps by the Challenge's accuracy (
trophyFillFraction). Below it come the title, "Original by …", the difficulty chip and the accuracy counting up, drawn throughScoreFigureatcompact— a Skia canvas that follows the count-up on the UI thread, so the roll re-renders nothing. - Accuracy is the claimed notes over all the Challenge's notes
(
challenge-score.pure.ts). A right key inside a note's window claims it: ±150 ms on the phone's speaker, ±250 ms on headphones. A wrong key, a stray press and a note left untouched claim nothing, and a stray press takes nothing away. - Right column: the Learn/Play toggle over the suggestion list. Here the toggle opens on Learn.
- Action row: song list, retry and the "Next song" pill (
sessionResultNextTarget). - It is drawn through
LearnOverlayCard, never an RN<Modal>, so a rewarded ad can present over it. - It is drawn whole on the run's last frame (
revealHeld), so an interstitial closes onto a finished screen and nothing moves, sounds or logs until the ad is gone.
Learn Mode opens after four finished songs
Learn Mode is locked until the player's lifetime song_end count reaches 4. The tutorial song is
the first of the four, a replay counts, a song the player quits does not. The rule applies to
everyone, subscribers included, and never re-locks: the counter only grows.
The rule lives in src/core/learn-access/ because songs, piano,
tutorial and learn all read it:
LEARN_UNLOCK_SONG_ENDS(4) andisLearnUnlocked(songEnds).learnUnlockProgress(songEnds)→{ done, total }.totalis 3 — the songs after the tutorial one — anddone = clamp(songEnds − 1, 0, 3), so the bar starts moving at the second finished song.useLearnUnlocked()(a boolean, so a component re-renders at the flip, not after every song),useLearnSongEnds()(the count, for the progress bar — read only by the tooltip, while it is up) andgetLearnUnlocked()(a one-off read for callbacks). All three readuseEventCountStore.counts.song_end.
The Song List. SongsScreen reads only the boolean (useLearnUnlocked()) and hands it to
buildSongRowViewModel (learnUnlocked), so a finished song that leaves Learn locked re-renders
neither the screen nor a row. While it is locked the Learn slot of every charted free or rewarded
row is the grey pill (learnCta: "learnLocked"; a paid row's slot stays empty):
- Look. The same size as the Learn pill, see-through (
learnLockedPillFill), a lock icon and a muted "Learn" label. It is notdisabled; VoiceOver reads "Learn, locked. Finish 3 songs to unlock Learn mode." Rows with no chart keep "Coming soon". - Press.
SongsScreen.onPressLearnLockedstops the preview and opensLearnLockedTooltipat the pill's window box. Nosong_click, noselect_songinterstitial and no rewarded offer fire: no song was chosen. - Tooltip. "Learn mode is locked", "Finish 3 songs to unlock Learn mode." and a 3-segment bar
with "x/3" (
learnUnlockProgressofuseLearnSongEnds(), read by the tooltip itself). It sits above the pill, or below when there is no room above (learnLockedTooltipPlacement), kept 16 pt inside the window with the arrow following the pill. Its close target and card stand at layer 20 (zIndexandelevation), over the Song List header's 10, so a card near the top draws over the search and the dropdowns. It closes on a tap anywhere (its close target covers the list, so the list cannot scroll under it) or on its own after 3 s (LEARN_LOCKED_TOOLTIP_MS). One tooltip at a time.
The result screens. While locked the Game result and the tutorial result (both
SessionResultOverlay) draw no Learn/Play toggle — see the result columns.
The Learn result is only reachable once Learn is open and is unchanged.
The route. LearnModeScreen renders nothing for a locked player and sends them back once —
router.back(), or router.replace("/songs") when there is nothing to go back to — so a deep
link or a stale path cannot reach Learn past the pill and the tab (routing.md).
The unlock popup. The first time Learn opens, a "Learn Mode unlocked!" popup takes the player
straight into Twinkle Twinkle Little Star. LearnUnlockHost
is mounted in app/_layout.tsx, next to TutorialExitHost.
- Gate.
shouldShowLearnUnlockPopup(learn-unlock-popup.pure.ts): unlocked, not claimed, the player has never used Learn (hasUsedLearn: the first Learn lesson is not done and no song has a Learn progress record), the path is/songs, no screen cover is up (an ad, a paywall, a sheet, the splash), and the launch's App Open step is over (appOpenLaunchDone:useAppOpenLaunchStore.phase === "done"— see below). - Settle. It opens once the Song List has stood uncovered for 1 s (
LEARN_UNLOCK_SETTLE_MS), so a paywall about to open goes first. While visible it holds a screen cover of its own, so previews fall quiet. - App Open first. On a launch from #2 on, an AdMob App Open may go up over the Song List,
which can wait up to 5 s for the ad to load; a popup up meanwhile would cover the list and keep
the ad off it. So the popup waits for the launch's App Open step (shown, skipped, blocked or
failed — a launch with none is
doneat once, and a step that never started is markeddoneafter 15 s). The 1 s settle runs after that as before, so the launch paywall, released by the same step, still goes first. Rules: ad-trigger-logic.md §6. - Popup.
LearnUnlockedPopupis drawn in the tree onPopupOverlay(never an RNModal) over the sharedStarryScaffold(the tutorial's night sky), with a music badge, "Learn Mode unlocked!", "Learn your first melody in one minute!", a Claim pill and the scaffold's X in its corner (PO, 23/10/2026). - Claim. Marks
useLearnUnlockStoreclaimed (persisted, MMKVlearn-unlock), sends thesong_clickthe Learn pill sends (song_mode: "learn",song_play_type: "home"; no new events) and opens/learnfortwinkle-twinkle-little-starwithreveal=1— the song reveal plays, then Learn starts as usual. - X. Marks it claimed too, and only that: no
song_click, no trip into Learn. The popup closes for good, and Learn Mode stays unlocked for the player to play later from the songs. Only Claim or the X mark it claimed: leaving the Song List or killing the app with it up brings it back on the next visit. - Hand-off. The popup stays up from Claim until the path leaves
/songs(the navigation is queued and lands a commit after the press), and that/learnvisit opens in place (animation: "none",learnOpensWithReveal), so the popup goes the same commit the reveal arrives and the Song List never shows between them. Learn's body mounts after the reveal already arrived (useScreenEntered({ alreadyEntered })), so its countdown starts straight away. - Existing players. Anyone who has already used Learn never sees it, whatever their count.
The two result columns — one Learn/Play toggle
Once Learn Mode is open, both result screens end on the same column of suggestions under the same
segmented toggle (while it is locked, see below): Learn Mode's (LearnResultSuggestions)
and Game Mode's (SessionRecommendationList,
given tabs). The control is the shared
SegmentedToggle — the chassis Learn Mode's
stage 7 wrote for Practice/Challenge — and the rule behind it is
session-result-tab.ts, read by both so
the two columns cannot disagree about the same song.
The two halves list different songs. They used to list the same ones — the toggle changed
only where a tap went — which left the Learn half mostly full of disabled "Coming soon" cards,
because about a dozen catalog rows ship a learn chart. The Learn half is now narrowed to exactly
those rows (pickSessionResultSuggestions,
learnableOnly), so every card on it opens and the closed card state is gone from
SessionRecommendationCard altogether. The Play half is untouched on both screens: finishing a
Learn run does not change what is worth playing next. Both halves are picked up front, from one
gated catalog and one seed, and the column draws the lit one.
When a half runs thin. The Learn half runs SHORT rather than topping itself up — fewer than
five cards, and none at all once the player finishes the last song the catalog can teach. A
top-up is precisely what used to close half its cards, and two cards that both open offer more
than five where three do not. A half with nothing left keeps its toggle up over one line of copy
(sessionResultEmptyTabNote) instead of taking the column down with it, which would strand the
player on a half with no control left to leave by. The result's split layout is gated on
either half having cards, so moving the toggle never re-runs the gameplay result's reveal
sequence or re-measures its dock.
Select, then Next song. The cards carry no CTA of their own: a tap on a card's body selects
it (a 2 pt ring in songCardSelectedBorder) and plays its preview in place of whatever was
sounding — left playing when it already is (useSongPreview().play →
SongPreviewService.playUnlessAsked). A tap on its cover selects it too and toggles the
preview, so tapping the playing card's cover silences the result until another tap. The
"Next song" pill opens the selected song in the lit half's mode.
Only the selected song is heard. A result does not play its cards in turn (that is the
song list's queue). useSongPreviewLoop
plays the selected card's song 3 s after the column is seen (RESULT_PREVIEW_START_DELAY_MS,
uncovered time only), fading in over 2 s, and starts it again each time it reaches its end; a
tapped card replaces it and is then the one that loops. A paywall or popup silences it and it
comes back when the screen clears; an ad, the app going to the background, or opening a song
end it; switching the Learn/Play half starts a new visit on that half's top card. The rules are
preview-loop-controller.ts,
tested by driving it. The top card
is selected on arrival; a tap is remembered with the half it was made on, so switching halves
selects the new half's top card, and a selection the list no longer holds falls back to its top
card (resolveResultSelection / resultSelectionFor, held by
useResultSongSelection). Game
Mode's overlay holds it beside its tab; Learn Mode's screen holds it beside resultTab and hands
it to the panel, so the glyph the panel draws and the song the screen opens are one answer.
The primary CTA reads sessionResultNextTarget(tab, suggestions, selectedId), which takes
both lists and indexes them by the tab it reports back — so the pill cannot name a song the
lit half is not showing. song_order is the selected card's 1-based place in the column. The
same call says whether the pick is still behind a rewarded video, which is what puts the video
glyph on the pill, and it leaves the result when the lit half lists nothing. Each half reads the
lock of the mode it opens (trackForMode): the Play half Game Mode's, the Learn half Learn Mode's,
for its cards' glyph and its "free first" lift alike. In the balance arm (isRewardedUnlockPerMode),
a song a video opened for one mode is a plain card on that half and a video card on the other, and
a rewarded video taken from a tab opens the song in that tab's mode only. In every other arm the
video opens both modes, so the halves agree; either way the player who watched it lands in the tab's
mode.
Which tab each result opens on. Learn Mode's opens on Learn, Game Mode's on Play — each on the mode the player is already in, and Game Mode's default keeps its behaviour exactly as it shipped. Learn is the offer there, not the default.
While Learn Mode is locked
Until Learn Mode opens (above) the Game Mode result
and the tutorial result — both are SessionResultOverlay — offer only what the player can open:
- No toggle.
SessionResultOverlayhands the list notabs, so it draws the plain "Recommended for You" heading over the Play recommendations. - Play only.
shownTabis pinned toplaywhile locked, and the list, the selection, the preview loop'srestartKeyandsessionResultNextTargetall read it, so a stalelearntab can never reach them. "Next song" opens a Play song. - The layout gate reads only the Play list while locked, so Learn-only songs cannot open an empty column.
The Learn result needs no such rule: it is only reachable once Learn is open.
Which order each result draws them in. Game Mode's reads Play, then Learn; Learn Mode's
reads Learn, then Play — each leads with the mode the player is already in, which is also the
half it opens on. They are two named orders over ONE object per half
(GAMEPLAY_RESULT_TABS / LEARN_RESULT_TABS in
session-result-tab.ts), so the columns share
every label and testID and differ only in order, and neither can take its neighbour's by flipping
a shared array at its own call site. Nothing else reads the order: the lit fill is placed by
looking the lit mode up in the segments the toggle was handed, and each screen's opening tab is a
SessionResultTab value rather than an index, so both still open on the half they always did.
The heading is the toggle: a tabbed column drops "Recommended for You", because the tabs already
say what the column is and a landscape phone has no room for both. Both columns draw it at the
large size on every device — the owner asked them to match. That costs the banner-carrying
phone 10pt of column height over the control rail's compact (40 against 30, where the heading
it replaced was 22), which is inside one card's 80pt pitch, so the same cards clear the fold and
only the peek at the next one shortens. That phone still shrinks its cards' covers
(compact on SessionRecommendationList / SessionRecommendationCard).
The result's song card is a short row. The result column is narrower than the song book,
so on a phone the card keeps the list's type but drops to a 52 pt cover (48 with the banner,
compact) — 64 / 60 pt rows — wears the result header's DifficultyChip pill, and has no star
rating. Game Mode's column caps its scroll window to exactly three cards
(sessionRecommendationViewportHeight) and hangs an always-visible
ScrollRailIndicator in the
gutter to its right, since iOS fades its own indicator once a scroll settles and players missed
that the list scrolls. The iPad card is unchanged.
The toggle's halves keep a point of slack. Both halves wear the widest label's measured
width (segmentedToggleWidth), rounded up
to a whole point plus SEGMENT_CONTENT_SLACK. Without it, "Learn" could end up a pixel
narrower than its text, from a float reading a hair short plus Yoga's pixel rounding. That
happened on an iPhone 16e on iOS 18.3 and on the owner's iPhones. Picking the tab re-measured
the label in that box: it broke onto a second line, filled its half, and drew 7.5 points high.
Both headers name the song the same way: title, artist, then the difficulty chip
(DifficultyChip). The Learn result drew it first,
and the gameplay result's SessionSongMeta now wears the same chip under its artist.
Rewarded unlock no-fill
When a rewarded ad for song unlock has no inventory, the song is courtesy free-unlocked and a Skia video backfill (videoads_backfill analytics) plays; a sound toggle (top-left, audio on by default) and a Close button (top-right, after 15s) let the user control playback before continuing. The MP4 URL defaults from source (VIDEO_ADS_BACKFILL_URL) and can be updated live via Remote Config key video_ads_backfill_url. See AdsBackfillOverlay and runAdsBackfill.
Dev-synced charts
Songs added or overridden through the Piano DevTool play through the normal song list. Gameplay loads the synced MIDI first, then the bundled chart; the row preview of an overridden song still uses the bundled chart. Internal builds only (EXPO_PUBLIC_ENABLE_DESKTOP_TOOLS=1).