Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

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
Loading
Loading
Loading
Loading
+9 −8
Original line number Diff line number Diff line
@@ -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)
+2 −1
Original line number Diff line number Diff line
@@ -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(