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

Commit d8e73b5c authored by Mike Schneider's avatar Mike Schneider
Browse files

Fix semantics missing on segment non-`CanBeLastSegment` segments

To avoid the mistake in other places, merged `applySemantics` into
`toBreakpointImpl`

Bug: 383631946
Flag: com.android.wm.shell.enable_magnetic_split_divider
Test: DirectionalBuilderImplTest
Change-Id: Ibe0abf8c5f37f559e3b07a1c8feb985a396a46f2
parent 10145c11
Loading
Loading
Loading
Loading
+20 −29
Original line number Diff line number Diff line
@@ -102,12 +102,8 @@ internal open class DirectionalBuilderImpl(
            }
        }

        toBreakpointImpl(atPosition, key)
        toBreakpointImpl(atPosition, key, semantics)
        doAddBreakpointImpl(springSpec, guarantee)

        if (key != BreakpointKey.MaxLimit) {
            applySemantics(semantics)
        }
    }

    fun finalizeBuilderFn(breakpoint: Breakpoint) =
@@ -140,8 +136,7 @@ internal open class DirectionalBuilderImpl(
        key: BreakpointKey,
        semantics: List<SemanticValue<*>>,
    ) {
        applySemantics(semantics)
        toBreakpointImpl(breakpoint, key)
        toBreakpointImpl(breakpoint, key, semantics)
        jumpToImpl(from, spring, guarantee)
        continueWithTargetValueImpl(to)
    }
@@ -155,8 +150,7 @@ internal open class DirectionalBuilderImpl(
        key: BreakpointKey,
        semantics: List<SemanticValue<*>>,
    ) {
        applySemantics(semantics)
        toBreakpointImpl(breakpoint, key)
        toBreakpointImpl(breakpoint, key, semantics)
        jumpByImpl(delta, spring, guarantee)
        continueWithTargetValueImpl(to)
    }
@@ -170,8 +164,7 @@ internal open class DirectionalBuilderImpl(
        key: BreakpointKey,
        semantics: List<SemanticValue<*>>,
    ): CanBeLastSegment {
        applySemantics(semantics)
        toBreakpointImpl(breakpoint, key)
        toBreakpointImpl(breakpoint, key, semantics)
        jumpToImpl(from, spring, guarantee)
        continueWithFractionalInputImpl(fraction)
        return CanBeLastSegmentImpl
@@ -186,8 +179,7 @@ internal open class DirectionalBuilderImpl(
        key: BreakpointKey,
        semantics: List<SemanticValue<*>>,
    ): CanBeLastSegment {
        applySemantics(semantics)
        toBreakpointImpl(breakpoint, key)
        toBreakpointImpl(breakpoint, key, semantics)
        jumpByImpl(delta, spring, guarantee)
        continueWithFractionalInputImpl(fraction)
        return CanBeLastSegmentImpl
@@ -201,8 +193,7 @@ internal open class DirectionalBuilderImpl(
        key: BreakpointKey,
        semantics: List<SemanticValue<*>>,
    ): CanBeLastSegment {
        applySemantics(semantics)
        toBreakpointImpl(breakpoint, key)
        toBreakpointImpl(breakpoint, key, semantics)
        jumpToImpl(value, spring, guarantee)
        continueWithFixedValueImpl()
        return CanBeLastSegmentImpl
@@ -216,8 +207,7 @@ internal open class DirectionalBuilderImpl(
        key: BreakpointKey,
        semantics: List<SemanticValue<*>>,
    ): CanBeLastSegment {
        applySemantics(semantics)
        toBreakpointImpl(breakpoint, key)
        toBreakpointImpl(breakpoint, key, semantics)
        jumpByImpl(delta, spring, guarantee)
        continueWithFixedValueImpl()
        return CanBeLastSegmentImpl
@@ -231,21 +221,11 @@ internal open class DirectionalBuilderImpl(
        semantics: List<SemanticValue<*>>,
        mapping: Mapping,
    ): CanBeLastSegment {
        applySemantics(semantics)
        toBreakpointImpl(breakpoint, key)
        toBreakpointImpl(breakpoint, key, semantics)
        continueWithImpl(mapping, spring, guarantee)
        return CanBeLastSegmentImpl
    }

    private fun applySemantics(toApply: List<SemanticValue<*>>) {
        toApply.forEach { (key, value) ->
            getSemantics(key).apply {
                // applySemantics is called BEFORE adding the mapping
                set(mappings.size, value)
            }
        }
    }

    private fun continueWithTargetValueImpl(target: Float) {
        check(sourceValue.isFinite())

@@ -286,7 +266,11 @@ internal open class DirectionalBuilderImpl(
        mappings.add(mapping)
    }

    private fun toBreakpointImpl(atPosition: Float, key: BreakpointKey) {
    private fun toBreakpointImpl(
        atPosition: Float,
        key: BreakpointKey,
        semantics: List<SemanticValue<*>>,
    ) {
        check(breakpointPosition.isNaN())
        check(breakpointKey == null)

@@ -324,6 +308,13 @@ internal open class DirectionalBuilderImpl(

        breakpointPosition = atPosition
        breakpointKey = key

        semantics.forEach { (key, value) ->
            getSemantics(key).apply {
                // Last segment is guaranteed to be completed
                set(mappings.size, value)
            }
        }
    }

    private fun doAddBreakpointImpl(
+11 −0
Original line number Diff line number Diff line
@@ -254,6 +254,17 @@ class DirectionalBuilderImplTest {
        assertThat(result).semantics().withKey(S2).containsExactly("AAA", "BBB", "BBB").inOrder()
    }

    @Test
    fun directionalSpec_semantics_lateCompletedSegmentsRetainSemantics() {
        val result =
            directionalMotionSpec(Spring, semantics = listOf(S1 with "One")) {
                targetFromCurrent(breakpoint = 0f, to = 10f, semantics = listOf(S1 with "Two"))
                identity(breakpoint = 1f, semantics = listOf(S1 with "Three"))
            }
        assertThat(result).mappings().hasSize(3)
        assertThat(result).semantics().withKey(S1).containsExactly("One", "Two", "Three").inOrder()
    }

    @Test
    fun builderContext_spatialDirectionalMotionSpec_defaultsToSpatialSpringAndIdentityMapping() {
        val context = FakeMotionSpecBuilderContext.Default