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

Commit 5fa13efc authored by Omar Miatello's avatar Omar Miatello
Browse files

Refactor: Rename `Empty` motion spec to `Identity` 1/2

This patch is a pure refactoring that renames `MotionSpec.Empty` to
`MotionSpec.Identity` and `DirectionalMotionSpec.Empty` to
`DirectionalMotionSpec.Identity`.

Rationale: The term **`Empty`** was semantically ambiguous. It could be
misinterpreted as a spec with no effect or no content.

The new name, **`Identity`**, more accurately describes the spec's
function: a direct, one-to-one mapping where the output value is always
identical to the input value (an identity function, where `f(x) = x`).

This change improves the clarity and discoverability of the API without
altering any underlying behavior.

Changes:
* Renamed `MotionSpec.Empty` to `MotionSpec.Identity`.
* Renamed `DirectionalMotionSpec.Empty` to `DirectionalMotionSpec
.Identity`.
* Updated all call sites across the library, including tests,
benchmarks, and sample applications, to use the new name.

Test: Existing tests were updated to reflect the name change.
Bug: 402113641
Flag: com.android.systemui.scene_container
Change-Id: I885f0f800a86ea844f73e438080aeac98a39e814
parent 2b309391
Loading
Loading
Loading
Loading
+4 −2
Original line number Diff line number Diff line
@@ -73,7 +73,7 @@ class MotionValueBenchmark {
    private fun testData(
        gestureContext: DistanceGestureContext = DistanceGestureContext(0f, InputDirection.Max, 2f),
        input: Float = 0f,
        spec: MotionSpec = MotionSpec.Empty,
        spec: MotionSpec = MotionSpec.Identity,
    ): TestData {
        val inputState = mutableFloatStateOf(input)
        return TestData(
@@ -91,7 +91,9 @@ class MotionValueBenchmark {
        val gestureContext = DistanceGestureContext(0f, InputDirection.Max, 2f)
        val input = { 0f }

        benchmarkRule.measureRepeated { MotionValue(input, gestureContext, { MotionSpec.Empty }) }
        benchmarkRule.measureRepeated {
            MotionValue(input, gestureContext, { MotionSpec.Identity })
        }
    }

    @Test
+4 −4
Original line number Diff line number Diff line
@@ -148,8 +148,8 @@ data class MotionSpec(
         */
        private val DefaultResetSpring = SpringParameters(stiffness = 1400f, dampingRatio = 1f)

        /* Empty motion spec, the output is the same as the input. */
        val Empty = MotionSpec(DirectionalMotionSpec.Empty)
        /* Identity motion spec, the output is the same as the input. */
        val Identity = MotionSpec(DirectionalMotionSpec.Identity)

        /**
         * Placeholder to indicate that a [MotionSpec] cannot be supplied yet.
@@ -254,8 +254,8 @@ data class DirectionalMotionSpec(
    override fun toString() = toDebugString()

    companion object {
        /* Empty spec, the full input domain is mapped to output using [Mapping.identity]. */
        val Empty =
        /* Identity spec, the full input domain is mapped to output using [Mapping.identity]. */
        val Identity =
            DirectionalMotionSpec(
                listOf(Breakpoint.minLimit, Breakpoint.maxLimit),
                listOf(Mapping.Identity),
+1 −1
Original line number Diff line number Diff line
@@ -49,7 +49,7 @@ class ViewMotionValue
constructor(
    initialInput: Float,
    gestureContext: ViewGestureContext,
    initialSpec: MotionSpec = MotionSpec.Empty,
    initialSpec: MotionSpec = MotionSpec.Identity,
    label: String? = null,
    stableThreshold: Float = StableThresholdEffect,
) : DisposableHandle {
+12 −9
Original line number Diff line number Diff line
@@ -72,7 +72,7 @@ class MotionValueTest : MotionBuilderContext by FakeMotionSpecBuilderContext.Def
    @Test
    fun emptySpec_outputMatchesInput_withoutAnimation() =
        motion.goldenTest(
            spec = MotionSpec.Empty,
            spec = MotionSpec.Identity,
            verifyTimeSeries = {
                // Output always matches the input
                assertThat(output).containsExactlyElementsIn(input).inOrder()
@@ -112,14 +112,14 @@ class MotionValueTest : MotionBuilderContext by FakeMotionSpecBuilderContext.Def
            },
        ) {
            animateValueTo(10f, changePerFrame = 5f)
            spec = MotionSpec.Empty
            spec = MotionSpec.Identity
            animateValueTo(20f, changePerFrame = 5f)
        }

    @Test
    fun unspecifiedSpec_onAlreadyInitializedValue_throws() {
        assertFailsWith<IllegalArgumentException> {
            motion.goldenTest(spec = MotionSpec.Empty) {
            motion.goldenTest(spec = MotionSpec.Identity) {
                animateValueTo(10f, changePerFrame = 5f)
                spec = MotionSpec.InitiallyUndefined
                animateValueTo(20f, changePerFrame = 5f)
@@ -529,7 +529,7 @@ class MotionValueTest : MotionBuilderContext by FakeMotionSpecBuilderContext.Def

    @Test
    fun semantics_returnsNullForUnknownKey() {
        val underTest = MotionValue({ 1f }, FakeGestureContext, { MotionSpec.Empty })
        val underTest = MotionValue({ 1f }, FakeGestureContext, { MotionSpec.Identity })

        val s1 = SemanticKey<String>("Foo")

@@ -575,7 +575,9 @@ class MotionValueTest : MotionBuilderContext by FakeMotionSpecBuilderContext.Def
        motion.goldenTest(
            spec = specBuilder(Mapping.Zero) { fixedValue(breakpoint = 0.5f, value = 1f) },
            createDerived = { primary ->
                listOf(MotionValue.createDerived(primary, { MotionSpec.Empty }, label = "derived"))
                listOf(
                    MotionValue.createDerived(primary, { MotionSpec.Identity }, label = "derived")
                )
            },
            verifyTimeSeries = {
                // the output of the derived value must match the primary value
@@ -634,7 +636,7 @@ class MotionValueTest : MotionBuilderContext by FakeMotionSpecBuilderContext.Def
    @Test
    fun nonFiniteNumbers_segmentChange_skipsAnimation() {
        motion.goldenTest(
            spec = MotionSpec.Empty,
            spec = MotionSpec.Identity,
            verifyTimeSeries = {
                // The mappings produce a non-finite number during a segment change.
                // The animation thereof is skipped to avoid poisoning the state with non-finite
@@ -684,7 +686,8 @@ class MotionValueTest : MotionBuilderContext by FakeMotionSpecBuilderContext.Def

    @Test
    fun keepRunning_concurrentInvocationThrows() = runMonotonicClockTest {
        val underTest = MotionValue({ 1f }, FakeGestureContext, { MotionSpec.Empty }, label = "Foo")
        val underTest =
            MotionValue({ 1f }, FakeGestureContext, { MotionSpec.Identity }, label = "Foo")
        val realJob = launch { underTest.keepRunning() }
        testScheduler.runCurrent()

@@ -702,7 +705,7 @@ class MotionValueTest : MotionBuilderContext by FakeMotionSpecBuilderContext.Def

    @Test
    fun debugInspector_sameInstance_whileInUse() {
        val underTest = MotionValue({ 1f }, FakeGestureContext, { MotionSpec.Empty })
        val underTest = MotionValue({ 1f }, FakeGestureContext, { MotionSpec.Identity })

        val originalInspector = underTest.debugInspector()
        assertThat(underTest.debugInspector()).isSameInstanceAs(originalInspector)
@@ -710,7 +713,7 @@ class MotionValueTest : MotionBuilderContext by FakeMotionSpecBuilderContext.Def

    @Test
    fun debugInspector_newInstance_afterUnused() {
        val underTest = MotionValue({ 1f }, FakeGestureContext, { MotionSpec.Empty })
        val underTest = MotionValue({ 1f }, FakeGestureContext, { MotionSpec.Identity })

        val originalInspector = underTest.debugInspector()
        originalInspector.dispose()
+3 −3
Original line number Diff line number Diff line
@@ -52,7 +52,7 @@ class MotionValueDebuggerTest {
            CompositionLocalProvider(LocalMotionValueDebugController provides debuggerState) {
                if (hasValue) {
                    val toDebug = remember {
                        MotionValue(input, gestureContext, { MotionSpec.Empty })
                        MotionValue(input, gestureContext, { MotionSpec.Identity })
                    }
                    Box(modifier = Modifier.debugMotionValue(toDebug))
                }
@@ -76,7 +76,7 @@ class MotionValueDebuggerTest {
            CompositionLocalProvider(LocalMotionValueDebugController provides debuggerState) {
                if (hasValue) {
                    val toDebug = remember {
                        MotionValue(input, gestureContext, { MotionSpec.Empty })
                        MotionValue(input, gestureContext, { MotionSpec.Identity })
                    }
                    Box(modifier = Modifier.debugMotionValue(toDebug))
                }
@@ -93,7 +93,7 @@ class MotionValueDebuggerTest {
    @Test
    fun debugMotionValue_noDebugger_isNoOp() {
        rule.setContent {
            val toDebug = remember { MotionValue(input, gestureContext, { MotionSpec.Empty }) }
            val toDebug = remember { MotionValue(input, gestureContext, { MotionSpec.Identity }) }
            Box(modifier = Modifier.debugMotionValue(toDebug))
        }
    }
Loading