-
-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
602b3a5
commit 01bdd2f
Showing
3 changed files
with
28 additions
and
16 deletions.
There are no files selected for viewing
26 changes: 17 additions & 9 deletions
26
app/src/main/kotlin/nl/ndat/tvlauncher/ui/screen/launcher/LauncherScreen.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,53 +1,61 @@ | ||
package nl.ndat.tvlauncher.ui.screen.launcher | ||
|
||
import androidx.compose.animation.AnimatedContent | ||
import androidx.compose.foundation.focusGroup | ||
import androidx.compose.foundation.layout.Column | ||
import androidx.compose.foundation.layout.fillMaxSize | ||
import androidx.compose.foundation.layout.padding | ||
import androidx.compose.runtime.Composable | ||
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>() | ||
val tabIndex by viewModel.tabIndex.collectAsState() | ||
|
||
val contentFocusRequester = remember { FocusRequester() } | ||
|
||
Column( | ||
modifier = Modifier | ||
.fillMaxSize() | ||
// TODO This focus restorer somehow disallows focus going to the toolbar | ||
// .focusRestorer { contentFocusRequester } | ||
) { | ||
val (first, second) = remember { FocusRequester.createRefs() } | ||
|
||
LaunchedEffect(Unit) { | ||
first.requestFocus() | ||
} | ||
|
||
Toolbar( | ||
modifier = Modifier | ||
.padding( | ||
vertical = 27.dp, | ||
horizontal = 48.dp, | ||
) | ||
.focusRequester(second) | ||
.focusProperties { next = first } | ||
) | ||
|
||
AnimatedContent( | ||
targetState = tabIndex, | ||
modifier = Modifier | ||
.focusGroup() | ||
.focusRequester(contentFocusRequester), | ||
.focusRequester(first) | ||
.focusProperties { next = second }, | ||
label = "content" | ||
) { tabIndex -> | ||
if (tabIndex == 0) HomeTab() | ||
else if (tabIndex == 1) AppsTab() | ||
if (tabIndex == 0) HomeTab(modifier = Modifier.focusRestorer()) | ||
else if (tabIndex == 1) AppsTab(modifier = Modifier.focusRestorer()) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters