New naming for NestedScrollBehavior
The new naming better reflects what happens when you have nested
scrolling.
If you make a scroll gesture that's partially consumed by the scrollable
and you reach the edge, there are 3 possible behaviors:
- EdgeNoPreview: you don't show the next scene
- EdgeWithPreview: you show a preview of the next scene
- EdgeAlways: you go directly to the next scene.
Test: atest SceneGestureHandlerTest
Bug: 291053278
Flag: NA
Change-Id: I38d24252386f2be338243810978cf781abb87470
diff --git a/packages/SystemUI/compose/scene/src/com/android/compose/animation/scene/NestedScrollToScene.kt b/packages/SystemUI/compose/scene/src/com/android/compose/animation/scene/NestedScrollToScene.kt
index 2986504..ded6cc1 100644
--- a/packages/SystemUI/compose/scene/src/com/android/compose/animation/scene/NestedScrollToScene.kt
+++ b/packages/SystemUI/compose/scene/src/com/android/compose/animation/scene/NestedScrollToScene.kt
@@ -44,22 +44,22 @@
* Overscroll will only be used by the [SceneTransitionLayout] to move to the next scene if the
* gesture begins at the edge of the scrollable component (so that a scroll in that direction
* can no longer be consumed). If the gesture is partially consumed by the scrollable component,
- * there will be NO overscroll effect between scenes.
+ * there will be NO preview of the next scene.
*
* In addition, during scene transitions, scroll events are consumed by the
* [SceneTransitionLayout] instead of the scrollable component.
*/
- EdgeNoOverscroll(canStartOnPostFling = false),
+ EdgeNoPreview(canStartOnPostFling = false),
/**
* Overscroll will only be used by the [SceneTransitionLayout] to move to the next scene if the
* gesture begins at the edge of the scrollable component. If the gesture is partially consumed
- * by the scrollable component, there will be an overscroll effect between scenes.
+ * by the scrollable component, there will be a preview of the next scene.
*
* In addition, during scene transitions, scroll events are consumed by the
* [SceneTransitionLayout] instead of the scrollable component.
*/
- EdgeWithOverscroll(canStartOnPostFling = true),
+ EdgeWithPreview(canStartOnPostFling = true),
/**
* Any overscroll will be used by the [SceneTransitionLayout] to move to the next scene.
@@ -67,7 +67,7 @@
* In addition, during scene transitions, scroll events are consumed by the
* [SceneTransitionLayout] instead of the scrollable component.
*/
- Always(canStartOnPostFling = true),
+ EdgeAlways(canStartOnPostFling = true),
}
internal fun Modifier.nestedScrollToScene(
diff --git a/packages/SystemUI/compose/scene/src/com/android/compose/animation/scene/SceneGestureHandler.kt b/packages/SystemUI/compose/scene/src/com/android/compose/animation/scene/SceneGestureHandler.kt
index b00c886..b38421a 100644
--- a/packages/SystemUI/compose/scene/src/com/android/compose/animation/scene/SceneGestureHandler.kt
+++ b/packages/SystemUI/compose/scene/src/com/android/compose/animation/scene/SceneGestureHandler.kt
@@ -612,15 +612,15 @@
canChangeScene = false // unused: added for consistency
false
}
- NestedScrollBehavior.EdgeNoOverscroll -> {
+ NestedScrollBehavior.EdgeNoPreview -> {
canChangeScene = isZeroOffset
isZeroOffset && hasNextScene(offsetAvailable)
}
- NestedScrollBehavior.EdgeWithOverscroll -> {
+ NestedScrollBehavior.EdgeWithPreview -> {
canChangeScene = isZeroOffset
hasNextScene(offsetAvailable)
}
- NestedScrollBehavior.Always -> {
+ NestedScrollBehavior.EdgeAlways -> {
canChangeScene = true
hasNextScene(offsetAvailable)
}
diff --git a/packages/SystemUI/compose/scene/src/com/android/compose/animation/scene/SceneTransitionLayout.kt b/packages/SystemUI/compose/scene/src/com/android/compose/animation/scene/SceneTransitionLayout.kt
index 07add77..afa184b 100644
--- a/packages/SystemUI/compose/scene/src/com/android/compose/animation/scene/SceneTransitionLayout.kt
+++ b/packages/SystemUI/compose/scene/src/com/android/compose/animation/scene/SceneTransitionLayout.kt
@@ -132,8 +132,8 @@
*/
fun Modifier.nestedScrollToScene(
orientation: Orientation,
- startBehavior: NestedScrollBehavior = NestedScrollBehavior.EdgeNoOverscroll,
- endBehavior: NestedScrollBehavior = NestedScrollBehavior.EdgeNoOverscroll,
+ startBehavior: NestedScrollBehavior = NestedScrollBehavior.EdgeNoPreview,
+ endBehavior: NestedScrollBehavior = NestedScrollBehavior.EdgeNoPreview,
): Modifier
/**
diff --git a/packages/SystemUI/compose/scene/tests/src/com/android/compose/animation/scene/SceneGestureHandlerTest.kt b/packages/SystemUI/compose/scene/tests/src/com/android/compose/animation/scene/SceneGestureHandlerTest.kt
index 49ef31b..317ba94 100644
--- a/packages/SystemUI/compose/scene/tests/src/com/android/compose/animation/scene/SceneGestureHandlerTest.kt
+++ b/packages/SystemUI/compose/scene/tests/src/com/android/compose/animation/scene/SceneGestureHandlerTest.kt
@@ -29,10 +29,10 @@
import androidx.compose.ui.unit.IntSize
import androidx.compose.ui.unit.Velocity
import androidx.test.ext.junit.runners.AndroidJUnit4
-import com.android.compose.animation.scene.NestedScrollBehavior.Always
import com.android.compose.animation.scene.NestedScrollBehavior.DuringTransitionBetweenScenes
-import com.android.compose.animation.scene.NestedScrollBehavior.EdgeNoOverscroll
-import com.android.compose.animation.scene.NestedScrollBehavior.EdgeWithOverscroll
+import com.android.compose.animation.scene.NestedScrollBehavior.EdgeAlways
+import com.android.compose.animation.scene.NestedScrollBehavior.EdgeNoPreview
+import com.android.compose.animation.scene.NestedScrollBehavior.EdgeWithPreview
import com.android.compose.animation.scene.TestScenes.SceneA
import com.android.compose.animation.scene.TestScenes.SceneB
import com.android.compose.animation.scene.TestScenes.SceneC
@@ -232,14 +232,14 @@
@Test
fun onInitialPreScroll_EdgeWithOverscroll_doNotChangeState() = runGestureTest {
- val nestedScroll = nestedScrollConnection(nestedScrollBehavior = EdgeWithOverscroll)
+ val nestedScroll = nestedScrollConnection(nestedScrollBehavior = EdgeWithPreview)
nestedScroll.onPreScroll(available = offsetY10, source = NestedScrollSource.Drag)
assertScene(currentScene = SceneA, isIdle = true)
}
@Test
fun onPostScrollWithNothingAvailable_EdgeWithOverscroll_doNotChangeState() = runGestureTest {
- val nestedScroll = nestedScrollConnection(nestedScrollBehavior = EdgeWithOverscroll)
+ val nestedScroll = nestedScrollConnection(nestedScrollBehavior = EdgeWithPreview)
val consumed =
nestedScroll.onPostScroll(
consumed = Offset.Zero,
@@ -253,7 +253,7 @@
@Test
fun onPostScrollWithSomethingAvailable_startSceneTransition() = runGestureTest {
- val nestedScroll = nestedScrollConnection(nestedScrollBehavior = EdgeWithOverscroll)
+ val nestedScroll = nestedScrollConnection(nestedScrollBehavior = EdgeWithPreview)
val consumed =
nestedScroll.onPostScroll(
consumed = Offset.Zero,
@@ -282,7 +282,7 @@
@Test
fun afterSceneTransitionIsStarted_interceptPreScrollEvents() = runGestureTest {
- val nestedScroll = nestedScrollConnection(nestedScrollBehavior = EdgeWithOverscroll)
+ val nestedScroll = nestedScrollConnection(nestedScrollBehavior = EdgeWithPreview)
nestedScroll.scroll(available = offsetY10)
assertScene(currentScene = SceneA, isIdle = false)
@@ -310,7 +310,7 @@
firstScroll: Float,
secondScroll: Float
) {
- val nestedScroll = nestedScrollConnection(nestedScrollBehavior = EdgeWithOverscroll)
+ val nestedScroll = nestedScrollConnection(nestedScrollBehavior = EdgeWithPreview)
// start scene transition
nestedScroll.scroll(available = Offset(0f, SCREEN_SIZE * firstScroll))
@@ -366,7 +366,7 @@
@Test
fun onPreFling_velocityLowerThanThreshold_remainSameScene() = runGestureTest {
- val nestedScroll = nestedScrollConnection(nestedScrollBehavior = EdgeWithOverscroll)
+ val nestedScroll = nestedScrollConnection(nestedScrollBehavior = EdgeWithPreview)
nestedScroll.scroll(available = offsetY10)
assertScene(currentScene = SceneA, isIdle = false)
@@ -398,7 +398,7 @@
@Test
fun flingAfterScroll_EdgeNoOverscroll_goToNextScene() = runGestureTest {
- flingAfterScroll(use = EdgeNoOverscroll, idleAfterScroll = false)
+ flingAfterScroll(use = EdgeNoPreview, idleAfterScroll = false)
assertScene(currentScene = SceneC, isIdle = false)
@@ -409,7 +409,7 @@
@Test
fun flingAfterScroll_EdgeWithOverscroll_goToNextScene() = runGestureTest {
- flingAfterScroll(use = EdgeWithOverscroll, idleAfterScroll = false)
+ flingAfterScroll(use = EdgeWithPreview, idleAfterScroll = false)
assertScene(currentScene = SceneC, isIdle = false)
@@ -420,7 +420,7 @@
@Test
fun flingAfterScroll_Always_goToNextScene() = runGestureTest {
- flingAfterScroll(use = Always, idleAfterScroll = false)
+ flingAfterScroll(use = EdgeAlways, idleAfterScroll = false)
assertScene(currentScene = SceneC, isIdle = false)
@@ -454,14 +454,14 @@
@Test
fun flingAfterScrollStartedInScene_EdgeNoOverscroll_doNothing() = runGestureTest {
- flingAfterScrollStartedInScene(use = EdgeNoOverscroll, idleAfterScroll = true)
+ flingAfterScrollStartedInScene(use = EdgeNoPreview, idleAfterScroll = true)
assertScene(currentScene = SceneA, isIdle = true)
}
@Test
fun flingAfterScrollStartedInScene_EdgeWithOverscroll_doOverscrollAnimation() = runGestureTest {
- flingAfterScrollStartedInScene(use = EdgeWithOverscroll, idleAfterScroll = false)
+ flingAfterScrollStartedInScene(use = EdgeWithPreview, idleAfterScroll = false)
assertScene(currentScene = SceneA, isIdle = false)
@@ -472,7 +472,7 @@
@Test
fun flingAfterScrollStartedInScene_Always_goToNextScene() = runGestureTest {
- flingAfterScrollStartedInScene(use = Always, idleAfterScroll = false)
+ flingAfterScrollStartedInScene(use = EdgeAlways, idleAfterScroll = false)
assertScene(currentScene = SceneC, isIdle = false)
@@ -495,14 +495,14 @@
@Test
fun beforeNestedScrollStart_stop_shouldBeIgnored() = runGestureTest {
- val nestedScroll = nestedScrollConnection(nestedScrollBehavior = EdgeWithOverscroll)
+ val nestedScroll = nestedScrollConnection(nestedScrollBehavior = EdgeWithPreview)
nestedScroll.onPreFling(Velocity(0f, velocityThreshold))
assertScene(currentScene = SceneA, isIdle = true)
}
@Test
fun startNestedScrollWhileDragging() = runGestureTest {
- val nestedScroll = nestedScrollConnection(nestedScrollBehavior = Always)
+ val nestedScroll = nestedScrollConnection(nestedScrollBehavior = EdgeAlways)
draggable.onDragStarted()
assertScene(currentScene = SceneA, isIdle = false)