Documentation comes from this release commit, without inheriting newer content. Commit: 63ea8c2b3d.
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
Route: app/(app)/(tabs)/songs.tsx (or equivalent tab route).
Lock resolution
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 SongsScreen via buildSongRowViewModel before FlatList 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. Callbacks are never compared, so a row keeps the ones of its first render: SongsScreen hands every row the stable forwarders from createSongListRowCallbacks, which run the latest render's handlers at the tap (kept in a ref written in an effect). A tap's song_click (song_unlock_type, song_order) and the play guard's isPlayable therefore read the current lock state, owned sources, list order and catalog, never the ones the row was first rendered with.
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 getItemLayout's uniform rows. 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.
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 (useAnimatedScrollHandler) 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 asgetItemLayout. 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 dims to 0.5 when it leaves view (below 10% showing) and brightens when it returns. 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. - 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 when its catalog row loads on
TutorialGameplayScreen. - The song the player taps Get on the tutorial pick-song exit screen — unlocked in
TutorialPickSongScreenbeforependingPlaynavigation (script 1, and every public build). - Every song on the Choose your first song screen (scripts 2 and 3) — unlocked in
TutorialChooseSongScreenas it opens, the chosen one and the others alike.
Both 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).
Row CTAs — a rewarded video opens the mode it was watched from
Temporarily, one rewarded video opens BOTH modes of the song again. The per-mode rule below is kept whole behind one code constant,
REWARDED_UNLOCK_PER_MODEinrewarded-unlock-mode.ts, which isfalsefor now. Off,rewardedUnlockModenames no mode, so a video (earned or the no-fill courtesy) grants the song exactly as before per-mode existed: a library record with nomodes, plus the legacy player record. On the read sideusePlayerUnlockSnapshotpasses the lock context throughfoldOneModeUnlocks, which reads every one-mode record a per-mode build stored as open in both modes — so the Play and Learn pills, the Learn video glyph, the result cards, their "free first" lift and the Next-song glyph all agree. Flip the constant totrueto bring back the behaviour the rest of this section describes; nothing else changes.
Each row carries a Learn slot and a Play slot, both precomputed in buildSongRowViewModel
(SongRow.utils.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. - 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. With REWARDED_UNLOCK_PER_MODE on, 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. Off (for now), 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).