Skip to content

Instantly share code, notes, and snippets.

@MrNtlu
Created December 12, 2022 14:11
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 MrNtlu/277782020ab7d10fc095c4d9f438c4e3 to your computer and use it in GitHub Desktop.
Save MrNtlu/277782020ab7d10fc095c4d9f438c4e3 to your computer and use it in GitHub Desktop.
@Composable
fun ExampleScreen(
sharedViewModel: SharedViewModel,
) {
val context = LocalContext.current
val listState = rememberLazyListState()
val expandedFabState = remember {
derivedStateOf {
listState.firstVisibleItemIndex == 0
}
}
LaunchedEffect(key1 = expandedFabState.value) {
sharedViewModel.expandedFab.value = expandedFabState.value
}
LaunchedEffect(key1 = Unit) {
sharedViewModel.fabOnClick.value = {
Toast.makeText(context, "Settings FAB Clicked", Toast.LENGTH_SHORT).show()
}
sharedViewModel.smallFabOnClick.value = {
Toast.makeText(context, "Settings Small FAB Clicked", Toast.LENGTH_SHORT).show()
}
}
LazyColumn(state = listState, modifier = Modifier.fillMaxSize()) {
for (index in 0 until 100) {
item {
Text(
text = "List item - $index",
modifier = Modifier.padding(24.dp)
)
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment