Skip to content

Commit 38e6c56

Browse files
authored
Merge pull request #14 from chikoski/update-remember-navigation-component-type
Stop referring to form factor information
2 parents 8e7d0d9 + c7c675e commit 38e6c56

31 files changed

+299
-240
lines changed

AdaptiveJetStream/gradle/libs.versions.toml

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,31 @@
11
[versions]
2-
activity-compose = "1.10.1"
3-
android-gradle-plugin = "8.9.3"
4-
android-test-plugin = "8.9.3"
5-
androidx-baselineprofile = "1.3.4"
6-
benchmark-macro-junit4 = "1.3.4"
2+
activity-compose = "1.11.0"
3+
android-gradle-plugin = "8.13.0"
4+
android-test-plugin = "8.13.0"
5+
androidx-baselineprofile = "1.4.1"
6+
benchmark-macro-junit4 = "1.4.1"
77
coil-compose = "2.7.0"
8-
compose-bom = "2025.05.00"
9-
tv-material = "1.0.0"
10-
core-ktx = "1.16.0"
8+
compose-bom = "2025.09.00"
9+
tv-material = "1.0.1"
10+
core-ktx = "1.17.0"
1111
core-splashscreen = "1.0.1"
12-
hilt-navigation-compose = "1.2.0"
13-
hilt-android = "2.56.1"
14-
junit = "1.2.1"
15-
kotlin-android = "2.1.10"
16-
kotlinx-serialization = "1.8.1"
17-
ksp = "2.1.10-1.0.30"
18-
lifecycle-runtime-ktx = "2.9.0"
12+
hilt-navigation-compose = "1.3.0"
13+
hilt-android = "2.57.1"
14+
junit = "1.3.0"
15+
kotlin-android = "2.2.20"
16+
kotlinx-serialization = "1.9.0"
17+
ksp = "2.2.20-2.0.3"
18+
lifecycle-runtime-ktx = "2.9.4"
1919
material3-adaptive = "1.1.0"
20-
material3-adaptive-navigation = "1.4.0-alpha14"
21-
media3 = "1.6.1"
22-
navigation-compose = "2.9.0"
20+
material3-adaptive-navigation = "1.4.0-rc01"
21+
media3 = "1.8.0"
22+
navigation-compose = "2.9.4"
2323
profileinstaller = "1.4.1"
2424
uiautomator = "2.3.0"
25-
rules = "1.6.1"
26-
window = "1.4.0-rc02"
27-
xr = "1.0.0-alpha04"
28-
xr-material3 = "1.0.0-alpha08"
25+
rules = "1.7.0"
26+
window = "1.4.0"
27+
xr = "1.0.0-alpha06"
28+
xr-material3 = "1.0.0-alpha11"
2929

3030
[libraries]
3131
androidx-activity-compose = { module = "androidx.activity:activity-compose", version.ref = "activity-compose" }
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
distributionBase=GRADLE_USER_HOME
22
distributionPath=wrapper/dists
3-
distributionUrl=https\://services.gradle.org/distributions/gradle-8.11.1-bin.zip
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-9.0.0-bin.zip
44
networkTimeout=10000
55
zipStoreBase=GRADLE_USER_HOME
66
zipStorePath=wrapper/dists

AdaptiveJetStream/jetstream/build.gradle.kts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
2+
13
/*
24
* Copyright 2023 Google LLC
35
*
@@ -26,17 +28,21 @@ plugins {
2628

2729
kotlin {
2830
jvmToolchain(17)
31+
32+
compilerOptions {
33+
jvmTarget = JvmTarget.JVM_17
34+
}
2935
}
3036

3137
android {
3238
namespace = "com.google.jetstream"
3339
// Needed for latest androidx snapshot build
34-
compileSdk = 35
40+
compileSdk = 36
3541

3642
defaultConfig {
3743
applicationId = "com.google.jetstream"
3844
minSdk = 28
39-
targetSdk = 35
45+
targetSdk = 36
4046
versionCode = 1
4147
versionName = "1.0"
4248

@@ -67,9 +73,6 @@ android {
6773
}
6874
}
6975

70-
kotlinOptions {
71-
jvmTarget = "17"
72-
}
7376
}
7477

7578
dependencies {

AdaptiveJetStream/jetstream/src/main/java/com/google/jetstream/MainActivity.kt

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ package com.google.jetstream
1919
import android.content.pm.PackageManager
2020
import android.os.Build
2121
import android.os.Bundle
22-
import android.util.Log
2322
import android.view.KeyEvent
2423
import android.view.KeyboardShortcutGroup
2524
import android.view.KeyboardShortcutInfo
@@ -42,7 +41,6 @@ import androidx.core.splashscreen.SplashScreen.Companion.installSplashScreen
4241
import androidx.xr.compose.material3.EnableXrComponentOverrides
4342
import androidx.xr.compose.material3.ExperimentalMaterial3XrApi
4443
import com.google.jetstream.presentation.App
45-
import com.google.jetstream.presentation.components.feature.UiMode
4644
import com.google.jetstream.presentation.theme.JetStreamTheme
4745
import dagger.hilt.android.AndroidEntryPoint
4846

@@ -92,7 +90,6 @@ class MainActivity : ComponentActivity() {
9290
private fun tryEnableCustomHeader() {
9391
if (toEnableCustomHeader()) {
9492
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.VANILLA_ICE_CREAM) {
95-
Log.d("MainActivity", "Custom header enabled")
9693
window.insetsController?.apply {
9794
setSystemBarsAppearance(
9895
WindowInsetsController.APPEARANCE_TRANSPARENT_CAPTION_BAR_BACKGROUND,
@@ -103,9 +100,6 @@ class MainActivity : ComponentActivity() {
103100
}
104101
}
105102

106-
private val currentUiMode: UiMode
107-
get() = UiMode.from(resources.configuration)
108-
109103
private fun toEnableCustomHeader(): Boolean {
110104
val reliedFeatures = listOf(
111105
PackageManager.FEATURE_FREEFORM_WINDOW_MANAGEMENT,

AdaptiveJetStream/jetstream/src/main/java/com/google/jetstream/presentation/App.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ fun App(
149149
}
150150
}
151151

152-
NavigationComponentType.Custom -> {
152+
NavigationComponentType.TopBar -> {
153153
AppWithTopBarNavigation(
154154
appState = appState,
155155
onActivityBackPressed = onActivityBackPressed,

AdaptiveJetStream/jetstream/src/main/java/com/google/jetstream/presentation/app/AppState.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ class AppState internal constructor(
7474
selectedScreen.navigationVisibility.isVisibleInNavigationSuite
7575
}
7676

77-
NavigationComponentType.Custom -> {
77+
NavigationComponentType.TopBar -> {
7878
selectedScreen.navigationVisibility.isVisibleInCustomNavigation
7979
}
8080
}

AdaptiveJetStream/jetstream/src/main/java/com/google/jetstream/presentation/app/NavigationComponentType.kt

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -19,39 +19,40 @@ package com.google.jetstream.presentation.app
1919
import androidx.compose.material3.adaptive.currentWindowAdaptiveInfo
2020
import androidx.compose.runtime.Composable
2121
import androidx.compose.runtime.remember
22-
import androidx.window.core.layout.WindowSizeClass
23-
import com.google.jetstream.presentation.components.feature.FormFactor
22+
import com.google.jetstream.presentation.components.feature.isAutomotiveEnabled
23+
import com.google.jetstream.presentation.components.feature.isLeanbackEnabled
2424
import com.google.jetstream.presentation.components.feature.isWidthAtLeastLarge
25-
import com.google.jetstream.presentation.components.feature.rememberFormFactor
2625

2726
enum class NavigationComponentType {
2827
NavigationSuiteScaffold,
29-
Custom
28+
TopBar
3029
}
3130

3231
@Composable
33-
fun rememberNavigationComponentType(
34-
formFactor: FormFactor = rememberFormFactor(),
35-
windowSizeClass: WindowSizeClass = currentWindowAdaptiveInfo().windowSizeClass
36-
): NavigationComponentType {
37-
return remember(formFactor, windowSizeClass) {
38-
selectNavigationComponentType(formFactor, windowSizeClass.isWidthAtLeastLarge())
32+
fun rememberNavigationComponentType(): NavigationComponentType {
33+
val windowSizeClass = currentWindowAdaptiveInfo().windowSizeClass
34+
val isLeanbackEnabled = isLeanbackEnabled()
35+
val isAutomotiveEnabled = isAutomotiveEnabled()
36+
37+
return remember(isLeanbackEnabled, isAutomotiveEnabled, windowSizeClass) {
38+
selectNavigationComponentType(
39+
isLeanbackEnabled = isLeanbackEnabled,
40+
isAutomotiveEnabled = isAutomotiveEnabled,
41+
isLargeWindow = windowSizeClass.isWidthAtLeastLarge()
42+
)
3943
}
4044
}
4145

46+
// Select the navigation component type based on the available input devices.
4247
private fun selectNavigationComponentType(
43-
formFactor: FormFactor,
48+
isLeanbackEnabled: Boolean,
49+
isAutomotiveEnabled: Boolean,
4450
isLargeWindow: Boolean,
4551
): NavigationComponentType {
46-
return when (formFactor) {
47-
FormFactor.Tv -> NavigationComponentType.Custom
48-
FormFactor.Car -> NavigationComponentType.Custom
49-
else -> {
50-
if (isLargeWindow) {
51-
NavigationComponentType.Custom
52-
} else {
53-
NavigationComponentType.NavigationSuiteScaffold
54-
}
55-
}
52+
return when {
53+
isLeanbackEnabled -> NavigationComponentType.TopBar
54+
isAutomotiveEnabled -> NavigationComponentType.TopBar
55+
isLargeWindow -> NavigationComponentType.TopBar
56+
else -> NavigationComponentType.NavigationSuiteScaffold
5657
}
5758
}

AdaptiveJetStream/jetstream/src/main/java/com/google/jetstream/presentation/app/withTopBarNavigation/TopBar.kt

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,7 @@ import androidx.compose.ui.unit.dp
5151
import com.google.jetstream.data.util.StringConstants
5252
import com.google.jetstream.presentation.app.JetStreamLogo
5353
import com.google.jetstream.presentation.app.UserAvatar
54-
import com.google.jetstream.presentation.components.feature.FormFactor
55-
import com.google.jetstream.presentation.components.feature.rememberUiMode
54+
import com.google.jetstream.presentation.components.feature.isDpadAvailable
5655
import com.google.jetstream.presentation.components.shim.tryRequestFocus
5756
import com.google.jetstream.presentation.screens.Screens
5857

@@ -66,14 +65,12 @@ internal fun TopBar(
6665
val focusManager = LocalFocusManager.current
6766
val (tabRow, avatar) = remember { FocusRequester.createRefs() }
6867

69-
val uiMode = rememberUiMode()
70-
val onClickHandler: (Screens) -> Unit = remember(uiMode) {
71-
when (uiMode.formFactor) {
72-
FormFactor.Tv -> {
73-
{ focusManager.moveFocus(FocusDirection.Down) }
74-
}
75-
76-
else -> { it -> showScreen(it) }
68+
val isDpadAvailable = isDpadAvailable()
69+
val onClickHandler: (Screens) -> Unit = remember(isDpadAvailable) {
70+
if (isDpadAvailable) {
71+
{ focusManager.moveFocus(FocusDirection.Down) }
72+
} else {
73+
{ it -> showScreen(it) }
7774
}
7875
}
7976

AdaptiveJetStream/jetstream/src/main/java/com/google/jetstream/presentation/components/BackButton.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import androidx.compose.material.icons.automirrored.filled.ArrowBack
2121
import androidx.compose.runtime.Composable
2222
import androidx.compose.ui.Modifier
2323
import androidx.compose.ui.graphics.vector.ImageVector
24-
import com.google.jetstream.presentation.components.feature.rememberIsBackButtonRequired
24+
import com.google.jetstream.presentation.components.feature.isBackButtonRequired
2525
import com.google.jetstream.presentation.screens.videoPlayer.components.button.VideoPlayerControlsIcon
2626

2727
@Composable
@@ -45,7 +45,7 @@ fun BackButton(
4545
modifier: Modifier = Modifier,
4646
icon: ImageVector = Icons.AutoMirrored.Filled.ArrowBack,
4747
description: String? = null,
48-
isRequired: Boolean = rememberIsBackButtonRequired()
48+
isRequired: Boolean = isBackButtonRequired()
4949
) {
5050
if (isRequired) {
5151
BackButton(
Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,14 @@
1717
package com.google.jetstream.presentation.components.feature
1818

1919
import androidx.compose.runtime.Composable
20-
import androidx.compose.ui.input.InputMode
21-
import androidx.compose.ui.input.InputModeManager
22-
import androidx.compose.ui.platform.LocalInputModeManager
2320

21+
// This function determines if the back button is required
22+
// so that users can comfortably navigate back to the previous screen when they are using
23+
// the app in the environment without touch screen or hardware back button as d-pad has.
2424
@Composable
25-
fun rememberDpadAvailability(
26-
inputModeManager: InputModeManager = LocalInputModeManager.current
27-
): Boolean {
28-
return inputModeManager.inputMode == InputMode.Keyboard
25+
fun isBackButtonRequired(): Boolean {
26+
return isAutomotiveEnabled() ||
27+
isMouseAvailable() ||
28+
isTouchPadAvailable() ||
29+
isXrSessionAvailable()
2930
}

0 commit comments

Comments
 (0)