Skip to content

Commit

Permalink
Merge remote-tracking branch 'pflammertsma/upstream' into upstream
Browse files Browse the repository at this point in the history
  • Loading branch information
Paul Lammertsma committed Nov 20, 2024
2 parents 8c68712 + e94e1a9 commit ddaa53b
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.focus.FocusRequester
import androidx.compose.ui.graphics.RectangleShape
import androidx.compose.ui.graphics.toArgb
import androidx.compose.ui.unit.LayoutDirection
Expand Down Expand Up @@ -38,15 +39,23 @@ fun App() {
fontScale = fontScale,
) {
MaterialTheme(colorScheme = colorScheme.toColorScheme()) {
val themeFocus = remember { FocusRequester() }
val fontFocus = remember { FocusRequester() }
ThemeAndColorModeSelector(
isExpanded = isThemeSelectorExpanded,
onClose = { isThemeSelectorExpanded = false },
onClose = {
isThemeSelectorExpanded = false
themeFocus.requestFocus()
},
onSeedColorChange = { seedColor = it },
onThemeModeChange = { themeMode = it },
) {
FontScaleAndLayoutDirectionSelector(
isExpanded = isFontScaleSelectorExpanded,
onClose = { isFontScaleSelectorExpanded = false },
onClose = {
isFontScaleSelectorExpanded = false
fontFocus.requestFocus()
},
onLayoutDirectionChange = { layoutDirection = it },
onFontScaleChange = { fontScale = it }
) {
Expand All @@ -56,6 +65,7 @@ fun App() {
) {
Column(Modifier.fillMaxSize()) {
NavigationGraph(
themeFocus, fontFocus,
onThemeColorModeClick = {
isThemeSelectorExpanded = true
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.google.tv.material.catalog

import androidx.compose.foundation.background
import androidx.compose.foundation.focusGroup
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
Expand All @@ -15,6 +16,8 @@ import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.focus.FocusRequester
import androidx.compose.ui.focus.focusRequester
import androidx.compose.ui.graphics.painter.Painter
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
Expand All @@ -29,6 +32,8 @@ import androidx.tv.material3.Text

@Composable
fun AppBar(
themeFocus: FocusRequester,
fontFocus: FocusRequester,
onThemeColorModeClick: () -> Unit,
onFontScaleClick: () -> Unit
) {
Expand Down Expand Up @@ -58,8 +63,9 @@ fun AppBar(
isMainIconMagnified = isMainIconMagnified
)
Actions(
themeFocus, fontFocus,
onThemeColorModeClick = onThemeColorModeClick,
onFontScaleClick = onFontScaleClick,
onFontScaleClick = onFontScaleClick
)
}
}
Expand Down Expand Up @@ -112,28 +118,37 @@ private fun HeadlineContent(

@Composable
private fun Actions(
themeFocus: FocusRequester,
fontFocus: FocusRequester,
onThemeColorModeClick: () -> Unit,
onFontScaleClick: () -> Unit,
) {
val actions = listOf(
Action(
iconPainter = painterResource(id = R.drawable.ic_palette),
text = "Theme & color mode",
onClick = onThemeColorModeClick
onClick = onThemeColorModeClick,
focusRequester = themeFocus
),
Action(
iconPainter = painterResource(id = R.drawable.ic_font),
text = "Font scale",
onClick = onFontScaleClick
onClick = onFontScaleClick,
focusRequester = fontFocus
)
)

Row(
horizontalArrangement = Arrangement.spacedBy(16.dp),
modifier = Modifier.padding(end = 8.dp)
modifier = Modifier
.padding(end = 8.dp)
.focusGroup()
) {
actions.forEach {
Button(onClick = it.onClick) {
Button(
modifier = Modifier.focusRequester(it.focusRequester),
onClick = it.onClick
) {
Icon(
modifier = Modifier.size(16.dp),
painter = it.iconPainter,
Expand All @@ -153,4 +168,5 @@ private data class Action(
val iconPainter: Painter,
val text: String,
val onClick: () -> Unit,
val focusRequester: FocusRequester
)
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.google.tv.material.catalog

import androidx.activity.compose.BackHandler
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
Expand Down Expand Up @@ -52,6 +53,10 @@ fun FontScaleAndLayoutDirectionSelector(
}
}

BackHandler(enabled = isExpanded) {
onClose()
}

Box(modifier = Modifier.fillMaxSize()) {
content()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.runtime.Composable
import androidx.compose.runtime.compositionLocalOf
import androidx.compose.ui.focus.FocusRequester
import androidx.navigation.NavHostController
import androidx.navigation.compose.NavHost
import androidx.navigation.compose.composable
Expand All @@ -22,6 +23,8 @@ import com.google.tv.material.catalog.screens.WorkInProgressScreen

@Composable
fun NavigationGraph(
themeFocus: FocusRequester,
fontFocus: FocusRequester,
onThemeColorModeClick: () -> Unit,
onFontScaleClick: () -> Unit
) {
Expand All @@ -31,6 +34,7 @@ fun NavigationGraph(
composable(destination.routeName) {
destination.composable {
AppBar(
themeFocus, fontFocus,
onThemeColorModeClick = onThemeColorModeClick,
onFontScaleClick = onFontScaleClick
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.google.tv.material.catalog

import androidx.activity.compose.BackHandler
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
Expand Down Expand Up @@ -51,6 +52,10 @@ fun ThemeAndColorModeSelector(
}
}

BackHandler(enabled = isExpanded) {
onClose()
}

Box(modifier = Modifier.fillMaxSize()) {
content()

Expand Down

0 comments on commit ddaa53b

Please sign in to comment.