Created
March 19, 2023 19:51
-
-
Save Ahmad-Hamwi/4ef9b1839eae3f6998b732700529f1d8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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