rememberPlayheadFollow

fun rememberPlayheadFollow(position: () -> Duration, grid: StripGrid, state: LazyListState, isPlaying: Boolean, enabled: Boolean = true, sourceOffset: () -> Duration = { Duration.ZERO }): PlayheadFollow(source)

Keeps the playhead on screen while isPlaying, and gets out of the way once the user scrolls.

Following stops the moment a finger drags the strip and starts again when playback next starts, so watching and editing do not fight over the scroll position. The strip is only scrolled once the playhead leaves the middle of the viewport, which is what stops it jittering on every tick.

val follow = rememberPlayheadFollow(
position = playhead.positionProvider(),
grid = timeline.grid,
state = timeline.listState,
isPlaying = playerState.isPlaying,
)

Box(Modifier.height(FilmstripTimelineDefaults.StripHeight)) {
FilmstripStrip(frames = frames, grid = timeline.grid, state = timeline.listState)

if (!follow.isEngaged) {
IconButton(
onClick = follow::engage,
modifier = Modifier.align(Alignment.TopEnd),
) { Icon(Recentre, "Follow the playhead") }
}
}

Return

State keyed to state, the same instance across recompositions.

Parameters

position

Where the playhead sits, from PlayheadState.positionProvider or from whatever clock the host drives its own transport with.

grid

Where the tiles sit, which is what turns a source time into a scroll offset.

state

The strip's scroll state.

isPlaying

Whether the player is advancing, from PlayerState.isPlaying .

enabled

Whether the strip follows at all. False leaves the scroll position entirely to the host, and PlayheadFollow.isEngaged stays wherever it was put.

sourceOffset

Where the player's zero sits on the timeline's clock, so timelineTime == playerTime + sourceOffset() .