From 6b8b5d3b89573957494cde1bafc298dbb113bf08 Mon Sep 17 00:00:00 2001 From: "Ian G. Clifton" Date: Fri, 30 Aug 2024 11:11:08 -0700 Subject: [PATCH 1/3] Added predictive back support to the drawer In M3 1.3, the drawerState can be passed to the ModalDrawerSheet to get predictive back animations without the need for a PredictiveBackHandler to be manually defined. --- JetNews/app/src/main/AndroidManifest.xml | 1 + .../main/java/com/example/jetnews/ui/AppDrawer.kt | 12 +++++++++--- .../main/java/com/example/jetnews/ui/JetnewsApp.kt | 8 +------- JetNews/gradle/libs.versions.toml | 4 ++-- 4 files changed, 13 insertions(+), 12 deletions(-) diff --git a/JetNews/app/src/main/AndroidManifest.xml b/JetNews/app/src/main/AndroidManifest.xml index dfc8ec8e98..134af83d20 100644 --- a/JetNews/app/src/main/AndroidManifest.xml +++ b/JetNews/app/src/main/AndroidManifest.xml @@ -17,6 +17,7 @@ Unit, navigateToInterests: () -> Unit, closeDrawer: () -> Unit, modifier: Modifier = Modifier ) { - ModalDrawerSheet(modifier) { + ModalDrawerSheet( + drawerState = drawerState, + modifier = modifier, + ) { JetNewsLogo( modifier = Modifier.padding(horizontal = 28.dp, vertical = 24.dp) ) @@ -93,6 +98,7 @@ private fun JetNewsLogo(modifier: Modifier = Modifier) { fun PreviewAppDrawer() { JetnewsTheme { AppDrawer( + drawerState = rememberDrawerState(initialValue = DrawerValue.Open), currentRoute = JetnewsDestinations.HOME_ROUTE, navigateToHome = {}, navigateToInterests = {}, diff --git a/JetNews/app/src/main/java/com/example/jetnews/ui/JetnewsApp.kt b/JetNews/app/src/main/java/com/example/jetnews/ui/JetnewsApp.kt index da34e1d301..1d65a206df 100644 --- a/JetNews/app/src/main/java/com/example/jetnews/ui/JetnewsApp.kt +++ b/JetNews/app/src/main/java/com/example/jetnews/ui/JetnewsApp.kt @@ -16,7 +16,6 @@ package com.example.jetnews.ui -import androidx.activity.compose.BackHandler import androidx.compose.foundation.layout.Row import androidx.compose.material3.DrawerState import androidx.compose.material3.DrawerValue @@ -54,15 +53,10 @@ fun JetnewsApp( val isExpandedScreen = widthSizeClass == WindowWidthSizeClass.Expanded val sizeAwareDrawerState = rememberSizeAwareDrawerState(isExpandedScreen) - BackHandler(sizeAwareDrawerState.isOpen) { - coroutineScope.launch { - sizeAwareDrawerState.close() - } - } - ModalNavigationDrawer( drawerContent = { AppDrawer( + drawerState = sizeAwareDrawerState, currentRoute = currentRoute, navigateToHome = navigationActions.navigateToHome, navigateToInterests = navigationActions.navigateToInterests, diff --git a/JetNews/gradle/libs.versions.toml b/JetNews/gradle/libs.versions.toml index 2c34e54e54..2ea1b3f83e 100644 --- a/JetNews/gradle/libs.versions.toml +++ b/JetNews/gradle/libs.versions.toml @@ -11,7 +11,7 @@ androidx-benchmark = "1.2.4" androidx-benchmark-junit4 = "1.2.4" androidx-compose-bom = "2024.06.00" androidx-compose-latest = "1.7.0-beta07" -androidx-compose-material3 = "1.3.0-beta05" +androidx-compose-material3 = "1.3.0-rc01" androidx-compose-material3-adaptive = "1.0.0-beta04" androidx-constraintlayout = "1.1.0-alpha13" androidx-core-splashscreen = "1.0.1" @@ -78,7 +78,7 @@ androidx-compose-bom = { module = "androidx.compose:compose-bom", version.ref = androidx-compose-foundation = { module = "androidx.compose.foundation:foundation", version.ref = "androidx-compose-latest"} androidx-compose-foundation-layout = { module = "androidx.compose.foundation:foundation-layout" ,version.ref = "androidx-compose-latest"} androidx-compose-material-iconsExtended = { module = "androidx.compose.material:material-icons-extended" } -androidx-compose-material3 = { module = "androidx.compose.material3:material3" } +androidx-compose-material3 = { module = "androidx.compose.material3:material3", version.ref = "androidx-compose-material3" } androidx-compose-material3-adaptive = { module = "androidx.compose.material3.adaptive:adaptive", version.ref = "androidx-compose-material3-adaptive" } androidx-compose-material3-adaptive-layout = { module = "androidx.compose.material3.adaptive:adaptive-layout", version.ref = "androidx-compose-material3-adaptive" } androidx-compose-material3-adaptive-navigation = { module = "androidx.compose.material3.adaptive:adaptive-navigation", version.ref = "androidx-compose-material3-adaptive" } From b4de9e930af8eff37ace585854d30bf4fbbcb831 Mon Sep 17 00:00:00 2001 From: "Ian G. Clifton" Date: Thu, 5 Sep 2024 17:31:14 -0700 Subject: [PATCH 2/3] Updated dependencies --- JetNews/gradle/libs.versions.toml | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/JetNews/gradle/libs.versions.toml b/JetNews/gradle/libs.versions.toml index 2ea1b3f83e..eb125e0aa6 100644 --- a/JetNews/gradle/libs.versions.toml +++ b/JetNews/gradle/libs.versions.toml @@ -9,10 +9,8 @@ androidx-activity-compose = "1.9.0" androidx-appcompat = "1.7.0" androidx-benchmark = "1.2.4" androidx-benchmark-junit4 = "1.2.4" -androidx-compose-bom = "2024.06.00" +androidx-compose-bom = "2024.09.00" androidx-compose-latest = "1.7.0-beta07" -androidx-compose-material3 = "1.3.0-rc01" -androidx-compose-material3-adaptive = "1.0.0-beta04" androidx-constraintlayout = "1.1.0-alpha13" androidx-core-splashscreen = "1.0.1" androidx-corektx = "1.13.1" @@ -78,11 +76,11 @@ androidx-compose-bom = { module = "androidx.compose:compose-bom", version.ref = androidx-compose-foundation = { module = "androidx.compose.foundation:foundation", version.ref = "androidx-compose-latest"} androidx-compose-foundation-layout = { module = "androidx.compose.foundation:foundation-layout" ,version.ref = "androidx-compose-latest"} androidx-compose-material-iconsExtended = { module = "androidx.compose.material:material-icons-extended" } -androidx-compose-material3 = { module = "androidx.compose.material3:material3", version.ref = "androidx-compose-material3" } -androidx-compose-material3-adaptive = { module = "androidx.compose.material3.adaptive:adaptive", version.ref = "androidx-compose-material3-adaptive" } -androidx-compose-material3-adaptive-layout = { module = "androidx.compose.material3.adaptive:adaptive-layout", version.ref = "androidx-compose-material3-adaptive" } -androidx-compose-material3-adaptive-navigation = { module = "androidx.compose.material3.adaptive:adaptive-navigation", version.ref = "androidx-compose-material3-adaptive" } -androidx-compose-material3-adaptive-navigationSuite = { module = "androidx.compose.material3:material3-adaptive-navigation-suite", version.ref = "androidx-compose-material3" } +androidx-compose-material3 = { module = "androidx.compose.material3:material3" } +androidx-compose-material3-adaptive = { module = "androidx.compose.material3.adaptive:adaptive" } +androidx-compose-material3-adaptive-layout = { module = "androidx.compose.material3.adaptive:adaptive-layout" } +androidx-compose-material3-adaptive-navigation = { module = "androidx.compose.material3.adaptive:adaptive-navigation" } +androidx-compose-material3-adaptive-navigationSuite = { module = "androidx.compose.material3:material3-adaptive-navigation-suite" } androidx-compose-materialWindow = { module = "androidx.compose.material3:material3-window-size-class" } androidx-compose-runtime = { module = "androidx.compose.runtime:runtime" } androidx-compose-runtime-livedata = { module = "androidx.compose.runtime:runtime-livedata" } From 3335c0477cc0e0b005ca7acad7a8a4dc6f084a32 Mon Sep 17 00:00:00 2001 From: "Ian G. Clifton" Date: Thu, 5 Sep 2024 17:35:25 -0700 Subject: [PATCH 3/3] Removed use of Compose beta --- JetNews/gradle/libs.versions.toml | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/JetNews/gradle/libs.versions.toml b/JetNews/gradle/libs.versions.toml index eb125e0aa6..5b178a9552 100644 --- a/JetNews/gradle/libs.versions.toml +++ b/JetNews/gradle/libs.versions.toml @@ -10,7 +10,6 @@ androidx-appcompat = "1.7.0" androidx-benchmark = "1.2.4" androidx-benchmark-junit4 = "1.2.4" androidx-compose-bom = "2024.09.00" -androidx-compose-latest = "1.7.0-beta07" androidx-constraintlayout = "1.1.0-alpha13" androidx-core-splashscreen = "1.0.1" androidx-corektx = "1.13.1" @@ -71,10 +70,10 @@ androidx-activity-ktx = { module = "androidx.activity:activity-ktx", version.ref androidx-appcompat = { module = "androidx.appcompat:appcompat", version.ref = "androidx-appcompat" } androidx-benchmark-macrobenchmark = { module = "androidx.benchmark:benchmark-macro", version.ref = "androidx-benchmark" } androidx-benchmark-macrobenchmark-junit4 = { module = "androidx.benchmark:benchmark-macro-junit4", version.ref = "androidx-benchmark-junit4" } -androidx-compose-animation = { module = "androidx.compose.animation:animation", version.ref = "androidx-compose-latest" } +androidx-compose-animation = { module = "androidx.compose.animation:animation" } androidx-compose-bom = { module = "androidx.compose:compose-bom", version.ref = "androidx-compose-bom" } -androidx-compose-foundation = { module = "androidx.compose.foundation:foundation", version.ref = "androidx-compose-latest"} -androidx-compose-foundation-layout = { module = "androidx.compose.foundation:foundation-layout" ,version.ref = "androidx-compose-latest"} +androidx-compose-foundation = { module = "androidx.compose.foundation:foundation" } +androidx-compose-foundation-layout = { module = "androidx.compose.foundation:foundation-layout" } androidx-compose-material-iconsExtended = { module = "androidx.compose.material:material-icons-extended" } androidx-compose-material3 = { module = "androidx.compose.material3:material3" } androidx-compose-material3-adaptive = { module = "androidx.compose.material3.adaptive:adaptive" } @@ -84,7 +83,7 @@ androidx-compose-material3-adaptive-navigationSuite = { module = "androidx.compo androidx-compose-materialWindow = { module = "androidx.compose.material3:material3-window-size-class" } androidx-compose-runtime = { module = "androidx.compose.runtime:runtime" } androidx-compose-runtime-livedata = { module = "androidx.compose.runtime:runtime-livedata" } -androidx-compose-ui = { module = "androidx.compose.ui:ui" , version.ref = "androidx-compose-latest"} +androidx-compose-ui = { module = "androidx.compose.ui:ui" } androidx-compose-ui-googlefonts = { module = "androidx.compose.ui:ui-text-google-fonts" } androidx-compose-ui-graphics = { module = "androidx.compose.ui:ui-graphics" } androidx-compose-ui-test = { module = "androidx.compose.ui:ui-test" }