@@ -25,15 +25,20 @@ import androidx.compose.foundation.focusable
2525import androidx.compose.foundation.interaction.FocusInteraction
2626import androidx.compose.foundation.interaction.InteractionSource
2727import androidx.compose.foundation.interaction.MutableInteractionSource
28+ import androidx.compose.foundation.layout.Arrangement
2829import androidx.compose.foundation.layout.Box
2930import androidx.compose.foundation.layout.Column
3031import androidx.compose.foundation.layout.Row
3132import androidx.compose.foundation.layout.fillMaxSize
33+ import androidx.compose.foundation.lazy.LazyColumn
3234import androidx.compose.foundation.lazy.grid.GridCells
3335import androidx.compose.foundation.lazy.grid.GridItemSpan
3436import androidx.compose.foundation.lazy.grid.LazyVerticalGrid
37+ import androidx.compose.foundation.lazy.items
3538import androidx.compose.material3.Button
3639import androidx.compose.material3.Card
40+ import androidx.compose.material3.ListItem
41+ import androidx.compose.material3.MaterialTheme
3742import androidx.compose.material3.Switch
3843import androidx.compose.material3.Text
3944import androidx.compose.material3.TextButton
@@ -52,10 +57,13 @@ import androidx.compose.ui.focus.FocusDirection.Companion.Right
5257import androidx.compose.ui.focus.FocusRequester
5358import androidx.compose.ui.focus.FocusRequester.Companion.Cancel
5459import androidx.compose.ui.focus.FocusRequester.Companion.Default
60+ import androidx.compose.ui.focus.FocusRequester.Companion.FocusRequesterFactory.component1
61+ import androidx.compose.ui.focus.FocusRequester.Companion.FocusRequesterFactory.component2
62+ import androidx.compose.ui.focus.FocusRequester.Companion.FocusRequesterFactory.component3
63+ import androidx.compose.ui.focus.FocusRequester.Companion.FocusRequesterFactory.component4
5564import androidx.compose.ui.focus.focusProperties
5665import androidx.compose.ui.focus.focusRequester
5766import androidx.compose.ui.focus.onFocusChanged
58- import androidx.compose.ui.graphics.Color
5967import androidx.compose.ui.graphics.Color.Companion.Blue
6068import androidx.compose.ui.graphics.Color.Companion.Green
6169import androidx.compose.ui.graphics.Color.Companion.Red
@@ -70,10 +78,68 @@ import androidx.compose.ui.node.DelegatableNode
7078import androidx.compose.ui.node.DrawModifierNode
7179import androidx.compose.ui.node.invalidateDraw
7280import androidx.compose.ui.platform.LocalFocusManager
81+ import androidx.compose.ui.text.TextStyle
7382import androidx.compose.ui.tooling.preview.Preview
7483import androidx.compose.ui.unit.dp
84+ import com.example.compose.snippets.navigation.FocusExamplesDestination
7585import kotlinx.coroutines.launch
7686
87+ @Composable
88+ fun FocusExamples (
89+ modifier : Modifier = Modifier ,
90+ onNavigation : (FocusExamplesDestination ) -> Unit = {}
91+ ) {
92+ LazyColumn (
93+ verticalArrangement = Arrangement .spacedBy(8 .dp),
94+ modifier = modifier
95+ ) {
96+ items(FocusExamplesDestination .entries.toList()) {
97+ ListItem (
98+ modifier = Modifier .clickable(onClick = {
99+ onNavigation(it)
100+ }),
101+ headlineContent = {
102+ Text (it.title)
103+ }
104+ )
105+ }
106+ }
107+ }
108+
109+ @Composable
110+ internal fun Section (
111+ title : String ,
112+ modifier : Modifier = Modifier ,
113+ verticalArrangement : Arrangement .Vertical = Arrangement .spacedBy(16.dp),
114+ style : TextStyle = MaterialTheme .typography.headlineMedium,
115+ content : @Composable () -> Unit = {}
116+ ) {
117+ Column (
118+ modifier = modifier.focusGroup(),
119+ verticalArrangement = verticalArrangement
120+ ) {
121+ Text (title, style = style)
122+ content()
123+ }
124+ }
125+
126+ @Composable
127+ internal fun SubSection (
128+ title : String ,
129+ modifier : Modifier = Modifier ,
130+ verticalArrangement : Arrangement .Vertical = Arrangement .spacedBy(8.dp),
131+ style : TextStyle = MaterialTheme .typography.headlineSmall,
132+ content : @Composable () -> Unit = {}
133+ ) {
134+ Section (
135+ title = title,
136+ modifier = modifier,
137+ verticalArrangement = verticalArrangement,
138+ style = style,
139+ content = content,
140+ )
141+ }
142+
77143@Preview
78144@Composable
79145private fun BasicSample () {
@@ -276,7 +342,7 @@ private fun RequestFocus() {
276342}
277343
278344@Composable
279- private fun RequestFocus2 () {
345+ internal fun RequestFocus2 () {
280346 // [START android_compose_touchinput_focus_request2]
281347 val focusRequester = remember { FocusRequester () }
282348 var text by remember { mutableStateOf(" " ) }
@@ -382,7 +448,7 @@ private fun ModifierOrder2() {
382448
383449@OptIn(ExperimentalComposeUiApi ::class )
384450@Composable
385- private fun RedirectFocus () {
451+ private fun FocusRedirection () {
386452 // [START android_compose_touchinput_focus_redirect]
387453 val otherComposable = remember { FocusRequester () }
388454
@@ -399,7 +465,7 @@ private fun RedirectFocus() {
399465}
400466
401467@Composable
402- private fun FocusAdvancing () {
468+ internal fun FocusAdvancing () {
403469 // [START android_compose_touchinput_focus_advancing]
404470 val focusManager = LocalFocusManager .current
405471 var text by remember { mutableStateOf(" " ) }
@@ -424,7 +490,7 @@ private fun FocusAdvancing() {
424490@Composable
425491private fun ReactToFocus () {
426492 // [START android_compose_touchinput_focus_react]
427- var color by remember { mutableStateOf(Color . White ) }
493+ var color by remember { mutableStateOf(White ) }
428494 Card (
429495 modifier = Modifier
430496 .onFocusChanged {
@@ -460,7 +526,7 @@ private class MyHighlightIndicationNode(private val interactionSource: Interacti
460526 override fun ContentDrawScope.draw () {
461527 drawContent()
462528 if (isFocused) {
463- drawRect(size = size, color = Color . White , alpha = 0.2f )
529+ drawRect(size = size, color = White , alpha = 0.2f )
464530 }
465531 }
466532}
0 commit comments