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

Commit cb488d98 authored by omarmt's avatar omarmt
Browse files

STL improve large appbar demo experience

Simplifying overscroll logic in the demo by removing logic based on what
has already been consumed by descendants.

Test: Manually tested on a device, videos in b/378470603#comment15
Bug: 378470603
Flag: com.android.systemui.scene_container
Change-Id: I6dd489c41a6e102c5a0b90298764379162362be6
parent 9aca08b5
Loading
Loading
Loading
Loading
+2 −2
Original line number Original line Diff line number Diff line
@@ -48,8 +48,8 @@ fun LargeTopAppBarNestedScrollConnection(
        orientation = Orientation.Vertical,
        orientation = Orientation.Vertical,
        // When swiping up, the LargeTopAppBar will shrink (to [minHeight]) and the content will
        // When swiping up, the LargeTopAppBar will shrink (to [minHeight]) and the content will
        // expand. Then, you can then scroll down the content.
        // expand. Then, you can then scroll down the content.
        canStartPreScroll = { offsetAvailable, offsetBeforeStart, _ ->
        canStartPreScroll = { offsetAvailable, _, _ ->
            offsetAvailable < 0 && offsetBeforeStart == 0f && height() > minHeight()
            offsetAvailable < 0 && height() > minHeight()
        },
        },
        // When swiping down, the content will scroll up until it reaches the top. Then, the
        // When swiping down, the content will scroll up until it reaches the top. Then, the
        // LargeTopAppBar will expand until it reaches its [maxHeight].
        // LargeTopAppBar will expand until it reaches its [maxHeight].
+0 −35
Original line number Original line Diff line number Diff line
@@ -70,41 +70,6 @@ class LargeTopAppBarNestedScrollConnectionTest(testCase: TestCase) {
        assertThat(height).isEqualTo(0f)
        assertThat(height).isEqualTo(0f)
    }
    }


    @Test
    fun onScrollUpAfterContentScrolled_ignoreUpEvent() {
        val scrollConnection = buildScrollConnection(heightRange = 0f..2f)
        height = 1f

        // scroll down consumed by a child
        scrollConnection.scroll(available = Offset(0f, 1f), consumedByScroll = Offset(0f, 1f))

        val offsetConsumed =
            scrollConnection.onPreScroll(available = Offset(x = 0f, y = -1f), source = scrollSource)

        // It should ignore all onPreScroll events
        assertThat(offsetConsumed).isEqualTo(Offset.Zero)
        assertThat(height).isEqualTo(1f)
    }

    @Test
    fun onScrollUpAfterContentReturnedToZero_consumeHeight() {
        val scrollConnection = buildScrollConnection(heightRange = 0f..2f)
        height = 1f

        // scroll down consumed by a child
        scrollConnection.scroll(available = Offset(0f, 1f), consumedByScroll = Offset(0f, 1f))

        // scroll up consumed by a child, the child is in its original position
        scrollConnection.scroll(available = Offset(0f, -1f), consumedByScroll = Offset(0f, -1f))

        val offsetConsumed =
            scrollConnection.onPreScroll(available = Offset(x = 0f, y = -1f), source = scrollSource)

        // It should ignore all onPreScroll events
        assertThat(offsetConsumed).isEqualTo(Offset(0f, -1f))
        assertThat(height).isEqualTo(0f)
    }

    @Test
    @Test
    fun onScrollUp_consumeDownToMin() {
    fun onScrollUp_consumeDownToMin() {
        val scrollConnection = buildScrollConnection(heightRange = 0f..2f)
        val scrollConnection = buildScrollConnection(heightRange = 0f..2f)