Loading mechanics/src/com/android/mechanics/spec/builder/DirectionalBuilderImpl.kt +20 −29 Original line number Diff line number Diff line Loading @@ -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) = Loading Loading @@ -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) } Loading @@ -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) } Loading @@ -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 Loading @@ -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 Loading @@ -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 Loading @@ -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 Loading @@ -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()) Loading Loading @@ -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) Loading Loading @@ -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( Loading mechanics/tests/src/com/android/mechanics/spec/builder/DirectionalBuilderImplTest.kt +11 −0 Original line number Diff line number Diff line Loading @@ -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 Loading Loading
mechanics/src/com/android/mechanics/spec/builder/DirectionalBuilderImpl.kt +20 −29 Original line number Diff line number Diff line Loading @@ -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) = Loading Loading @@ -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) } Loading @@ -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) } Loading @@ -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 Loading @@ -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 Loading @@ -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 Loading @@ -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 Loading @@ -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()) Loading Loading @@ -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) Loading Loading @@ -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( Loading
mechanics/tests/src/com/android/mechanics/spec/builder/DirectionalBuilderImplTest.kt +11 −0 Original line number Diff line number Diff line Loading @@ -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 Loading