Last active
February 19, 2024 08:42
-
-
Save Levi-Moreira/0e57643740006fccafd25ee7e7c42f07 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
When the scroll y is less than 1, it will be ignored.
Is this modification more reasonable?