Skip to content

Instantly share code, notes, and snippets.

@mattmook
Last active August 3, 2021 14:44
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 mattmook/2599c405d3bab897163f67e5dd13592b to your computer and use it in GitHub Desktop.
Save mattmook/2599c405d3bab897163f67e5dd13592b to your computer and use it in GitHub Desktop.
val LazyListState.elevation: Dp
get() = if (firstVisibleItemIndex == 0) {
// For the first element, use the minimum of scroll offset and default elevation
// i.e. a value between 0 and 4.dp
minOf(firstVisibleItemScrollOffset.toFloat().dp, AppBarDefaults.TopAppBarElevation)
} else {
// If not the first element, always set elevation and show the shadow
AppBarDefaults.TopAppBarElevation
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment