Skip to content
Snippets Groups Projects
Commit d9d1cada authored by Jordan Demeulenaere's avatar Jordan Demeulenaere Committed by Android (Google) Code Review
Browse files

Merge "Clean-up the STL demo shade implementation (2/2)" into main

parents 7eab624a 5b9efe5a
No related branches found
No related tags found
No related merge requests found
......@@ -36,24 +36,25 @@ import androidx.compose.ui.input.nestedscroll.NestedScrollConnection
fun LargeTopAppBarNestedScrollConnection(
height: () -> Float,
onHeightChanged: (Float) -> Unit,
heightRange: ClosedFloatingPointRange<Float>,
minHeight: () -> Float,
maxHeight: () -> Float,
): PriorityNestedScrollConnection {
val minHeight = heightRange.start
val maxHeight = heightRange.endInclusive
return PriorityNestedScrollConnection(
orientation = Orientation.Vertical,
// When swiping up, the LargeTopAppBar will shrink (to [minHeight]) and the content will
// expand. Then, you can then scroll down the content.
canStartPreScroll = { offsetAvailable, offsetBeforeStart ->
offsetAvailable < 0 && offsetBeforeStart == 0f && height() > minHeight
offsetAvailable < 0 && offsetBeforeStart == 0f && height() > minHeight()
},
// When swiping down, the content will scroll up until it reaches the top. Then, the
// LargeTopAppBar will expand until it reaches its [maxHeight].
canStartPostScroll = { offsetAvailable, _ -> offsetAvailable > 0 && height() < maxHeight },
canStartPostScroll = { offsetAvailable, _ ->
offsetAvailable > 0 && height() < maxHeight()
},
canStartPostFling = { false },
canContinueScroll = {
val currentHeight = height()
minHeight < currentHeight && currentHeight < maxHeight
minHeight() < currentHeight && currentHeight < maxHeight()
},
canScrollOnFling = true,
onStart = { /* do nothing */},
......@@ -61,10 +62,10 @@ fun LargeTopAppBarNestedScrollConnection(
val currentHeight = height()
val amountConsumed =
if (offsetAvailable > 0) {
val amountLeft = maxHeight - currentHeight
val amountLeft = maxHeight() - currentHeight
offsetAvailable.coerceAtMost(amountLeft)
} else {
val amountLeft = minHeight - currentHeight
val amountLeft = minHeight() - currentHeight
offsetAvailable.coerceAtLeast(amountLeft)
}
onHeightChanged(currentHeight + amountConsumed)
......
......@@ -34,7 +34,8 @@ class LargeTopAppBarNestedScrollConnectionTest(testCase: TestCase) {
LargeTopAppBarNestedScrollConnection(
height = { height },
onHeightChanged = { height = it },
heightRange = heightRange,
minHeight = { heightRange.start },
maxHeight = { heightRange.endInclusive },
)
private fun NestedScrollConnection.scroll(
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment