Artur Schwarz
07/12/2021, 12:01 PMArtur Schwarz
07/12/2021, 12:02 PMArtur Schwarz
07/12/2021, 12:04 PMAndrey Kulikov
07/12/2021, 12:30 PMArtur Schwarz
07/12/2021, 12:32 PMAndrey Kulikov
07/12/2021, 12:36 PMcomposeView.setViewCompositionStrategy(ViewCompositionStrategy.DisposeOnViewTreeLifecycleDestroyed)
Artur Schwarz
07/12/2021, 12:37 PMArtur Schwarz
07/12/2021, 1:24 PMfun CameraRoll(
images: List<File>,
onImageClick: (File) -> Unit,
firstItemVisibleIndex: Int = 0,
onFirstItemVisibleIndexChanged: ((Int) -> Unit)
) {
val lazyListState = rememberLazyListState(firstItemVisibleIndex)
if (images.isNotEmpty()) {
LazyRow(
modifier = Modifier
.fillMaxSize(),
verticalAlignment = Alignment.CenterVertically,
state = lazyListState
) {
items(images) {
ImagePreview(
image = it,
onImageClick
)
}
}
DisposableEffect(lazyListState) {
onDispose {
onFirstItemVisibleIndexChanged.invoke(lazyListState.firstVisibleItemIndex)
}
}
} else {
NoContentInfo()
}
}
@Andrey Kulikov Here is some code. The firstItemVisibleIndex is given to the composable via field. In my case, when returning to Fragment A where the LazyRow is held, the firstItemVisibleIndex is 4 and still the LazyRows Scroll position is on the very first item (index 0)Artur Schwarz
07/12/2021, 1:24 PMArtur Schwarz
07/12/2021, 1:30 PMSideEffect {
scope.launch { lazyListState.scrollToItem(firstItemVisibleIndex) }
}
Even adding a SideEffect which explicitly scrolls the LazyRow to the firstItemVisibleIndex on each composition does not workAndrey Kulikov
07/12/2021, 1:32 PMArtur Schwarz
07/12/2021, 1:33 PMArtur Schwarz
07/12/2021, 1:34 PMfun CameraRoll(
images: List<File>,
onImageClick: (File) -> Unit
) {
if (images.isNotEmpty()) {
LazyRow(
modifier = Modifier
.fillMaxSize(),
verticalAlignment = Alignment.CenterVertically
) {
items(images) {
ImagePreview(
image = it,
onImageClick
)
}
}
} else {
NoContentInfo()
}
}
So basically: this should automatically restore the scroll position right? Well, no, it doesn’t, for some reasonAndrey Kulikov
07/12/2021, 1:38 PM