Skip to content

Instantly share code, notes, and snippets.

@Ahmad-Hamwi
Created March 19, 2023 19:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Ahmad-Hamwi/62726fbe94b1f058532c9ae92540dda1 to your computer and use it in GitHub Desktop.
Save Ahmad-Hamwi/62726fbe94b1f058532c9ae92540dda1 to your computer and use it in GitHub Desktop.
@Composable
fun TabSyncComposeScreen(categories: List<Category>) {
val (selectedTabIndex, setSelectedTabIndex, lazyListState) = tabSyncMediator(
mutableListOf(0, 2, 4), //Mandatory. The indices of lazy list items to sync the tabs with
tabsCount = 3, //Optional. To check for viability of the synchronization with the tabs. Optimal when equals the count of syncedIndices.
lazyListState = rememberLazyListState(), //Optional. To provide your own LazyListState. Defaults to rememberLazyListState().
smoothScroll = true, // Optional. To make the auto scroll smooth or not when clicking tabs. Defaults to true
)
Column {
MyTabBar(
categories = categories,
selectedTabIndex = selectedTabIndex,
onTabClicked = { index, _ -> setSelectedTabIndex(index) }
)
MyLazyList(categories, lazyListState)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment