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 Levi-Moreira/0e57643740006fccafd25ee7e7c42f07 to your computer and use it in GitHub Desktop.
Save Levi-Moreira/0e57643740006fccafd25ee7e7c42f07 to your computer and use it in GitHub Desktop.
private class CollapsingAppBarNestedScrollConnection(
val appBarMaxHeight: Int
) : NestedScrollConnection {
var appBarOffset: Int by mutableIntStateOf(0)
private set
override fun onPreScroll(available: Offset, source: NestedScrollSource): Offset {
val delta = available.y.toInt()
val newOffset = appBarOffset + delta
val previousOffset = appBarOffset
appBarOffset = newOffset.coerceIn(-appBarMaxHeight, 0)
val consumed = appBarOffset - previousOffset
return Offset(0f, consumed.toFloat())
}
}
@Yoke0
Copy link

Yoke0 commented Feb 19, 2024

When the scroll y is less than 1, it will be ignored.

Is this modification more reasonable?

val delta = available.y.let {
    if (it < 0) floor(it) else ceil(it)
}.toInt()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment