My tip of the day: There are a couple times in my ...
# storyboard
b
My tip of the day: There are a couple times in my stories where I want to animate the scroll position and I want it tied to the scene frame transition. For this, I'm using the following little Composable. Not sure it's the most optimal, due to dispatching the delta during composition, but it seems to work quite well.
Copy code
@Composable
fun <T> Transition<T>.animateScroll(
    scrollState: ScrollState,
    transitionSpec: @Composable Transition.Segment<T>.() -> FiniteAnimationSpec<Int> = { spring() },
    label: String = "ScrollAnimation",
    targetValueByState: @Composable (state: T) -> Int,
) {
    val scrollPosition by animateInt(transitionSpec, label, targetValueByState)
    scrollState.dispatchRawDelta((scrollPosition - scrollState.value).toFloat())
}