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

Commit 2ad4c0dc authored by Jordan Demeulenaere's avatar Jordan Demeulenaere
Browse files

Recompile STL sources when building tests

This CL works around b/240432457 by recompiling the sources of
PlatformComposeSceneTransitionLayout when compiling the associated tests
so that we can access internal members without polluting the public API.

Bug: 240432457
Test: atest PlatformComposeSceneTransitionLayoutTests
Flag: NA
Change-Id: I4ffceda155e836e360a2d8f562e2e3c43da8bbf0
parent ba469660
Loading
Loading
Loading
Loading
+8 −1
Original line number Diff line number Diff line
@@ -21,12 +21,19 @@ package {
    default_applicable_licenses: ["frameworks_base_packages_SystemUI_license"],
}

filegroup {
    name: "PlatformComposeSceneTransitionLayout-srcs",
    srcs: [
        "src/**/*.kt",
    ],
}

android_library {
    name: "PlatformComposeSceneTransitionLayout",
    manifest: "AndroidManifest.xml",

    srcs: [
        "src/**/*.kt",
        ":PlatformComposeSceneTransitionLayout-srcs",
    ],

    static_libs: [
+8 −2
Original line number Diff line number Diff line
@@ -43,7 +43,10 @@ class SceneKey(
    name: String,
    identity: Any = Object(),
) : Key(name, identity) {
    @VisibleForTesting val testTag: String = "scene:$name"
    @VisibleForTesting
    // TODO(b/240432457): Make internal once PlatformComposeSceneTransitionLayoutTestsUtils can
    // access internal members.
    val testTag: String = "scene:$name"

    /** The unique [ElementKey] identifying this scene's root element. */
    val rootElementKey = ElementKey(name, identity)
@@ -64,7 +67,10 @@ class ElementKey(
     */
    val isBackground: Boolean = false,
) : Key(name, identity), ElementMatcher {
    @VisibleForTesting val testTag: String = "element:$name"
    @VisibleForTesting
    // TODO(b/240432457): Make internal once PlatformComposeSceneTransitionLayoutTestsUtils can
    // access internal members.
    val testTag: String = "element:$name"

    override fun matches(key: ElementKey, scene: SceneKey): Boolean {
        return key == this
+5 −10
Original line number Diff line number Diff line
@@ -17,7 +17,6 @@
package com.android.compose.animation.scene

import android.util.Log
import androidx.annotation.VisibleForTesting
import androidx.compose.animation.core.Animatable
import androidx.compose.animation.core.Spring
import androidx.compose.animation.core.spring
@@ -37,8 +36,7 @@ import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Job
import kotlinx.coroutines.launch

@VisibleForTesting
class SceneGestureHandler(
internal class SceneGestureHandler(
    internal val layoutImpl: SceneTransitionLayoutImpl,
    internal val orientation: Orientation,
    private val coroutineScope: CoroutineScope,
@@ -63,12 +61,10 @@ class SceneGestureHandler(
    internal val currentScene: Scene
        get() = layoutImpl.scene(transitionState.currentScene)

    @VisibleForTesting
    val isDrivingTransition
    internal val isDrivingTransition
        get() = transitionState == swipeTransition

    @VisibleForTesting
    var isAnimatingOffset
    internal var isAnimatingOffset
        get() = swipeTransition.isAnimatingOffset
        private set(value) {
            swipeTransition.isAnimatingOffset = value
@@ -81,7 +77,7 @@ class SceneGestureHandler(
     * The velocity threshold at which the intent of the user is to swipe up or down. It is the same
     * as SwipeableV2Defaults.VelocityThreshold.
     */
    @VisibleForTesting val velocityThreshold = with(layoutImpl.density) { 125.dp.toPx() }
    internal val velocityThreshold = with(layoutImpl.density) { 125.dp.toPx() }

    /**
     * The positional threshold at which the intent of the user is to swipe to the next scene. It is
@@ -533,8 +529,7 @@ private class SceneDraggableHandler(
    }
}

@VisibleForTesting
class SceneNestedScrollHandler(
internal class SceneNestedScrollHandler(
    private val gestureHandler: SceneGestureHandler,
    private val startBehavior: NestedScrollBehavior,
    private val endBehavior: NestedScrollBehavior,
+2 −5
Original line number Diff line number Diff line
@@ -17,7 +17,6 @@
package com.android.compose.animation.scene

import androidx.activity.compose.BackHandler
import androidx.annotation.VisibleForTesting
import androidx.compose.foundation.gestures.Orientation
import androidx.compose.foundation.layout.Box
import androidx.compose.runtime.Composable
@@ -42,8 +41,7 @@ import com.android.compose.ui.util.lerp
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.channels.Channel

@VisibleForTesting
class SceneTransitionLayoutImpl(
internal class SceneTransitionLayoutImpl(
    onChangeScene: (SceneKey) -> Unit,
    builder: SceneTransitionLayoutScope.() -> Unit,
    transitions: SceneTransitions,
@@ -260,8 +258,7 @@ class SceneTransitionLayoutImpl(

    internal fun isSceneReady(scene: SceneKey): Boolean = readyScenes.containsKey(scene)

    @VisibleForTesting
    fun setScenesTargetSizeForTest(size: IntSize) {
    internal fun setScenesTargetSizeForTest(size: IntSize) {
        scenes.values.forEach { it.targetSize = size }
    }
}
+2 −4
Original line number Diff line number Diff line
@@ -16,7 +16,6 @@

package com.android.compose.animation.scene

import androidx.annotation.VisibleForTesting
import androidx.compose.animation.core.AnimationSpec
import androidx.compose.animation.core.snap
import androidx.compose.ui.geometry.Offset
@@ -38,12 +37,11 @@ import com.android.compose.animation.scene.transformation.Translate

/** The transitions configuration of a [SceneTransitionLayout]. */
class SceneTransitions(
    @get:VisibleForTesting val transitionSpecs: List<TransitionSpec>,
    internal val transitionSpecs: List<TransitionSpec>,
) {
    private val cache = mutableMapOf<SceneKey, MutableMap<SceneKey, TransitionSpec>>()

    @VisibleForTesting
    fun transitionSpec(from: SceneKey, to: SceneKey): TransitionSpec {
    internal fun transitionSpec(from: SceneKey, to: SceneKey): TransitionSpec {
        return cache.getOrPut(from) { mutableMapOf() }.getOrPut(to) { findSpec(from, to) }
    }

Loading