From 4340d2f5b7e4e0b5dad787776a8d5aea4bf933b4 Mon Sep 17 00:00:00 2001 From: Sungyong An Date: Fri, 19 Jul 2024 00:49:19 +0900 Subject: [PATCH] Enable predictive back gesture --- gradle/libs.versions.toml | 4 ++-- sample/android/src/main/AndroidManifest.xml | 1 + .../sample/ui/circularreveal/CircularRevealScreen.kt | 8 ++------ .../compose/material/motion/sample/ui/demo/DemoScreen.kt | 4 ---- .../elevationscale/MaterialElevationScaleScreen.kt | 8 ++------ .../motion/sample/ui/material/fade/MaterialFadeScreen.kt | 4 ---- .../ui/material/fadethrough/MaterialFadeThroughScreen.kt | 4 ---- .../material/motion/sample/ui/material/hold/HoldScreen.kt | 8 ++------ .../ui/material/sharedaxis/MaterialSharedAxisScreen.kt | 8 ++------ .../motion/sample/ui/navigation/AnimatedNavHostScreen.kt | 4 ---- 10 files changed, 11 insertions(+), 42 deletions(-) diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 56dd8b8..6bbb6ac 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -11,8 +11,8 @@ dokka = "1.8.10" # Compose activity = "1.9.0" -navigation = "2.8.0-beta02" -compose = "1.7.0-beta02" +navigation = "2.8.0-beta05" +compose = "1.7.0-beta05" compose-compiler = "1.5.2" # AndroidX diff --git a/sample/android/src/main/AndroidManifest.xml b/sample/android/src/main/AndroidManifest.xml index 6d2b157..56c96bc 100644 --- a/sample/android/src/main/AndroidManifest.xml +++ b/sample/android/src/main/AndroidManifest.xml @@ -3,6 +3,7 @@ Unit) { val (state, onStateChanged) = remember { mutableStateOf(State(false, Offset.Zero)) } - BackHandler { - if (state.visible) { - onStateChanged(state.copy(visible = false)) - } else { - upPress() - } + BackHandler(enabled = state.visible) { + onStateChanged(state.copy(visible = false)) } DefaultScaffold(upPress = upPress) { innerPadding -> Surface(modifier = Modifier.padding(innerPadding)) { diff --git a/sample/android/src/main/java/soup/compose/material/motion/sample/ui/demo/DemoScreen.kt b/sample/android/src/main/java/soup/compose/material/motion/sample/ui/demo/DemoScreen.kt index b22c2d3..4f07113 100644 --- a/sample/android/src/main/java/soup/compose/material/motion/sample/ui/demo/DemoScreen.kt +++ b/sample/android/src/main/java/soup/compose/material/motion/sample/ui/demo/DemoScreen.kt @@ -16,7 +16,6 @@ package soup.compose.material.motion.sample.ui.demo import android.content.res.Configuration -import androidx.activity.compose.BackHandler import androidx.compose.runtime.Composable import androidx.compose.ui.tooling.preview.Preview import androidx.navigation.compose.NavHost @@ -46,9 +45,6 @@ fun DemoScreen(upPress: () -> Unit) { enterTransition = { holdIn() }, exitTransition = { holdOut() }, ) { - BackHandler { - upPress() - } LibraryScreen( onItemClick = { navController.navigate(DemoDestination.Album(albumId = it.id)) diff --git a/sample/android/src/main/java/soup/compose/material/motion/sample/ui/material/elevationscale/MaterialElevationScaleScreen.kt b/sample/android/src/main/java/soup/compose/material/motion/sample/ui/material/elevationscale/MaterialElevationScaleScreen.kt index f6a36e4..3fb310e 100644 --- a/sample/android/src/main/java/soup/compose/material/motion/sample/ui/material/elevationscale/MaterialElevationScaleScreen.kt +++ b/sample/android/src/main/java/soup/compose/material/motion/sample/ui/material/elevationscale/MaterialElevationScaleScreen.kt @@ -37,12 +37,8 @@ import soup.compose.material.motion.sample.ui.theme.SampleTheme @Composable fun MaterialElevationScaleScreen(upPress: () -> Unit) { val (forward, onForwardChanged) = remember { mutableStateOf(false) } - BackHandler { - if (forward) { - onForwardChanged(false) - } else { - upPress() - } + BackHandler(enabled = forward) { + onForwardChanged(false) } DefaultScaffold( upPress = upPress, diff --git a/sample/android/src/main/java/soup/compose/material/motion/sample/ui/material/fade/MaterialFadeScreen.kt b/sample/android/src/main/java/soup/compose/material/motion/sample/ui/material/fade/MaterialFadeScreen.kt index 43aec63..317d395 100644 --- a/sample/android/src/main/java/soup/compose/material/motion/sample/ui/material/fade/MaterialFadeScreen.kt +++ b/sample/android/src/main/java/soup/compose/material/motion/sample/ui/material/fade/MaterialFadeScreen.kt @@ -16,7 +16,6 @@ package soup.compose.material.motion.sample.ui.material.fade import android.content.res.Configuration -import androidx.activity.compose.BackHandler import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.padding @@ -39,9 +38,6 @@ import soup.compose.material.motion.sample.ui.theme.SampleTheme @Composable fun MaterialFadeScreen(upPress: () -> Unit) { - BackHandler { - upPress() - } DefaultScaffold(upPress = upPress) { innerPadding -> val (visible, onVisibleChanged) = remember { mutableStateOf(true) } Box( diff --git a/sample/android/src/main/java/soup/compose/material/motion/sample/ui/material/fadethrough/MaterialFadeThroughScreen.kt b/sample/android/src/main/java/soup/compose/material/motion/sample/ui/material/fadethrough/MaterialFadeThroughScreen.kt index 32ea217..d699b57 100644 --- a/sample/android/src/main/java/soup/compose/material/motion/sample/ui/material/fadethrough/MaterialFadeThroughScreen.kt +++ b/sample/android/src/main/java/soup/compose/material/motion/sample/ui/material/fadethrough/MaterialFadeThroughScreen.kt @@ -16,7 +16,6 @@ package soup.compose.material.motion.sample.ui.material.fadethrough import android.content.res.Configuration -import androidx.activity.compose.BackHandler import androidx.compose.foundation.layout.padding import androidx.compose.runtime.Composable import androidx.compose.runtime.mutableStateOf @@ -33,9 +32,6 @@ import soup.compose.material.motion.sample.ui.theme.SampleTheme @Composable fun MaterialFadeThroughScreen(upPress: () -> Unit) { val (selectedTab, setSelectedTab) = remember { mutableStateOf(BottomTabs.Albums) } - BackHandler { - upPress() - } DefaultScaffold( upPress = upPress, bottomBar = { BottomTabsControls(selectedTab, setSelectedTab) }, diff --git a/sample/android/src/main/java/soup/compose/material/motion/sample/ui/material/hold/HoldScreen.kt b/sample/android/src/main/java/soup/compose/material/motion/sample/ui/material/hold/HoldScreen.kt index aeae2e1..d3ecc79 100644 --- a/sample/android/src/main/java/soup/compose/material/motion/sample/ui/material/hold/HoldScreen.kt +++ b/sample/android/src/main/java/soup/compose/material/motion/sample/ui/material/hold/HoldScreen.kt @@ -37,12 +37,8 @@ import soup.compose.material.motion.sample.ui.theme.SampleTheme @Composable fun HoldScreen(upPress: () -> Unit) { val (forward, onForwardChanged) = remember { mutableStateOf(false) } - BackHandler { - if (forward) { - onForwardChanged(false) - } else { - upPress() - } + BackHandler(enabled = forward) { + onForwardChanged(false) } DefaultScaffold( upPress = upPress, diff --git a/sample/android/src/main/java/soup/compose/material/motion/sample/ui/material/sharedaxis/MaterialSharedAxisScreen.kt b/sample/android/src/main/java/soup/compose/material/motion/sample/ui/material/sharedaxis/MaterialSharedAxisScreen.kt index 68afe7e..3ed910c 100644 --- a/sample/android/src/main/java/soup/compose/material/motion/sample/ui/material/sharedaxis/MaterialSharedAxisScreen.kt +++ b/sample/android/src/main/java/soup/compose/material/motion/sample/ui/material/sharedaxis/MaterialSharedAxisScreen.kt @@ -55,12 +55,8 @@ private enum class Axis { fun MaterialSharedAxisScreen(upPress: () -> Unit) { val (selectedAxis, onAxisSelected) = remember { mutableStateOf(Axis.X) } val (forward, onForwardChanged) = remember { mutableStateOf(false) } - BackHandler { - if (forward) { - onForwardChanged(false) - } else { - upPress() - } + BackHandler(enabled = forward) { + onForwardChanged(false) } DefaultScaffold( upPress = upPress, diff --git a/sample/android/src/main/java/soup/compose/material/motion/sample/ui/navigation/AnimatedNavHostScreen.kt b/sample/android/src/main/java/soup/compose/material/motion/sample/ui/navigation/AnimatedNavHostScreen.kt index 80a56ec..328b9ee 100644 --- a/sample/android/src/main/java/soup/compose/material/motion/sample/ui/navigation/AnimatedNavHostScreen.kt +++ b/sample/android/src/main/java/soup/compose/material/motion/sample/ui/navigation/AnimatedNavHostScreen.kt @@ -15,7 +15,6 @@ */ package soup.compose.material.motion.sample.ui.navigation -import androidx.activity.compose.BackHandler import androidx.compose.foundation.background import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Column @@ -74,9 +73,6 @@ fun AnimatedNavHostScreen(upPress: () -> Unit) { }, ) { composable { - BackHandler { - upPress() - } AnimatedNavDestinationScreen( name = "First", backgroundColor = Color.Cyan,