Adding device class breakopints (http://b/216019537)

Adding NavRail for MEDIUM / EXPANDED classes (http://b/216019759)

Change-Id: I19a8888de558e1466d186a48f2ea293bb1b8ba4b
pull/2/head
Ran Nachmany 3 years ago
parent 1dc478c441
commit ea9fbad058

@ -121,10 +121,12 @@ dependencies {
coreLibraryDesugaring libs.android.desugarJdkLibs coreLibraryDesugaring libs.android.desugarJdkLibs
implementation libs.androidx.activity.compose implementation libs.androidx.activity.compose
implementation libs.androidx.core.ktx
implementation libs.androidx.appcompat implementation libs.androidx.appcompat
implementation libs.androidx.core.ktx
implementation libs.androidx.compose.material.window
implementation libs.androidx.hilt.navigation.compose implementation libs.androidx.hilt.navigation.compose
implementation libs.androidx.navigation.compose implementation libs.androidx.navigation.compose
implementation libs.androidx.window.manager
implementation libs.material3 implementation libs.material3
implementation libs.hilt.android implementation libs.hilt.android

@ -16,6 +16,7 @@
package com.google.samples.apps.nowinandroid.ui package com.google.samples.apps.nowinandroid.ui
import androidx.compose.material.window.ExperimentalMaterialWindowApi
import androidx.compose.ui.test.assertIsOn import androidx.compose.ui.test.assertIsOn
import androidx.compose.ui.test.junit4.createAndroidComposeRule import androidx.compose.ui.test.junit4.createAndroidComposeRule
import androidx.compose.ui.test.onNodeWithContentDescription import androidx.compose.ui.test.onNodeWithContentDescription
@ -36,6 +37,7 @@ import org.junit.rules.TemporaryFolder
/** /**
* Tests all the navigation flows that are handled by the navigation library. * Tests all the navigation flows that are handled by the navigation library.
*/ */
@ExperimentalMaterialWindowApi
@HiltAndroidTest @HiltAndroidTest
class NavigationTest { class NavigationTest {

@ -19,10 +19,13 @@ package com.google.samples.apps.nowinandroid
import android.os.Bundle import android.os.Bundle
import androidx.activity.ComponentActivity import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent import androidx.activity.compose.setContent
import androidx.compose.material.window.ExperimentalMaterialWindowApi
import androidx.compose.material.window.rememberSizeClass
import androidx.core.view.WindowCompat import androidx.core.view.WindowCompat
import com.google.samples.apps.nowinandroid.ui.NiaApp import com.google.samples.apps.nowinandroid.ui.NiaApp
import dagger.hilt.android.AndroidEntryPoint import dagger.hilt.android.AndroidEntryPoint
@ExperimentalMaterialWindowApi
@AndroidEntryPoint @AndroidEntryPoint
class MainActivity : ComponentActivity() { class MainActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
@ -32,6 +35,6 @@ class MainActivity : ComponentActivity() {
// including IME animations // including IME animations
WindowCompat.setDecorFitsSystemWindows(window, false) WindowCompat.setDecorFitsSystemWindows(window, false)
setContent { NiaApp() } setContent { NiaApp(rememberSizeClass()) }
} }
} }

@ -17,6 +17,7 @@
package com.google.samples.apps.nowinandroid.ui package com.google.samples.apps.nowinandroid.ui
import androidx.annotation.StringRes import androidx.annotation.StringRes
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.captionBarPadding import androidx.compose.foundation.layout.captionBarPadding
import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.navigationBarsPadding import androidx.compose.foundation.layout.navigationBarsPadding
@ -32,11 +33,15 @@ import androidx.compose.material.icons.outlined.Bookmarks
import androidx.compose.material.icons.outlined.Grid3x3 import androidx.compose.material.icons.outlined.Grid3x3
import androidx.compose.material.icons.outlined.Upcoming import androidx.compose.material.icons.outlined.Upcoming
import androidx.compose.material.ripple.LocalRippleTheme import androidx.compose.material.ripple.LocalRippleTheme
import androidx.compose.material.window.SizeClass
import androidx.compose.material.window.WidthSizeClass
import androidx.compose.material3.ExperimentalMaterial3Api import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.Icon import androidx.compose.material3.Icon
import androidx.compose.material3.MaterialTheme import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.NavigationBar import androidx.compose.material3.NavigationBar
import androidx.compose.material3.NavigationBarItem import androidx.compose.material3.NavigationBarItem
import androidx.compose.material3.NavigationRail
import androidx.compose.material3.NavigationRailItem
import androidx.compose.material3.Scaffold import androidx.compose.material3.Scaffold
import androidx.compose.material3.Surface import androidx.compose.material3.Surface
import androidx.compose.material3.Text import androidx.compose.material3.Text
@ -56,7 +61,7 @@ import com.google.samples.apps.nowinandroid.core.ui.theme.NiaTheme
@OptIn(ExperimentalMaterial3Api::class) @OptIn(ExperimentalMaterial3Api::class)
@Composable @Composable
fun NiaApp() { fun NiaApp(windowSizeClass: SizeClass) {
NiaTheme { NiaTheme {
val navController = rememberNavController() val navController = rememberNavController()
val navigationActions = remember(navController) { val navigationActions = remember(navController) {
@ -70,18 +75,49 @@ fun NiaApp() {
Scaffold( Scaffold(
modifier = Modifier, modifier = Modifier,
bottomBar = { bottomBar = {
// TODO: Only show on small screens if (windowSizeClass.width == WidthSizeClass.Compact) NiABottomBar(
NiABottomBar(navigationActions, currentRoute) navigationActions = navigationActions,
}, currentRoute = currentRoute
) { padding ->
Surface(Modifier.fillMaxSize()) {
NiaNavGraph(
navController = navController,
modifier = Modifier
.statusBarsPadding()
.padding(padding)
) )
} }
) { padding ->
Surface(Modifier.fillMaxSize().statusBarsPadding()) {
Row {
if (windowSizeClass.width != WidthSizeClass.Compact) {
NiANavRail(
navigationActions = navigationActions,
currentRoute = currentRoute
)
}
NiaNavGraph(
navController = navController,
modifier = Modifier.padding(padding)
)
}
}
}
}
}
@Composable
private fun NiANavRail(
navigationActions: NiaNavigationActions,
currentRoute: String
) {
NavigationRail {
TOP_LEVEL_DESTINATIONS.forEach { destination ->
val selected = currentRoute == destination.route
NavigationRailItem(
selected = selected,
onClick = { navigationActions.navigateToTopLevelDestination(destination.route) },
icon = {
Icon(
if (selected) destination.selectedIcon else destination.unselectedIcon,
contentDescription = null
)
},
label = { Text(stringResource(destination.iconTextId)) }
)
} }
} }
} }

@ -27,6 +27,7 @@ buildscript {
repositories { repositories {
google() google()
mavenCentral() mavenCentral()
maven { url 'https://androidx.dev/snapshots/builds/8273139/artifacts/repository' }
} }
dependencies { dependencies {

@ -5,6 +5,7 @@ androidGradlePlugin = "7.0.3"
androidxActivity = "1.4.0" androidxActivity = "1.4.0"
androidxAppCompat = "1.3.0" androidxAppCompat = "1.3.0"
androidxCompose = "1.2.0-alpha03" androidxCompose = "1.2.0-alpha03"
androidxMaterialWindow = "1.2.0-SNAPSHOT"
androidxComposeMaterial3 = "1.0.0-alpha03" androidxComposeMaterial3 = "1.0.0-alpha03"
androidxCore = "1.7.0" androidxCore = "1.7.0"
androidxDataStore = "1.0.0" androidxDataStore = "1.0.0"
@ -12,6 +13,7 @@ androidxEspresso = "3.3.0"
androidxHiltNavigationCompose = "1.0.0-rc01" androidxHiltNavigationCompose = "1.0.0-rc01"
androidxLifecycle = "2.4.0" androidxLifecycle = "2.4.0"
androidxNavigation = "2.4.0-rc01" androidxNavigation = "2.4.0-rc01"
androidxWindowManager = "1.0.0"
androidxTest = "1.4.0" androidxTest = "1.4.0"
androidxTestExt = "1.1.2" androidxTestExt = "1.1.2"
hilt = "2.41" hilt = "2.41"
@ -42,6 +44,7 @@ androidx-activity-compose = { group = "androidx.activity", name = "activity-comp
androidx-appcompat = { group = "androidx.appcompat", name = "appcompat", version.ref = "androidxAppCompat" } androidx-appcompat = { group = "androidx.appcompat", name = "appcompat", version.ref = "androidxAppCompat" }
androidx-compose-foundation-layout = { group = "androidx.compose.foundation", name = "foundation-layout", version.ref = "androidxCompose" } androidx-compose-foundation-layout = { group = "androidx.compose.foundation", name = "foundation-layout", version.ref = "androidxCompose" }
androidx-compose-material = { group = "androidx.compose.material", name = "material", version.ref = "androidxCompose" } androidx-compose-material = { group = "androidx.compose.material", name = "material", version.ref = "androidxCompose" }
androidx-compose-material-window = {group = "androidx.compose.material", name = "material-window", version.ref="androidxMaterialWindow"}
androidx-compose-material-iconsExtended = { group = "androidx.compose.material", name = "material-icons-extended", version.ref = "androidxCompose" } androidx-compose-material-iconsExtended = { group = "androidx.compose.material", name = "material-icons-extended", version.ref = "androidxCompose" }
androidx-compose-material3 = { group = "androidx.compose.material3", name = "material3", version.ref = "androidxComposeMaterial3" } androidx-compose-material3 = { group = "androidx.compose.material3", name = "material3", version.ref = "androidxComposeMaterial3" }
androidx-compose-runtime = { group = "androidx.compose.runtime", name = "runtime", version.ref = "androidxCompose" } androidx-compose-runtime = { group = "androidx.compose.runtime", name = "runtime", version.ref = "androidxCompose" }
@ -56,6 +59,7 @@ androidx-dataStore = { group = "androidx.datastore", name = "datastore", version
androidx-hilt-navigation-compose = { group = "androidx.hilt", name = "hilt-navigation-compose", version.ref = "androidxHiltNavigationCompose" } androidx-hilt-navigation-compose = { group = "androidx.hilt", name = "hilt-navigation-compose", version.ref = "androidxHiltNavigationCompose" }
androidx-lifecycle-viewModelCompose = { group = "androidx.lifecycle", name = "lifecycle-viewmodel-compose", version.ref = "androidxLifecycle" } androidx-lifecycle-viewModelCompose = { group = "androidx.lifecycle", name = "lifecycle-viewmodel-compose", version.ref = "androidxLifecycle" }
androidx-navigation-compose = { group = "androidx.navigation", name = "navigation-compose", version.ref = "androidxNavigation" } androidx-navigation-compose = { group = "androidx.navigation", name = "navigation-compose", version.ref = "androidxNavigation" }
androidx-window-manager = {module = "androidx.window:window", version.ref = "androidxWindowManager"}
androidx-test-core = { group = "androidx.test", name = "core", version.ref = "androidxTest" } androidx-test-core = { group = "androidx.test", name = "core", version.ref = "androidxTest" }
androidx-test-espresso-core = { group = "androidx.test.espresso", name = "espresso-core", version.ref = "androidxEspresso" } androidx-test-espresso-core = { group = "androidx.test.espresso", name = "espresso-core", version.ref = "androidxEspresso" }
androidx-test-runner = { group = "androidx.test", name = "runner", version.ref = "androidxTest" } androidx-test-runner = { group = "androidx.test", name = "runner", version.ref = "androidxTest" }

@ -24,6 +24,7 @@ dependencyResolutionManagement {
google() google()
mavenCentral() mavenCentral()
gradlePluginPortal() gradlePluginPortal()
maven { url 'https://androidx.dev/snapshots/builds/8273139/artifacts/repository' }
} }
} }
rootProject.name = "nowinandroid" rootProject.name = "nowinandroid"

Loading…
Cancel
Save