https://kotlinlang.org logo
#compose
Title
# compose
d

Deepak Gahlot

03/04/2021, 3:17 PM
Hello, I was using scrollToItem(int, int) inside the LazyColumn and it does scroll to the item but them it does not scroll to the offset
@Composable fun CardItem( { val state = rememberLazyListState() val modifierNoError = Modifier .fillMaxSize() .padding(bottom = 55.dp) val modifierError = Modifier .fillMaxSize() .padding(bottom = 95.dp) LazyColumn(modifier = if (eData > 0) modifierError else modifierNoError, state) { itemsIndexed(cards.value) { _, card -> ExpandableCard() } CoroutineScope(Dispatchers.Main).launch { state.scrollToItem(3, 800) } } }
Is it something i'm missing here ?
@cb any thoughts on this ?
c

cb

03/04/2021, 6:18 PM
You don't want to create
CoroutineScope
like that. Have a read through the docs: https://developer.android.com/jetpack/compose/lists#control-scroll-position
👍 1
If it's still not working after that, it sounds like a possible bug 🐛
Might be something to do with the item not being
800
pixels tall
a

Andrey Kulikov

03/04/2021, 6:49 PM
you basically want to set an initial scroll position, right? the correct way to do it is by passing them as a params to
rememberLazyListState()
function
👍 1
d

Deepak Gahlot

03/05/2021, 4:59 AM
Thank you all for your help.
16 Views