Skip to content

Instantly share code, notes, and snippets.

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 saqib-github-commits/b1cc041bd63c0c3a328eb819c3a4764b to your computer and use it in GitHub Desktop.
Save saqib-github-commits/b1cc041bd63c0c3a328eb819c3a4764b to your computer and use it in GitHub Desktop.
@Composable
fun ScrollToTopDerivedAndRememberedCase(lazyListState: LazyListState) {
val isEnabledDerivedStateCase by remember { derivedStateOf { lazyListState.firstVisibleItemIndex > 0 }}
val isEnabledRememberCase = remember(lazyListState.firstVisibleItemIndex) { lazyListState.firstVisibleItemIndex > 0}
Column(
modifier = Modifier.fillMaxSize(),
verticalArrangement = Arrangement.Bottom,
horizontalAlignment = Alignment.CenterHorizontally
) {
Button(onClick = { /*TODO*/ }, enabled = isEnabledDerivedStateCase) {
Text(text = "Derived State Button")
}
Button(onClick = { /*TODO*/ }, enabled = isEnabledRememberCase) {
Text(text = "Remembered Button")
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment