Skip to content

Commit 8c11769

Browse files
committed
Update to material3 1.0.0-beta03 wih built-in insets support
Change-Id: I4d07f89d4faa6e3417468ad78acf3fbb161f0797
1 parent 23ad5e8 commit 8c11769

File tree

8 files changed

+39
-61
lines changed

8 files changed

+39
-61
lines changed

app/src/main/java/com/google/samples/apps/nowinandroid/ui/NiaApp.kt

Lines changed: 26 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ import androidx.compose.material3.ExperimentalMaterial3Api
3131
import androidx.compose.material3.Icon
3232
import androidx.compose.material3.MaterialTheme
3333
import androidx.compose.material3.Scaffold
34-
import androidx.compose.material3.Surface
3534
import androidx.compose.material3.Text
3635
import androidx.compose.material3.windowsizeclass.WindowSizeClass
3736
import androidx.compose.runtime.Composable
@@ -73,6 +72,7 @@ fun NiaApp(
7372
},
7473
containerColor = Color.Transparent,
7574
contentColor = MaterialTheme.colorScheme.onBackground,
75+
contentWindowInsets = WindowInsets(0, 0, 0, 0),
7676
bottomBar = {
7777
if (appState.shouldShowBottomBar) {
7878
NiaBottomBar(
@@ -158,42 +158,32 @@ private fun NiaBottomBar(
158158
onNavigateToDestination: (TopLevelDestination) -> Unit,
159159
currentDestination: NavDestination?
160160
) {
161-
// Wrap the navigation bar in a surface so the color behind the system
162-
// navigation is equal to the container color of the navigation bar.
163-
Surface(color = MaterialTheme.colorScheme.surface) {
164-
NiaNavigationBar(
165-
modifier = Modifier.windowInsetsPadding(
166-
WindowInsets.safeDrawing.only(
167-
WindowInsetsSides.Horizontal + WindowInsetsSides.Bottom
168-
)
161+
NiaNavigationBar {
162+
destinations.forEach { destination ->
163+
val selected =
164+
currentDestination?.hierarchy?.any { it.route == destination.route } == true
165+
NiaNavigationBarItem(
166+
selected = selected,
167+
onClick = { onNavigateToDestination(destination) },
168+
icon = {
169+
val icon = if (selected) {
170+
destination.selectedIcon
171+
} else {
172+
destination.unselectedIcon
173+
}
174+
when (icon) {
175+
is ImageVectorIcon -> Icon(
176+
imageVector = icon.imageVector,
177+
contentDescription = null
178+
)
179+
is DrawableResourceIcon -> Icon(
180+
painter = painterResource(id = icon.id),
181+
contentDescription = null
182+
)
183+
}
184+
},
185+
label = { Text(stringResource(destination.iconTextId)) }
169186
)
170-
) {
171-
destinations.forEach { destination ->
172-
val selected =
173-
currentDestination?.hierarchy?.any { it.route == destination.route } == true
174-
NiaNavigationBarItem(
175-
selected = selected,
176-
onClick = { onNavigateToDestination(destination) },
177-
icon = {
178-
val icon = if (selected) {
179-
destination.selectedIcon
180-
} else {
181-
destination.unselectedIcon
182-
}
183-
when (icon) {
184-
is ImageVectorIcon -> Icon(
185-
imageVector = icon.imageVector,
186-
contentDescription = null
187-
)
188-
is DrawableResourceIcon -> Icon(
189-
painter = painterResource(id = icon.id),
190-
contentDescription = null
191-
)
192-
}
193-
},
194-
label = { Text(stringResource(destination.iconTextId)) }
195-
)
196-
}
197187
}
198188
}
199189
}

core/designsystem/src/main/java/com/google/samples/apps/nowinandroid/core/designsystem/component/Chip.kt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ import androidx.compose.material3.FilterChipDefaults
2222
import androidx.compose.material3.Icon
2323
import androidx.compose.material3.MaterialTheme
2424
import androidx.compose.material3.ProvideTextStyle
25-
import androidx.compose.material3.Shapes
2625
import androidx.compose.runtime.Composable
2726
import androidx.compose.ui.Modifier
2827
import androidx.compose.ui.graphics.Color
@@ -58,13 +57,12 @@ fun NiaFilterChip(
5857
},
5958
modifier = modifier,
6059
enabled = enabled,
61-
selectedIcon = {
60+
trailingIcon = {
6261
Icon(
6362
imageVector = NiaIcons.Check,
6463
contentDescription = null
6564
)
6665
},
67-
shape = Shapes.Full,
6866
border = FilterChipDefaults.filterChipBorder(
6967
borderColor = MaterialTheme.colorScheme.onBackground,
7068
selectedBorderColor = MaterialTheme.colorScheme.onBackground,

core/designsystem/src/main/java/com/google/samples/apps/nowinandroid/core/designsystem/component/TopAppBar.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import androidx.compose.material.icons.Icons
2121
import androidx.compose.material.icons.filled.MoreVert
2222
import androidx.compose.material.icons.filled.Search
2323
import androidx.compose.material3.CenterAlignedTopAppBar
24+
import androidx.compose.material3.ExperimentalMaterial3Api
2425
import androidx.compose.material3.Icon
2526
import androidx.compose.material3.IconButton
2627
import androidx.compose.material3.MaterialTheme
@@ -33,6 +34,7 @@ import androidx.compose.ui.graphics.vector.ImageVector
3334
import androidx.compose.ui.res.stringResource
3435
import androidx.compose.ui.tooling.preview.Preview
3536

37+
@OptIn(ExperimentalMaterial3Api::class)
3638
@Composable
3739
fun NiaTopAppBar(
3840
@StringRes titleRes: Int,
@@ -73,6 +75,7 @@ fun NiaTopAppBar(
7375
/**
7476
* Top app bar with action, displayed on the right
7577
*/
78+
@OptIn(ExperimentalMaterial3Api::class)
7679
@Composable
7780
fun NiaTopAppBar(
7881
@StringRes titleRes: Int,
@@ -98,6 +101,7 @@ fun NiaTopAppBar(
98101
)
99102
}
100103

104+
@OptIn(ExperimentalMaterial3Api::class)
101105
@Preview("Top App Bar")
102106
@Composable
103107
fun NiaTopAppBarPreview() {

feature/bookmarks/src/main/java/com/google/samples/apps/nowinandroid/feature/bookmarks/BookmarksScreen.kt

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,11 @@ import androidx.compose.foundation.layout.ExperimentalLayoutApi
2121
import androidx.compose.foundation.layout.PaddingValues
2222
import androidx.compose.foundation.layout.Spacer
2323
import androidx.compose.foundation.layout.WindowInsets
24-
import androidx.compose.foundation.layout.WindowInsetsSides
2524
import androidx.compose.foundation.layout.consumedWindowInsets
2625
import androidx.compose.foundation.layout.fillMaxSize
27-
import androidx.compose.foundation.layout.only
2826
import androidx.compose.foundation.layout.padding
2927
import androidx.compose.foundation.layout.safeDrawing
3028
import androidx.compose.foundation.layout.windowInsetsBottomHeight
31-
import androidx.compose.foundation.layout.windowInsetsPadding
3229
import androidx.compose.foundation.lazy.grid.GridCells.Adaptive
3330
import androidx.compose.foundation.lazy.grid.GridItemSpan
3431
import androidx.compose.foundation.lazy.grid.LazyVerticalGrid
@@ -83,13 +80,11 @@ fun BookmarksScreen(
8380
),
8481
colors = TopAppBarDefaults.centerAlignedTopAppBarColors(
8582
containerColor = Color.Transparent
86-
),
87-
modifier = Modifier.windowInsetsPadding(
88-
WindowInsets.safeDrawing.only(WindowInsetsSides.Top)
8983
)
9084
)
9185
},
92-
containerColor = Color.Transparent
86+
containerColor = Color.Transparent,
87+
contentWindowInsets = WindowInsets(0, 0, 0, 0)
9388
) { innerPadding ->
9489
LazyVerticalGrid(
9590
columns = Adaptive(300.dp),

feature/foryou/src/main/java/com/google/samples/apps/nowinandroid/feature/foryou/ForYouScreen.kt

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,19 +25,16 @@ import androidx.compose.foundation.layout.PaddingValues
2525
import androidx.compose.foundation.layout.Row
2626
import androidx.compose.foundation.layout.Spacer
2727
import androidx.compose.foundation.layout.WindowInsets
28-
import androidx.compose.foundation.layout.WindowInsetsSides
2928
import androidx.compose.foundation.layout.consumedWindowInsets
3029
import androidx.compose.foundation.layout.fillMaxSize
3130
import androidx.compose.foundation.layout.fillMaxWidth
3231
import androidx.compose.foundation.layout.height
3332
import androidx.compose.foundation.layout.heightIn
34-
import androidx.compose.foundation.layout.only
3533
import androidx.compose.foundation.layout.padding
3634
import androidx.compose.foundation.layout.safeDrawing
3735
import androidx.compose.foundation.layout.size
3836
import androidx.compose.foundation.layout.width
3937
import androidx.compose.foundation.layout.windowInsetsBottomHeight
40-
import androidx.compose.foundation.layout.windowInsetsPadding
4138
import androidx.compose.foundation.layout.wrapContentSize
4239
import androidx.compose.foundation.lazy.LazyListScope
4340
import androidx.compose.foundation.lazy.grid.GridCells
@@ -138,13 +135,11 @@ fun ForYouScreen(
138135
),
139136
colors = TopAppBarDefaults.centerAlignedTopAppBarColors(
140137
containerColor = Color.Transparent
141-
),
142-
modifier = Modifier.windowInsetsPadding(
143-
WindowInsets.safeDrawing.only(WindowInsetsSides.Top)
144138
)
145139
)
146140
},
147-
containerColor = Color.Transparent
141+
containerColor = Color.Transparent,
142+
contentWindowInsets = WindowInsets(0, 0, 0, 0)
148143
) { innerPadding ->
149144
// Workaround to call Activity.reportFullyDrawn from Jetpack Compose.
150145
// This code should be called when the UI is ready for use

feature/interests/src/main/java/com/google/samples/apps/nowinandroid/feature/interests/InterestsScreen.kt

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,7 @@
1717
package com.google.samples.apps.nowinandroid.feature.interests
1818

1919
import androidx.compose.foundation.layout.Column
20-
import androidx.compose.foundation.layout.Spacer
21-
import androidx.compose.foundation.layout.WindowInsets
22-
import androidx.compose.foundation.layout.safeDrawing
23-
import androidx.compose.foundation.layout.windowInsetsTopHeight
20+
import androidx.compose.material3.ExperimentalMaterial3Api
2421
import androidx.compose.material3.Text
2522
import androidx.compose.material3.TopAppBarDefaults
2623
import androidx.compose.runtime.Composable
@@ -77,6 +74,7 @@ fun InterestsRoute(
7774
}
7875
}
7976

77+
@OptIn(ExperimentalMaterial3Api::class)
8078
@Composable
8179
fun InterestsScreen(
8280
uiState: InterestsUiState,
@@ -92,8 +90,6 @@ fun InterestsScreen(
9290
modifier = modifier,
9391
horizontalAlignment = Alignment.CenterHorizontally
9492
) {
95-
Spacer(Modifier.windowInsetsTopHeight(WindowInsets.safeDrawing))
96-
9793
NiaTopAppBar(
9894
titleRes = R.string.interests,
9995
actionIcon = NiaIcons.MoreVert,

gradle/libs.versions.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ androidxAppCompat = "1.5.1"
77
androidxCompose = "1.3.0-beta02"
88
androidxComposeRuntimeTracing = "1.0.0-alpha01"
99
androidxComposeCompiler = "1.3.1"
10-
androidxComposeMaterial3 = "1.0.0-alpha13"
10+
androidxComposeMaterial3 = "1.0.0-beta03"
1111
androidxCore = "1.9.0"
1212
androidxCoreSplashscreen = "1.0.0"
1313
androidxCustomView = "1.0.0"

settings.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ dependencyResolutionManagement {
2828
repositories {
2929
// Register the AndroidX snapshot repository first so snapshots don't attempt (and fail)
3030
// to download from the non-snapshot repositories
31-
maven(url = "https://androidx.dev/snapshots/builds/8455591/artifacts/repository") {
31+
maven(url = "https://androidx.dev/snapshots/builds/9042167/artifacts/repository") {
3232
content {
3333
// The AndroidX snapshot repository will only have androidx artifacts, don't
3434
// bother trying to find other ones

0 commit comments

Comments
 (0)