Skip to content

Instantly share code, notes, and snippets.

@Ahmad-Hamwi
Created March 19, 2023 19:51
Show Gist options
  • Save Ahmad-Hamwi/4ef9b1839eae3f6998b732700529f1d8 to your computer and use it in GitHub Desktop.
Save Ahmad-Hamwi/4ef9b1839eae3f6998b732700529f1d8 to your computer and use it in GitHub Desktop.
@Composable
fun lazyListTabSync(...): TabSyncState {
...
LaunchedEffect(lazyListState) {
snapshotFlow { lazyListState.layoutInfo }.collect {
var itemPosition = lazyListState.findFirstFullyVisibleItemIndex()
if (itemPosition == -1) {
itemPosition = lazyListState.firstVisibleItemIndex
}
if (itemPosition == -1) {
return@collect
}
if (lazyListState.findLastFullyVisibleItemIndex() == syncedIndices.last()) {
itemPosition = syncedIndices.last()
}
if (syncedIndices.contains(itemPosition) && itemPosition != syncedIndices[selectedTabIndex]) {
selectedTabIndex = syncedIndices.indexOf(itemPosition)
}
}
}
...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment