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

Commit 95b9a3b7 authored by William Xiao's avatar William Xiao
Browse files

Only listen to edge swipes to/from hub mode

This makes SceneTransitionLayout only listen to swipes from the right
edge when transitioning to hub mode and left edge when leaving.

A blank spacer is added above the LazyHorizontalGrid in order to block
touches so that the SceneTransitionLayout can receive them.

Unfortunately this doesn't automatically allow other inputs to pass
through so bouncer swipe still doesn't work.

Flag: ACONFIG com.android.systemui.communal_hub DEVELOPMENT
Bug: 308813166
Test: manually tested on device
Change-Id: I9176c297f78417422ee84af2e64114a8a32e81e5
parent 7d0c9340
Loading
Loading
Loading
Loading
+16 −6
Original line number Diff line number Diff line
@@ -12,7 +12,6 @@ import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Close
import androidx.compose.material3.Icon
import androidx.compose.material3.IconButton
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue
@@ -25,10 +24,12 @@ import androidx.compose.ui.graphics.Color
import androidx.compose.ui.unit.dp
import com.android.compose.animation.scene.Edge
import com.android.compose.animation.scene.ElementKey
import com.android.compose.animation.scene.FixedSizeEdgeDetector
import com.android.compose.animation.scene.SceneKey
import com.android.compose.animation.scene.SceneScope
import com.android.compose.animation.scene.SceneTransitionLayout
import com.android.compose.animation.scene.Swipe
import com.android.compose.animation.scene.SwipeDirection
import com.android.compose.animation.scene.transitions
import com.android.systemui.communal.shared.model.CommunalSceneKey
import com.android.systemui.communal.ui.viewmodel.CommunalViewModel
@@ -76,17 +77,24 @@ fun CommunalContainer(
        currentScene = currentScene,
        onChangeScene = { sceneKey -> viewModel.onSceneChanged(sceneKey.toCommunalSceneKey()) },
        transitions = sceneTransitions,
        edgeDetector = FixedSizeEdgeDetector(ContainerDimensions.EdgeSwipeSize)
    ) {
        scene(
            TransitionSceneKey.Blank,
            userActions = mapOf(Swipe.Left to TransitionSceneKey.Communal)
            userActions =
                mapOf(
                    Swipe(SwipeDirection.Left, fromEdge = Edge.Right) to TransitionSceneKey.Communal
                )
        ) {
            BlankScene { showSceneTransitionLayout = false }
        }

        scene(
            TransitionSceneKey.Communal,
            userActions = mapOf(Swipe.Right to TransitionSceneKey.Blank),
            userActions =
                mapOf(
                    Swipe(SwipeDirection.Right, fromEdge = Edge.Left) to TransitionSceneKey.Blank
                ),
        ) {
            CommunalScene(viewModel, modifier = modifier)
        }
@@ -105,14 +113,12 @@ private fun BlankScene(
    Box(modifier.fillMaxSize()) {
        Column(
            Modifier.fillMaxHeight()
                .width(100.dp)
                .width(ContainerDimensions.EdgeSwipeSize)
                .align(Alignment.CenterEnd)
                .background(Color(0x55e9f2eb)),
            verticalArrangement = Arrangement.Center,
            horizontalAlignment = Alignment.CenterHorizontally
        ) {
            Text("Default scene")

            IconButton(onClick = hideSceneTransitionLayout) {
                Icon(Icons.Filled.Close, contentDescription = "Close button")
            }
@@ -142,3 +148,7 @@ fun CommunalSceneKey.toTransitionSceneKey(): SceneKey {
fun SceneKey.toCommunalSceneKey(): CommunalSceneKey {
    return this.identity as CommunalSceneKey
}

object ContainerDimensions {
    val EdgeSwipeSize = 40.dp
}
+14 −0
Original line number Diff line number Diff line
@@ -22,6 +22,8 @@ import android.widget.FrameLayout
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxHeight
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.height
@@ -42,6 +44,7 @@ import androidx.compose.runtime.getValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.input.pointer.pointerInput
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp
@@ -65,6 +68,7 @@ fun CommunalHub(
        LazyHorizontalGrid(
            modifier = modifier.height(Dimensions.GridHeight).align(Alignment.CenterStart),
            rows = GridCells.Fixed(CommunalContentSize.FULL.span),
            contentPadding = PaddingValues(horizontal = Dimensions.Spacing),
            horizontalArrangement = Arrangement.spacedBy(Dimensions.Spacing),
            verticalArrangement = Arrangement.spacedBy(Dimensions.Spacing),
        ) {
@@ -92,6 +96,16 @@ fun CommunalHub(
                LocalContext.current.getString(R.string.button_to_open_widget_picker)
            )
        }

        // This spacer covers the edge of the LazyHorizontalGrid and prevents it from receiving
        // touches, so that the SceneTransitionLayout can intercept the touches and allow an edge
        // swipe back to the blank scene.
        Spacer(
            Modifier.height(Dimensions.GridHeight)
                .align(Alignment.CenterStart)
                .width(Dimensions.Spacing)
                .pointerInput(Unit) {}
        )
    }
}