Skip to content

Commit

Permalink
Inline focusRestorer to AppsTab and remove focusProperties
Browse files Browse the repository at this point in the history
  • Loading branch information
nielsvanvelzen committed Oct 9, 2024
1 parent b69db1c commit 3b74b4a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<LauncherScreenViewModel>()
Expand All @@ -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(
Expand All @@ -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()
}
}
}
4 changes: 4 additions & 0 deletions app/src/main/kotlin/nl/ndat/tvlauncher/ui/tab/apps/AppsTab.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -31,6 +34,7 @@ fun AppsTab(
horizontalArrangement = Arrangement.spacedBy(14.dp),
columns = GridCells.Adaptive(90.dp * (16f / 9f)),
modifier = modifier
.focusRestorer()
.fillMaxSize()
) {
items(
Expand Down

0 comments on commit 3b74b4a

Please sign in to comment.