Hello, I'm trying to scroll a LazyColumn to a spec...
# compose
s
Hello, I'm trying to scroll a LazyColumn to a specific index and offset using Launched Effect. Is this safe or could there be timing issue where request to scroll is processed earlier than the layout/draw phase?
Copy code
@Composable
private fun ScrollableList(
    items: List<Int>,
    scrollTo: Int,
    scrollToOffset: Int,
    modifier: Modifier = Modifier
) {
    val state = rememberLazyListState()

    // Can this happen before list's layout/draw?
    LaunchedEffect(state, scrollTo) {
        state.scrollToItem(scrollTo, scrollToOffset)
    }

    LazyColumn(
        state = state,
        modifier = modifier.fillMaxSize(),
        horizontalAlignment = Alignment.CenterHorizontally
    ) {
      ...
    }
}
s
LaunchedEffect anyway launches a coroutine which will only start doing its work after the next frame according to https://kotlinlang.slack.com/archives/CJLTWPH7S/p1622560036078600?thread_ts=1622556885.065600&amp;cid=CJLTWPH7S So it should never try to run before there was full frame drawn to the UI. I feel like with that assumption in mind, this should be safe to do.
👍 2