From 3b74b4a6f50e34dcb3aa61ee7e52a8cea3f19bea Mon Sep 17 00:00:00 2001 From: Niels van Velzen Date: Wed, 9 Oct 2024 21:49:59 +0200 Subject: [PATCH] Inline focusRestorer to AppsTab and remove focusProperties --- .../ui/screen/launcher/LauncherScreen.kt | 18 +++++------------- .../nl/ndat/tvlauncher/ui/tab/apps/AppsTab.kt | 4 ++++ 2 files changed, 9 insertions(+), 13 deletions(-) diff --git a/app/src/main/kotlin/nl/ndat/tvlauncher/ui/screen/launcher/LauncherScreen.kt b/app/src/main/kotlin/nl/ndat/tvlauncher/ui/screen/launcher/LauncherScreen.kt index ee1ba30..932b639 100644 --- a/app/src/main/kotlin/nl/ndat/tvlauncher/ui/screen/launcher/LauncherScreen.kt +++ b/app/src/main/kotlin/nl/ndat/tvlauncher/ui/screen/launcher/LauncherScreen.kt @@ -9,19 +9,15 @@ import androidx.compose.runtime.LaunchedEffect import androidx.compose.runtime.collectAsState import androidx.compose.runtime.getValue 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 -import androidx.compose.ui.focus.focusRestorer import androidx.compose.ui.unit.dp import nl.ndat.tvlauncher.ui.tab.apps.AppsTab import nl.ndat.tvlauncher.ui.tab.home.HomeTab import nl.ndat.tvlauncher.ui.toolbar.Toolbar import org.koin.androidx.compose.koinViewModel -@OptIn(ExperimentalComposeUiApi::class) @Composable fun LauncherScreen() { val viewModel = koinViewModel() @@ -31,10 +27,9 @@ fun LauncherScreen() { modifier = Modifier .fillMaxSize() ) { - val (first, second) = remember { FocusRequester.createRefs() } - - LaunchedEffect(Unit) { - first.requestFocus() + val contentFocusRequester = remember { FocusRequester() } + LaunchedEffect(contentFocusRequester) { + contentFocusRequester.requestFocus() } Toolbar( @@ -43,19 +38,16 @@ fun LauncherScreen() { vertical = 27.dp, horizontal = 48.dp, ) - .focusRequester(second) - .focusProperties { next = first } ) AnimatedContent( targetState = tabIndex, modifier = Modifier - .focusRequester(first) - .focusProperties { next = second }, + .focusRequester(contentFocusRequester), label = "content" ) { tabIndex -> if (tabIndex == 0) HomeTab() - else if (tabIndex == 1) AppsTab(modifier = Modifier.focusRestorer()) + else if (tabIndex == 1) AppsTab() } } } diff --git a/app/src/main/kotlin/nl/ndat/tvlauncher/ui/tab/apps/AppsTab.kt b/app/src/main/kotlin/nl/ndat/tvlauncher/ui/tab/apps/AppsTab.kt index 81ea535..80406c2 100644 --- a/app/src/main/kotlin/nl/ndat/tvlauncher/ui/tab/apps/AppsTab.kt +++ b/app/src/main/kotlin/nl/ndat/tvlauncher/ui/tab/apps/AppsTab.kt @@ -10,11 +10,14 @@ import androidx.compose.foundation.lazy.grid.items import androidx.compose.runtime.Composable import androidx.compose.runtime.collectAsState import androidx.compose.runtime.getValue +import androidx.compose.ui.ExperimentalComposeUiApi import androidx.compose.ui.Modifier +import androidx.compose.ui.focus.focusRestorer import androidx.compose.ui.unit.dp import nl.ndat.tvlauncher.ui.component.card.AppCard import org.koin.androidx.compose.koinViewModel +@OptIn(ExperimentalComposeUiApi::class) @Composable fun AppsTab( modifier: Modifier = Modifier @@ -31,6 +34,7 @@ fun AppsTab( horizontalArrangement = Arrangement.spacedBy(14.dp), columns = GridCells.Adaptive(90.dp * (16f / 9f)), modifier = modifier + .focusRestorer() .fillMaxSize() ) { items(