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

Commit 93747b75 authored by Jordan Demeulenaere's avatar Jordan Demeulenaere
Browse files

Make the transition DSL more opaque

This CL makes most of the classes in the transition DSL internal instead
of public.

In the past, the TransitionSpec's returned by the from() {} and to() {}
builders were used, but it's not the case anymore. By removing these
returned specs we can make most of the DSL classes internal.

Bug: 376438969
Test: atest PlatformComposeSceneTransitionLayoutTests
Flag: com.android.systemui.scene_container
Change-Id: I1b4e37b4c105d5f2253629ddd96fdfc0e96361fc
parent dc465643
Loading
Loading
Loading
Loading
+3 −3
Original line number Diff line number Diff line
@@ -169,7 +169,7 @@ internal constructor(
}

/** The definition of a transition between [from] and [to]. */
interface TransitionSpec {
internal interface TransitionSpec {
    /** The key of this [TransitionSpec]. */
    val key: TransitionKey?

@@ -209,7 +209,7 @@ interface TransitionSpec {
    fun previewTransformationSpec(transition: TransitionState.Transition): TransformationSpec?
}

interface TransformationSpec {
internal interface TransformationSpec {
    /**
     * The [AnimationSpec] used to animate the associated transition progress from `0` to `1` when
     * the transition is triggered (i.e. it is not gesture-based).
@@ -295,7 +295,7 @@ internal class TransitionSpecImpl(
}

/** The definition of the overscroll behavior of the [content]. */
interface OverscrollSpec {
internal interface OverscrollSpec {
    /** The scene we are over scrolling. */
    val content: ContentKey

+4 −4
Original line number Diff line number Diff line
@@ -76,7 +76,7 @@ interface SceneTransitionsBuilder {
        preview: (TransitionBuilder.() -> Unit)? = null,
        reversePreview: (TransitionBuilder.() -> Unit)? = null,
        builder: TransitionBuilder.() -> Unit = {},
    ): TransitionSpec
    )

    /**
     * Define the animation to be played when transitioning [from] the specified content. For the
@@ -102,7 +102,7 @@ interface SceneTransitionsBuilder {
        preview: (TransitionBuilder.() -> Unit)? = null,
        reversePreview: (TransitionBuilder.() -> Unit)? = null,
        builder: TransitionBuilder.() -> Unit = {},
    ): TransitionSpec
    )

    /**
     * Define the animation to be played when the [content] is overscrolled in the given
@@ -115,13 +115,13 @@ interface SceneTransitionsBuilder {
        content: ContentKey,
        orientation: Orientation,
        builder: OverscrollBuilder.() -> Unit,
    ): OverscrollSpec
    )

    /**
     * Prevents overscroll the [content] in the given [orientation], allowing ancestors to
     * eventually consume the remaining gesture.
     */
    fun overscrollDisabled(content: ContentKey, orientation: Orientation): OverscrollSpec
    fun overscrollDisabled(content: ContentKey, orientation: Orientation)
}

interface BaseTransitionBuilder : PropertyTransformationBuilder {
+8 −8
Original line number Diff line number Diff line
@@ -66,8 +66,8 @@ private class SceneTransitionsBuilderImpl : SceneTransitionsBuilder {
        preview: (TransitionBuilder.() -> Unit)?,
        reversePreview: (TransitionBuilder.() -> Unit)?,
        builder: TransitionBuilder.() -> Unit,
    ): TransitionSpec {
        return transition(from = null, to = to, key = key, preview, reversePreview, builder)
    ) {
        transition(from = null, to = to, key = key, preview, reversePreview, builder)
    }

    override fun from(
@@ -77,25 +77,25 @@ private class SceneTransitionsBuilderImpl : SceneTransitionsBuilder {
        preview: (TransitionBuilder.() -> Unit)?,
        reversePreview: (TransitionBuilder.() -> Unit)?,
        builder: TransitionBuilder.() -> Unit,
    ): TransitionSpec {
        return transition(from = from, to = to, key = key, preview, reversePreview, builder)
    ) {
        transition(from = from, to = to, key = key, preview, reversePreview, builder)
    }

    override fun overscroll(
        content: ContentKey,
        orientation: Orientation,
        builder: OverscrollBuilder.() -> Unit,
    ): OverscrollSpec {
    ) {
        val impl = OverscrollBuilderImpl().apply(builder)
        check(impl.transformationMatchers.isNotEmpty()) {
            "This method does not allow empty transformations. " +
                "Use overscrollDisabled($content, $orientation) instead."
        }
        return overscrollSpec(content, orientation, impl)
        overscrollSpec(content, orientation, impl)
    }

    override fun overscrollDisabled(content: ContentKey, orientation: Orientation): OverscrollSpec {
        return overscrollSpec(content, orientation, OverscrollBuilderImpl())
    override fun overscrollDisabled(content: ContentKey, orientation: Orientation) {
        overscrollSpec(content, orientation, OverscrollBuilderImpl())
    }

    private fun overscrollSpec(
+3 −3
Original line number Diff line number Diff line
@@ -133,14 +133,14 @@ interface PropertyTransformationScope : Density, ElementStateScope {
}

/** Defines the transformation-type to be applied to all elements matching [matcher]. */
class TransformationMatcher(
internal class TransformationMatcher(
    val matcher: ElementMatcher,
    val factory: Transformation.Factory,
    val range: TransformationRange?,
)

/** A pair consisting of a [transformation] and optional [range]. */
data class TransformationWithRange<out T : Transformation>(
internal data class TransformationWithRange<out T : Transformation>(
    val transformation: T,
    val range: TransformationRange?,
) {
@@ -152,7 +152,7 @@ data class TransformationWithRange<out T : Transformation>(
}

/** The progress-based range of a [PropertyTransformation]. */
data class TransformationRange(val start: Float, val end: Float, val easing: Easing) {
internal data class TransformationRange(val start: Float, val end: Float, val easing: Easing) {
    constructor(
        start: Float? = null,
        end: Float? = null,
+1 −1
Original line number Diff line number Diff line
@@ -157,7 +157,7 @@ abstract class BaseTransitionSubject<T : TransitionState.Transition>(
        check("isUserInputOngoing").that(actual.isUserInputOngoing).isEqualTo(isUserInputOngoing)
    }

    fun hasOverscrollSpec(): OverscrollSpec {
    internal fun hasOverscrollSpec(): OverscrollSpec {
        check("currentOverscrollSpec").that(actual.currentOverscrollSpec).isNotNull()
        return actual.currentOverscrollSpec!!
    }