chore: cleanup unnecessary createCustomIntialFocusRestorerModifierFactory
Test: not applicable
Change-Id: I196a3bba19b5684a61585488a26a549708fc44f4
diff --git a/tv/integration-tests/playground/src/main/java/androidx/tv/integration/playground/ImmersiveList.kt b/tv/integration-tests/playground/src/main/java/androidx/tv/integration/playground/ImmersiveList.kt
index 94240b6..da94fd9 100644
--- a/tv/integration-tests/playground/src/main/java/androidx/tv/integration/playground/ImmersiveList.kt
+++ b/tv/integration-tests/playground/src/main/java/androidx/tv/integration/playground/ImmersiveList.kt
@@ -24,7 +24,12 @@
import androidx.compose.foundation.lazy.LazyRow
import androidx.compose.foundation.lazy.itemsIndexed
import androidx.compose.runtime.Composable
+import androidx.compose.runtime.remember
+import androidx.compose.ui.ExperimentalComposeUiApi
import androidx.compose.ui.Modifier
+import androidx.compose.ui.focus.FocusRequester
+import androidx.compose.ui.focus.focusRequester
+import androidx.compose.ui.focus.focusRestorer
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.semantics.CollectionItemInfo
import androidx.compose.ui.semantics.collectionItemInfo
@@ -43,7 +48,7 @@
}
}
-@OptIn(ExperimentalTvMaterial3Api::class)
+@OptIn(ExperimentalTvMaterial3Api::class, ExperimentalComposeUiApi::class)
@Composable
private fun SampleImmersiveList() {
val immersiveListHeight = 300.dp
@@ -68,13 +73,13 @@
)
}
) {
- val focusRestorerModifiers = createCustomInitialFocusRestorerModifiers()
+ val focusRequester = remember { FocusRequester() }
LazyRow(
horizontalArrangement = Arrangement.spacedBy(cardSpacing),
modifier = Modifier
.lazyListSemantics(1, backgrounds.count())
- .then(focusRestorerModifiers.parentModifier)
+ .focusRestorer { focusRequester }
) {
itemsIndexed(backgrounds) { index, backgroundColor ->
Card(
@@ -83,7 +88,7 @@
collectionItemInfo = CollectionItemInfo(0, 1, index, 1)
}
.immersiveListItem(index)
- .ifElse(index == 0, focusRestorerModifiers.childModifier),
+ .ifElse(index == 0, Modifier.focusRequester(focusRequester)),
backgroundColor = backgroundColor
)
}
diff --git a/tv/integration-tests/playground/src/main/java/androidx/tv/integration/playground/LazyRowsAndColumns.kt b/tv/integration-tests/playground/src/main/java/androidx/tv/integration/playground/LazyRowsAndColumns.kt
index 20134a5..ed832f8 100644
--- a/tv/integration-tests/playground/src/main/java/androidx/tv/integration/playground/LazyRowsAndColumns.kt
+++ b/tv/integration-tests/playground/src/main/java/androidx/tv/integration/playground/LazyRowsAndColumns.kt
@@ -22,7 +22,11 @@
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
+import androidx.compose.ui.ExperimentalComposeUiApi
import androidx.compose.ui.Modifier
+import androidx.compose.ui.focus.FocusRequester
+import androidx.compose.ui.focus.focusRequester
+import androidx.compose.ui.focus.focusRestorer
import androidx.compose.ui.focus.onFocusChanged
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.semantics.CollectionInfo
@@ -56,22 +60,23 @@
}
}
+@OptIn(ExperimentalComposeUiApi::class)
@Composable
fun SampleLazyRow(modifier: Modifier = Modifier) {
val colors = listOf(Color.Red, Color.Magenta, Color.Green, Color.Yellow, Color.Blue, Color.Cyan)
val backgroundColors = List(columnsCount) { colors.random() }
- val focusRestorerModifiers = createCustomInitialFocusRestorerModifiers()
+ val focusRequester = remember { FocusRequester() }
TvLazyRow(
modifier = modifier
.lazyListSemantics(1, columnsCount)
- .then(focusRestorerModifiers.parentModifier),
+ .focusRestorer { focusRequester },
horizontalArrangement = Arrangement.spacedBy(10.dp)
) {
itemsIndexed(backgroundColors) { index, item ->
Card(
modifier = Modifier
- .ifElse(index == 0, focusRestorerModifiers.childModifier)
+ .ifElse(index == 0, Modifier.focusRequester(focusRequester))
.semantics {
collectionItemInfo = CollectionItemInfo(0, 1, index, 1)
},
diff --git a/tv/integration-tests/playground/src/main/java/androidx/tv/integration/playground/TopNavigation.kt b/tv/integration-tests/playground/src/main/java/androidx/tv/integration/playground/TopNavigation.kt
index f0ed752..f065bb2 100644
--- a/tv/integration-tests/playground/src/main/java/androidx/tv/integration/playground/TopNavigation.kt
+++ b/tv/integration-tests/playground/src/main/java/androidx/tv/integration/playground/TopNavigation.kt
@@ -26,7 +26,11 @@
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
+import androidx.compose.ui.ExperimentalComposeUiApi
import androidx.compose.ui.Modifier
+import androidx.compose.ui.focus.FocusRequester
+import androidx.compose.ui.focus.focusRequester
+import androidx.compose.ui.focus.focusRestorer
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import androidx.tv.material3.ExperimentalTvMaterial3Api
@@ -86,27 +90,25 @@
/**
* Pill indicator tab row for reference
*/
-@OptIn(ExperimentalTvMaterial3Api::class)
+@OptIn(ExperimentalTvMaterial3Api::class, ExperimentalComposeUiApi::class)
@Composable
fun PillIndicatorTabRow(
tabs: List<String>,
selectedTabIndex: Int,
updateSelectedTab: (Int) -> Unit
) {
- val focusRestorerModifiers = createCustomInitialFocusRestorerModifiers()
+ val focusRequester = remember { FocusRequester() }
TabRow(
selectedTabIndex = selectedTabIndex,
- modifier = Modifier
- .then(focusRestorerModifiers.parentModifier)
+ modifier = Modifier.focusRestorer { focusRequester }
) {
tabs.forEachIndexed { index, tab ->
key(index) {
Tab(
selected = index == selectedTabIndex,
onFocus = { updateSelectedTab(index) },
- modifier = Modifier
- .ifElse(index == 0, focusRestorerModifiers.childModifier)
+ modifier = Modifier.ifElse(index == 0, Modifier.focusRequester(focusRequester))
) {
Text(
text = tab,
@@ -122,14 +124,14 @@
/**
* Underlined indicator tab row for reference
*/
-@OptIn(ExperimentalTvMaterial3Api::class)
+@OptIn(ExperimentalTvMaterial3Api::class, ExperimentalComposeUiApi::class)
@Composable
fun UnderlinedIndicatorTabRow(
tabs: List<String>,
selectedTabIndex: Int,
updateSelectedTab: (Int) -> Unit
) {
- val focusRestorerModifiers = createCustomInitialFocusRestorerModifiers()
+ val focusRequester = remember { FocusRequester() }
TabRow(
selectedTabIndex = selectedTabIndex,
@@ -141,14 +143,14 @@
)
},
modifier = Modifier
- .then(focusRestorerModifiers.parentModifier),
+ .focusRestorer { focusRequester },
) {
tabs.forEachIndexed { index, tab ->
Tab(
selected = index == selectedTabIndex,
onFocus = { updateSelectedTab(index) },
modifier = Modifier
- .ifElse(index == 0, focusRestorerModifiers.childModifier),
+ .ifElse(index == 0, Modifier.focusRequester(focusRequester)),
colors = TabDefaults.underlinedIndicatorTabColors(),
) {
Text(
diff --git a/tv/integration-tests/playground/src/main/java/androidx/tv/integration/playground/createCustomInitialFocusRestorerModifiers.kt b/tv/integration-tests/playground/src/main/java/androidx/tv/integration/playground/createCustomInitialFocusRestorerModifiers.kt
deleted file mode 100644
index 3f3acbf..0000000
--- a/tv/integration-tests/playground/src/main/java/androidx/tv/integration/playground/createCustomInitialFocusRestorerModifiers.kt
+++ /dev/null
@@ -1,68 +0,0 @@
-/*
- * Copyright 2023 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package androidx.tv.integration.playground
-
-import androidx.compose.runtime.Composable
-import androidx.compose.runtime.remember
-import androidx.compose.ui.ExperimentalComposeUiApi
-import androidx.compose.ui.Modifier
-import androidx.compose.ui.focus.FocusRequester
-import androidx.compose.ui.focus.focusProperties
-import androidx.compose.ui.focus.focusRequester
-
-/**
- * Assign the parentModifier to the container of items and assign the childModifier to the
- * item that needs to first gain focus. For example, if you want the item at index 0 to get
- * focus for the first time, you can do the following:
- *
- * LazyRow(modifier.then(modifiers.parentModifier) {
- * item1(modifier.then(modifiers.childModifier) {...}
- * item2 {...}
- * item3 {...}
- * ...
- * }
- */
-data class FocusRequesterModifiers(
- val parentModifier: Modifier,
- val childModifier: Modifier
-)
-
-@OptIn(ExperimentalComposeUiApi::class)
-@Composable
-fun createCustomInitialFocusRestorerModifiers(): FocusRequesterModifiers {
- val focusRequester = remember { FocusRequester() }
- val childFocusRequester = remember { FocusRequester() }
-
- val parentModifier = Modifier
- .focusRequester(focusRequester)
- .focusProperties {
- exit = {
- focusRequester.saveFocusedChild()
- FocusRequester.Default
- }
- enter = {
- if (!focusRequester.restoreFocusedChild())
- childFocusRequester
- else
- FocusRequester.Cancel
- }
- }
-
- val childModifier = Modifier.focusRequester(childFocusRequester)
-
- return FocusRequesterModifiers(parentModifier, childModifier)
-}