Merge "Only listen to edge swipes to/from hub mode" into main
diff --git a/packages/SystemUI/compose/features/src/com/android/systemui/communal/ui/compose/CommunalContainer.kt b/packages/SystemUI/compose/features/src/com/android/systemui/communal/ui/compose/CommunalContainer.kt
index 3780468..09706be 100644
--- a/packages/SystemUI/compose/features/src/com/android/systemui/communal/ui/compose/CommunalContainer.kt
+++ b/packages/SystemUI/compose/features/src/com/android/systemui/communal/ui/compose/CommunalContainer.kt
@@ -12,7 +12,6 @@
 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.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 @@
         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 @@
     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 SceneKey.toCommunalSceneKey(): CommunalSceneKey {
     return this.identity as CommunalSceneKey
 }
+
+object ContainerDimensions {
+    val EdgeSwipeSize = 40.dp
+}
diff --git a/packages/SystemUI/compose/features/src/com/android/systemui/communal/ui/compose/CommunalHub.kt b/packages/SystemUI/compose/features/src/com/android/systemui/communal/ui/compose/CommunalHub.kt
index 0569431..6e18cb9 100644
--- a/packages/SystemUI/compose/features/src/com/android/systemui/communal/ui/compose/CommunalHub.kt
+++ b/packages/SystemUI/compose/features/src/com/android/systemui/communal/ui/compose/CommunalHub.kt
@@ -22,6 +22,8 @@
 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
@@ -41,6 +43,7 @@
 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
@@ -64,6 +67,7 @@
         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),
         ) {
@@ -91,6 +95,16 @@
                 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) {}
+        )
     }
 }