Documentation Index
Fetch the complete documentation index at: https://mintlify.com/6xingyv/accompanist-lyrics-ui/llms.txt
Use this file to discover all available pages before exploring further.
springPlacement is a custom Modifier extension that animates a composable to its target position using spring physics, without interfering with Compose’s layout measurement pass. It is used inside KaraokeLyricsView to give each lyric row a fluid, physically motivated motion as the active line scrolls and surrounding rows reposition themselves.
Function signature
Parameters
The enclosing
LookaheadScope provided by the LookaheadScope { } block in KaraokeLyricsView. springPlacement uses this scope to query the item’s lookahead (future) position — the position Compose has already computed for the next frame — so it can interpolate the current visual position toward that target without re-triggering layout.A unique, stable key for this item — typically the lyric line’s index or ID. When
itemKey changes, the DeferredTargetAnimation is reset and the isFirstFrame flag is set back to true, causing the next frame to snap immediately rather than animate from the old position.Pass
true while the user is actively dragging the scroll container. When true, the modifier uses a snap() animation spec instead of spring(), so the item moves with the user’s finger without any lag or overshoot that would fight the gesture.The stiffness constant of the spring. Higher values produce a snappier, less springy motion; lower values produce a looser, more elastic feel.
This creates a wave-like ripple effect where nearby rows react quickly while farther rows trail behind.
KaraokeLyricsView uses differentiated stiffness values depending on a row’s distance from the focused (active) line:| Distance from active line | Suggested stiffness |
|---|---|
| Active / adjacent row | 120f |
| Distant rows | Down to 20f |
Behaviour
The modifier is implemented as anApproachLayoutModifierNode backed by a DeferredTargetAnimation<IntOffset>. On each frame:
isPlacementApproachInProgresscomputes the lookahead target position and feeds it to the animation. Returnstrue(telling Compose to keep animating) whileoffsetAnimation.isIdle == false.approachMeasureplaces the composable at the animated offset rather than the lookahead offset, creating the smooth visual interpolation.
First-frame snap
On the very first frame after composition (or afteritemKey changes), the modifier uses snap() regardless of isManualScrolling. This prevents the jarring effect of an item appearing to fly in from Offset.Zero when it is first added to the layout.
Spring parameters
| Parameter | Value |
|---|---|
dampingRatio | 0.95f (highly damped — minimal overshoot) |
stiffness | Variable per row (see table above) |
Implementation classes
The publicspringPlacement function is a thin wrapper over two internal types:
stiffness value as the active line changes), SpringPlacementNodeElement.update() calls node.updateState(), which updates the parameters in place without recreating the node or resetting the animation — unless itemKey has changed.
Usage example
ApproachLayoutModifierNode and DeferredTargetAnimation are marked @ExperimentalAnimatableApi in Compose. The library applies the corresponding opt-in annotation internally, but if you reference SpringPlacementModifierNode directly in your own code you will need to add @OptIn(ExperimentalAnimatableApi::class) to your call site.