summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Jordan Demeulenaere <jdemeulenaere@google.com> 2024-01-18 14:10:07 +0100
committer Jordan Demeulenaere <jdemeulenaere@google.com> 2024-01-18 14:10:26 +0100
commit5b9efe5a94a94f63152cfc2b8e38aaed35d682c8 (patch)
tree1789af5323d333147221c3219114d0e515369af0
parentc294bbc630d332e1b28c34909952e65d0d176b9a (diff)
Clean-up the STL demo shade implementation (2/2)
Bug: 308961608 Test: Manual, transitioned to Shade from Lockscreen and Launcher in the STL demo app. Flag: N/A Change-Id: Ib4f7d8c3ed425850d98000f60a724cb45ab860b1
-rw-r--r--packages/SystemUI/compose/scene/src/com/android/compose/nestedscroll/LargeTopAppBarNestedScrollConnection.kt17
-rw-r--r--packages/SystemUI/compose/scene/tests/src/com/android/compose/nestedscroll/LargeTopAppBarNestedScrollConnectionTest.kt3
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(