diff options
2 files changed, 11 insertions, 9 deletions
diff --git a/packages/SystemUI/compose/scene/src/com/android/compose/nestedscroll/LargeTopAppBarNestedScrollConnection.kt b/packages/SystemUI/compose/scene/src/com/android/compose/nestedscroll/LargeTopAppBarNestedScrollConnection.kt index 2c96d0e5402a..8e35988832dc 100644 --- a/packages/SystemUI/compose/scene/src/com/android/compose/nestedscroll/LargeTopAppBarNestedScrollConnection.kt +++ b/packages/SystemUI/compose/scene/src/com/android/compose/nestedscroll/LargeTopAppBarNestedScrollConnection.kt @@ -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) diff --git a/packages/SystemUI/compose/scene/tests/src/com/android/compose/nestedscroll/LargeTopAppBarNestedScrollConnectionTest.kt b/packages/SystemUI/compose/scene/tests/src/com/android/compose/nestedscroll/LargeTopAppBarNestedScrollConnectionTest.kt index e2974cddf1b9..ac7717b41a5a 100644 --- a/packages/SystemUI/compose/scene/tests/src/com/android/compose/nestedscroll/LargeTopAppBarNestedScrollConnectionTest.kt +++ b/packages/SystemUI/compose/scene/tests/src/com/android/compose/nestedscroll/LargeTopAppBarNestedScrollConnectionTest.kt @@ -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( |