From 8c11769622d0684e76860e00db5dc1b797b5f731 Mon Sep 17 00:00:00 2001 From: Alex Vanyo Date: Wed, 24 Aug 2022 15:46:53 -0700 Subject: [PATCH] Update to material3 1.0.0-beta03 wih built-in insets support Change-Id: I4d07f89d4faa6e3417468ad78acf3fbb161f0797 --- .../samples/apps/nowinandroid/ui/NiaApp.kt | 62 ++++++++----------- .../core/designsystem/component/Chip.kt | 4 +- .../core/designsystem/component/TopAppBar.kt | 4 ++ .../feature/bookmarks/BookmarksScreen.kt | 9 +-- .../feature/foryou/ForYouScreen.kt | 9 +-- .../feature/interests/InterestsScreen.kt | 8 +-- gradle/libs.versions.toml | 2 +- settings.gradle.kts | 2 +- 8 files changed, 39 insertions(+), 61 deletions(-) diff --git a/app/src/main/java/com/google/samples/apps/nowinandroid/ui/NiaApp.kt b/app/src/main/java/com/google/samples/apps/nowinandroid/ui/NiaApp.kt index 5bb603911..5731a4d6a 100644 --- a/app/src/main/java/com/google/samples/apps/nowinandroid/ui/NiaApp.kt +++ b/app/src/main/java/com/google/samples/apps/nowinandroid/ui/NiaApp.kt @@ -31,7 +31,6 @@ import androidx.compose.material3.ExperimentalMaterial3Api import androidx.compose.material3.Icon import androidx.compose.material3.MaterialTheme import androidx.compose.material3.Scaffold -import androidx.compose.material3.Surface import androidx.compose.material3.Text import androidx.compose.material3.windowsizeclass.WindowSizeClass import androidx.compose.runtime.Composable @@ -73,6 +72,7 @@ fun NiaApp( }, containerColor = Color.Transparent, contentColor = MaterialTheme.colorScheme.onBackground, + contentWindowInsets = WindowInsets(0, 0, 0, 0), bottomBar = { if (appState.shouldShowBottomBar) { NiaBottomBar( @@ -158,42 +158,32 @@ private fun NiaBottomBar( onNavigateToDestination: (TopLevelDestination) -> Unit, currentDestination: NavDestination? ) { - // Wrap the navigation bar in a surface so the color behind the system - // navigation is equal to the container color of the navigation bar. - Surface(color = MaterialTheme.colorScheme.surface) { - NiaNavigationBar( - modifier = Modifier.windowInsetsPadding( - WindowInsets.safeDrawing.only( - WindowInsetsSides.Horizontal + WindowInsetsSides.Bottom - ) + NiaNavigationBar { + destinations.forEach { destination -> + val selected = + currentDestination?.hierarchy?.any { it.route == destination.route } == true + NiaNavigationBarItem( + selected = selected, + onClick = { onNavigateToDestination(destination) }, + icon = { + val icon = if (selected) { + destination.selectedIcon + } else { + destination.unselectedIcon + } + when (icon) { + is ImageVectorIcon -> Icon( + imageVector = icon.imageVector, + contentDescription = null + ) + is DrawableResourceIcon -> Icon( + painter = painterResource(id = icon.id), + contentDescription = null + ) + } + }, + label = { Text(stringResource(destination.iconTextId)) } ) - ) { - destinations.forEach { destination -> - val selected = - currentDestination?.hierarchy?.any { it.route == destination.route } == true - NiaNavigationBarItem( - selected = selected, - onClick = { onNavigateToDestination(destination) }, - icon = { - val icon = if (selected) { - destination.selectedIcon - } else { - destination.unselectedIcon - } - when (icon) { - is ImageVectorIcon -> Icon( - imageVector = icon.imageVector, - contentDescription = null - ) - is DrawableResourceIcon -> Icon( - painter = painterResource(id = icon.id), - contentDescription = null - ) - } - }, - label = { Text(stringResource(destination.iconTextId)) } - ) - } } } } diff --git a/core/designsystem/src/main/java/com/google/samples/apps/nowinandroid/core/designsystem/component/Chip.kt b/core/designsystem/src/main/java/com/google/samples/apps/nowinandroid/core/designsystem/component/Chip.kt index 3d2cf3f2c..2bb86954f 100644 --- a/core/designsystem/src/main/java/com/google/samples/apps/nowinandroid/core/designsystem/component/Chip.kt +++ b/core/designsystem/src/main/java/com/google/samples/apps/nowinandroid/core/designsystem/component/Chip.kt @@ -22,7 +22,6 @@ import androidx.compose.material3.FilterChipDefaults import androidx.compose.material3.Icon import androidx.compose.material3.MaterialTheme import androidx.compose.material3.ProvideTextStyle -import androidx.compose.material3.Shapes import androidx.compose.runtime.Composable import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.Color @@ -58,13 +57,12 @@ fun NiaFilterChip( }, modifier = modifier, enabled = enabled, - selectedIcon = { + trailingIcon = { Icon( imageVector = NiaIcons.Check, contentDescription = null ) }, - shape = Shapes.Full, border = FilterChipDefaults.filterChipBorder( borderColor = MaterialTheme.colorScheme.onBackground, selectedBorderColor = MaterialTheme.colorScheme.onBackground, diff --git a/core/designsystem/src/main/java/com/google/samples/apps/nowinandroid/core/designsystem/component/TopAppBar.kt b/core/designsystem/src/main/java/com/google/samples/apps/nowinandroid/core/designsystem/component/TopAppBar.kt index b06dbeea6..d82c86989 100644 --- a/core/designsystem/src/main/java/com/google/samples/apps/nowinandroid/core/designsystem/component/TopAppBar.kt +++ b/core/designsystem/src/main/java/com/google/samples/apps/nowinandroid/core/designsystem/component/TopAppBar.kt @@ -21,6 +21,7 @@ import androidx.compose.material.icons.Icons import androidx.compose.material.icons.filled.MoreVert import androidx.compose.material.icons.filled.Search import androidx.compose.material3.CenterAlignedTopAppBar +import androidx.compose.material3.ExperimentalMaterial3Api import androidx.compose.material3.Icon import androidx.compose.material3.IconButton import androidx.compose.material3.MaterialTheme @@ -33,6 +34,7 @@ import androidx.compose.ui.graphics.vector.ImageVector import androidx.compose.ui.res.stringResource import androidx.compose.ui.tooling.preview.Preview +@OptIn(ExperimentalMaterial3Api::class) @Composable fun NiaTopAppBar( @StringRes titleRes: Int, @@ -73,6 +75,7 @@ fun NiaTopAppBar( /** * Top app bar with action, displayed on the right */ +@OptIn(ExperimentalMaterial3Api::class) @Composable fun NiaTopAppBar( @StringRes titleRes: Int, @@ -98,6 +101,7 @@ fun NiaTopAppBar( ) } +@OptIn(ExperimentalMaterial3Api::class) @Preview("Top App Bar") @Composable fun NiaTopAppBarPreview() { diff --git a/feature/bookmarks/src/main/java/com/google/samples/apps/nowinandroid/feature/bookmarks/BookmarksScreen.kt b/feature/bookmarks/src/main/java/com/google/samples/apps/nowinandroid/feature/bookmarks/BookmarksScreen.kt index ba1cb3986..5ffe9ed95 100644 --- a/feature/bookmarks/src/main/java/com/google/samples/apps/nowinandroid/feature/bookmarks/BookmarksScreen.kt +++ b/feature/bookmarks/src/main/java/com/google/samples/apps/nowinandroid/feature/bookmarks/BookmarksScreen.kt @@ -21,14 +21,11 @@ import androidx.compose.foundation.layout.ExperimentalLayoutApi import androidx.compose.foundation.layout.PaddingValues import androidx.compose.foundation.layout.Spacer import androidx.compose.foundation.layout.WindowInsets -import androidx.compose.foundation.layout.WindowInsetsSides import androidx.compose.foundation.layout.consumedWindowInsets import androidx.compose.foundation.layout.fillMaxSize -import androidx.compose.foundation.layout.only import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.safeDrawing import androidx.compose.foundation.layout.windowInsetsBottomHeight -import androidx.compose.foundation.layout.windowInsetsPadding import androidx.compose.foundation.lazy.grid.GridCells.Adaptive import androidx.compose.foundation.lazy.grid.GridItemSpan import androidx.compose.foundation.lazy.grid.LazyVerticalGrid @@ -83,13 +80,11 @@ fun BookmarksScreen( ), colors = TopAppBarDefaults.centerAlignedTopAppBarColors( containerColor = Color.Transparent - ), - modifier = Modifier.windowInsetsPadding( - WindowInsets.safeDrawing.only(WindowInsetsSides.Top) ) ) }, - containerColor = Color.Transparent + containerColor = Color.Transparent, + contentWindowInsets = WindowInsets(0, 0, 0, 0) ) { innerPadding -> LazyVerticalGrid( columns = Adaptive(300.dp), diff --git a/feature/foryou/src/main/java/com/google/samples/apps/nowinandroid/feature/foryou/ForYouScreen.kt b/feature/foryou/src/main/java/com/google/samples/apps/nowinandroid/feature/foryou/ForYouScreen.kt index 9e47d8782..63e001c3b 100644 --- a/feature/foryou/src/main/java/com/google/samples/apps/nowinandroid/feature/foryou/ForYouScreen.kt +++ b/feature/foryou/src/main/java/com/google/samples/apps/nowinandroid/feature/foryou/ForYouScreen.kt @@ -25,19 +25,16 @@ import androidx.compose.foundation.layout.PaddingValues import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.Spacer import androidx.compose.foundation.layout.WindowInsets -import androidx.compose.foundation.layout.WindowInsetsSides import androidx.compose.foundation.layout.consumedWindowInsets import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.height import androidx.compose.foundation.layout.heightIn -import androidx.compose.foundation.layout.only import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.safeDrawing import androidx.compose.foundation.layout.size import androidx.compose.foundation.layout.width import androidx.compose.foundation.layout.windowInsetsBottomHeight -import androidx.compose.foundation.layout.windowInsetsPadding import androidx.compose.foundation.layout.wrapContentSize import androidx.compose.foundation.lazy.LazyListScope import androidx.compose.foundation.lazy.grid.GridCells @@ -138,13 +135,11 @@ fun ForYouScreen( ), colors = TopAppBarDefaults.centerAlignedTopAppBarColors( containerColor = Color.Transparent - ), - modifier = Modifier.windowInsetsPadding( - WindowInsets.safeDrawing.only(WindowInsetsSides.Top) ) ) }, - containerColor = Color.Transparent + containerColor = Color.Transparent, + contentWindowInsets = WindowInsets(0, 0, 0, 0) ) { innerPadding -> // Workaround to call Activity.reportFullyDrawn from Jetpack Compose. // This code should be called when the UI is ready for use diff --git a/feature/interests/src/main/java/com/google/samples/apps/nowinandroid/feature/interests/InterestsScreen.kt b/feature/interests/src/main/java/com/google/samples/apps/nowinandroid/feature/interests/InterestsScreen.kt index 8bbfd02d4..b60fddb6a 100644 --- a/feature/interests/src/main/java/com/google/samples/apps/nowinandroid/feature/interests/InterestsScreen.kt +++ b/feature/interests/src/main/java/com/google/samples/apps/nowinandroid/feature/interests/InterestsScreen.kt @@ -17,10 +17,7 @@ package com.google.samples.apps.nowinandroid.feature.interests import androidx.compose.foundation.layout.Column -import androidx.compose.foundation.layout.Spacer -import androidx.compose.foundation.layout.WindowInsets -import androidx.compose.foundation.layout.safeDrawing -import androidx.compose.foundation.layout.windowInsetsTopHeight +import androidx.compose.material3.ExperimentalMaterial3Api import androidx.compose.material3.Text import androidx.compose.material3.TopAppBarDefaults import androidx.compose.runtime.Composable @@ -77,6 +74,7 @@ fun InterestsRoute( } } +@OptIn(ExperimentalMaterial3Api::class) @Composable fun InterestsScreen( uiState: InterestsUiState, @@ -92,8 +90,6 @@ fun InterestsScreen( modifier = modifier, horizontalAlignment = Alignment.CenterHorizontally ) { - Spacer(Modifier.windowInsetsTopHeight(WindowInsets.safeDrawing)) - NiaTopAppBar( titleRes = R.string.interests, actionIcon = NiaIcons.MoreVert, diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index f687f9229..b19b1b866 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -7,7 +7,7 @@ androidxAppCompat = "1.5.1" androidxCompose = "1.3.0-beta02" androidxComposeRuntimeTracing = "1.0.0-alpha01" androidxComposeCompiler = "1.3.1" -androidxComposeMaterial3 = "1.0.0-alpha13" +androidxComposeMaterial3 = "1.0.0-beta03" androidxCore = "1.9.0" androidxCoreSplashscreen = "1.0.0" androidxCustomView = "1.0.0" diff --git a/settings.gradle.kts b/settings.gradle.kts index c8518530f..850ea78ca 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -28,7 +28,7 @@ dependencyResolutionManagement { repositories { // Register the AndroidX snapshot repository first so snapshots don't attempt (and fail) // to download from the non-snapshot repositories - maven(url = "https://androidx.dev/snapshots/builds/8455591/artifacts/repository") { + maven(url = "https://androidx.dev/snapshots/builds/9042167/artifacts/repository") { content { // The AndroidX snapshot repository will only have androidx artifacts, don't // bother trying to find other ones