Move OffsetOverscrollEffect and others to PlatformComposeCore (1/2)
Bug: 378470603
Test: atest OffsetOverscrollEffectTest
Flag: EXEMPT simple refactoring
Change-Id: Ic5b32111ae971a1962e61fdf35e766fbab2472f0
diff --git a/packages/SystemUI/compose/scene/src/com/android/compose/animation/scene/effect/ContentOverscrollEffect.kt b/packages/SystemUI/compose/core/src/com/android/compose/gesture/effect/ContentOverscrollEffect.kt
similarity index 98%
rename from packages/SystemUI/compose/scene/src/com/android/compose/animation/scene/effect/ContentOverscrollEffect.kt
rename to packages/SystemUI/compose/core/src/com/android/compose/gesture/effect/ContentOverscrollEffect.kt
index 2eeaa4a..4ee6db3 100644
--- a/packages/SystemUI/compose/scene/src/com/android/compose/animation/scene/effect/ContentOverscrollEffect.kt
+++ b/packages/SystemUI/compose/core/src/com/android/compose/gesture/effect/ContentOverscrollEffect.kt
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-package com.android.compose.animation.scene.effect
+package com.android.compose.gesture.effect
import androidx.compose.animation.core.Animatable
import androidx.compose.animation.core.AnimationSpec
diff --git a/packages/SystemUI/compose/scene/src/com/android/compose/animation/scene/effect/OffsetOverscrollEffect.kt b/packages/SystemUI/compose/core/src/com/android/compose/gesture/effect/OffsetOverscrollEffect.kt
similarity index 71%
rename from packages/SystemUI/compose/scene/src/com/android/compose/animation/scene/effect/OffsetOverscrollEffect.kt
rename to packages/SystemUI/compose/core/src/com/android/compose/gesture/effect/OffsetOverscrollEffect.kt
index f459c46..d992403 100644
--- a/packages/SystemUI/compose/scene/src/com/android/compose/animation/scene/effect/OffsetOverscrollEffect.kt
+++ b/packages/SystemUI/compose/core/src/com/android/compose/gesture/effect/OffsetOverscrollEffect.kt
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-package com.android.compose.animation.scene.effect
+package com.android.compose.gesture.effect
import androidx.annotation.VisibleForTesting
import androidx.compose.animation.core.AnimationSpec
@@ -34,7 +34,6 @@
import androidx.compose.ui.unit.Constraints
import androidx.compose.ui.unit.Density
import androidx.compose.ui.unit.dp
-import com.android.compose.animation.scene.ProgressConverter
import kotlin.math.roundToInt
import kotlinx.coroutines.CoroutineScope
@@ -80,7 +79,7 @@
)
@VisibleForTesting
- internal fun computeOffset(density: Density, overscrollDistance: Float): Int {
+ fun computeOffset(density: Density, overscrollDistance: Float): Int {
val maxDistancePx = with(density) { MaxDistance.toPx() }
val progress = ProgressConverter.Default.convert(overscrollDistance / maxDistancePx)
return (progress * maxDistancePx).roundToInt()
@@ -98,3 +97,35 @@
OffsetOverscrollEffect(orientation, animationScope, animationSpec)
}
}
+
+/** This converter lets you change a linear progress into a function of your choice. */
+fun interface ProgressConverter {
+ fun convert(progress: Float): Float
+
+ companion object {
+ /** Starts linearly with some resistance and slowly approaches to 0.2f */
+ val Default = tanh(maxProgress = 0.2f, tilt = 3f)
+
+ /**
+ * The scroll stays linear, with [factor] you can control how much resistance there is.
+ *
+ * @param factor If you choose a value between 0f and 1f, the progress will grow more
+ * slowly, like there's resistance. A value of 1f means there's no resistance.
+ */
+ fun linear(factor: Float = 1f) = ProgressConverter { it * factor }
+
+ /**
+ * This function starts linear and slowly approaches [maxProgress].
+ *
+ * See a [visual representation](https://www.desmos.com/calculator/usgvvf0z1u) of this
+ * function.
+ *
+ * @param maxProgress is the maximum progress value.
+ * @param tilt behaves similarly to the factor in the [linear] function, and allows you to
+ * control how quickly you get to the [maxProgress].
+ */
+ fun tanh(maxProgress: Float, tilt: Float = 1f) = ProgressConverter {
+ maxProgress * kotlin.math.tanh(x = it / (maxProgress * tilt))
+ }
+ }
+}
diff --git a/packages/SystemUI/compose/scene/src/com/android/compose/ui/util/SpaceVectorConverter.kt b/packages/SystemUI/compose/core/src/com/android/compose/ui/util/SpaceVectorConverter.kt
similarity index 100%
rename from packages/SystemUI/compose/scene/src/com/android/compose/ui/util/SpaceVectorConverter.kt
rename to packages/SystemUI/compose/core/src/com/android/compose/ui/util/SpaceVectorConverter.kt
diff --git a/packages/SystemUI/compose/scene/tests/src/com/android/compose/animation/scene/effect/OffsetOverscrollEffectTest.kt b/packages/SystemUI/compose/core/tests/src/com/android/compose/gesture/effect/OffsetOverscrollEffectTest.kt
similarity index 98%
rename from packages/SystemUI/compose/scene/tests/src/com/android/compose/animation/scene/effect/OffsetOverscrollEffectTest.kt
rename to packages/SystemUI/compose/core/tests/src/com/android/compose/gesture/effect/OffsetOverscrollEffectTest.kt
index da8fe30..5a3f240 100644
--- a/packages/SystemUI/compose/scene/tests/src/com/android/compose/animation/scene/effect/OffsetOverscrollEffectTest.kt
+++ b/packages/SystemUI/compose/core/tests/src/com/android/compose/gesture/effect/OffsetOverscrollEffectTest.kt
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-package com.android.compose.animation.scene.effect
+package com.android.compose.gesture.effect
import androidx.compose.foundation.gestures.Orientation
import androidx.compose.foundation.gestures.rememberScrollableState
diff --git a/packages/SystemUI/compose/features/src/com/android/systemui/shade/ui/composable/OverlayShade.kt b/packages/SystemUI/compose/features/src/com/android/systemui/shade/ui/composable/OverlayShade.kt
index cfbe667..ffdf509 100644
--- a/packages/SystemUI/compose/features/src/com/android/systemui/shade/ui/composable/OverlayShade.kt
+++ b/packages/SystemUI/compose/features/src/com/android/systemui/shade/ui/composable/OverlayShade.kt
@@ -58,7 +58,7 @@
import com.android.compose.animation.scene.ContentScope
import com.android.compose.animation.scene.ElementKey
import com.android.compose.animation.scene.LowestZIndexContentPicker
-import com.android.compose.animation.scene.effect.rememberOffsetOverscrollEffect
+import com.android.compose.gesture.effect.rememberOffsetOverscrollEffect
import com.android.compose.windowsizeclass.LocalWindowSizeClass
import com.android.systemui.res.R
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 7b30a2a..c704a3e 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
@@ -35,7 +35,7 @@
import androidx.compose.ui.unit.IntOffset
import androidx.compose.ui.unit.IntSize
import androidx.compose.ui.unit.LayoutDirection
-import com.android.compose.animation.scene.effect.ContentOverscrollEffect
+import com.android.compose.gesture.effect.ContentOverscrollEffect
/**
* [SceneTransitionLayout] is a container that automatically animates its content whenever its state
diff --git a/packages/SystemUI/compose/scene/src/com/android/compose/animation/scene/TransitionDsl.kt b/packages/SystemUI/compose/scene/src/com/android/compose/animation/scene/TransitionDsl.kt
index 8794df0..fda6fab 100644
--- a/packages/SystemUI/compose/scene/src/com/android/compose/animation/scene/TransitionDsl.kt
+++ b/packages/SystemUI/compose/scene/src/com/android/compose/animation/scene/TransitionDsl.kt
@@ -25,7 +25,6 @@
import androidx.compose.ui.unit.dp
import com.android.compose.animation.scene.content.state.TransitionState
import com.android.compose.animation.scene.transformation.Transformation
-import kotlin.math.tanh
/** Define the [transitions][SceneTransitions] to be used with a [SceneTransitionLayout]. */
fun transitions(builder: SceneTransitionsBuilder.() -> Unit): SceneTransitions {
@@ -476,35 +475,3 @@
/** Apply a [transformation] to the element(s) matching [matcher]. */
fun transformation(matcher: ElementMatcher, transformation: Transformation.Factory)
}
-
-/** This converter lets you change a linear progress into a function of your choice. */
-fun interface ProgressConverter {
- fun convert(progress: Float): Float
-
- companion object {
- /** Starts linearly with some resistance and slowly approaches to 0.2f */
- val Default = tanh(maxProgress = 0.2f, tilt = 3f)
-
- /**
- * The scroll stays linear, with [factor] you can control how much resistance there is.
- *
- * @param factor If you choose a value between 0f and 1f, the progress will grow more
- * slowly, like there's resistance. A value of 1f means there's no resistance.
- */
- fun linear(factor: Float = 1f) = ProgressConverter { it * factor }
-
- /**
- * This function starts linear and slowly approaches [maxProgress].
- *
- * See a [visual representation](https://www.desmos.com/calculator/usgvvf0z1u) of this
- * function.
- *
- * @param maxProgress is the maximum progress value.
- * @param tilt behaves similarly to the factor in the [linear] function, and allows you to
- * control how quickly you get to the [maxProgress].
- */
- fun tanh(maxProgress: Float, tilt: Float = 1f) = ProgressConverter {
- maxProgress * tanh(x = it / (maxProgress * tilt))
- }
- }
-}
diff --git a/packages/SystemUI/compose/scene/src/com/android/compose/animation/scene/content/Content.kt b/packages/SystemUI/compose/scene/src/com/android/compose/animation/scene/content/Content.kt
index 8c5a727..4c15f7a 100644
--- a/packages/SystemUI/compose/scene/src/com/android/compose/animation/scene/content/Content.kt
+++ b/packages/SystemUI/compose/scene/src/com/android/compose/animation/scene/content/Content.kt
@@ -53,10 +53,10 @@
import com.android.compose.animation.scene.ValueKey
import com.android.compose.animation.scene.animateSharedValueAsState
import com.android.compose.animation.scene.effect.GestureEffect
-import com.android.compose.animation.scene.effect.OffsetOverscrollEffect
import com.android.compose.animation.scene.effect.VisualEffect
import com.android.compose.animation.scene.element
import com.android.compose.animation.scene.modifiers.noResizeDuringTransitions
+import com.android.compose.gesture.effect.OffsetOverscrollEffect
import com.android.compose.modifiers.thenIf
import com.android.compose.ui.graphics.ContainerState
import com.android.compose.ui.graphics.container
diff --git a/packages/SystemUI/compose/scene/src/com/android/compose/animation/scene/effect/GestureEffect.kt b/packages/SystemUI/compose/scene/src/com/android/compose/animation/scene/effect/GestureEffect.kt
index dc3c16d..2db45aa 100644
--- a/packages/SystemUI/compose/scene/src/com/android/compose/animation/scene/effect/GestureEffect.kt
+++ b/packages/SystemUI/compose/scene/src/com/android/compose/animation/scene/effect/GestureEffect.kt
@@ -19,6 +19,7 @@
import androidx.compose.ui.geometry.Offset
import androidx.compose.ui.input.nestedscroll.NestedScrollSource
import androidx.compose.ui.unit.Velocity
+import com.android.compose.gesture.effect.ContentOverscrollEffect
/** An overscroll effect that ensures only a single fling animation is triggered. */
internal class GestureEffect(private val delegate: ContentOverscrollEffect) :
diff --git a/packages/SystemUI/compose/scene/tests/src/com/android/compose/animation/scene/ElementTest.kt b/packages/SystemUI/compose/scene/tests/src/com/android/compose/animation/scene/ElementTest.kt
index 6769032..53495be 100644
--- a/packages/SystemUI/compose/scene/tests/src/com/android/compose/animation/scene/ElementTest.kt
+++ b/packages/SystemUI/compose/scene/tests/src/com/android/compose/animation/scene/ElementTest.kt
@@ -70,8 +70,8 @@
import com.android.compose.animation.scene.TestScenes.SceneA
import com.android.compose.animation.scene.TestScenes.SceneB
import com.android.compose.animation.scene.TestScenes.SceneC
-import com.android.compose.animation.scene.effect.OffsetOverscrollEffect
import com.android.compose.animation.scene.subjects.assertThat
+import com.android.compose.gesture.effect.OffsetOverscrollEffect
import com.android.compose.test.assertSizeIsEqualTo
import com.android.compose.test.setContentAndCreateMainScope
import com.android.compose.test.transition