-
Notifications
You must be signed in to change notification settings - Fork 871
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move Home() and TiviContent() to :ui:root
- Loading branch information
1 parent
87b39c1
commit cf60cbb
Showing
7 changed files
with
150 additions
and
104 deletions.
There are no files selected for viewing
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
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
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 |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// Copyright 2023, Google LLC, Christopher Banes and the Tivi project contributors | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
|
||
plugins { | ||
id("app.tivi.android.library") | ||
id("app.tivi.kotlin.multiplatform") | ||
alias(libs.plugins.composeMultiplatform) | ||
} | ||
|
||
android { | ||
namespace = "app.tivi.home" | ||
} | ||
|
||
kotlin { | ||
sourceSets { | ||
val commonMain by getting { | ||
dependencies { | ||
implementation(projects.core.base) | ||
implementation(projects.core.analytics) | ||
implementation(projects.common.ui.compose) | ||
|
||
implementation(projects.common.ui.screens) | ||
implementation(libs.circuit.foundation) | ||
implementation(libs.circuit.overlay) | ||
implementation(projects.common.ui.circuitOverlay) | ||
|
||
implementation(compose.foundation) | ||
implementation(compose.material) | ||
implementation(compose.materialIconsExtended) | ||
implementation(compose.animation) | ||
} | ||
} | ||
} | ||
} |
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
92 changes: 92 additions & 0 deletions
92
ui/root/src/commonMain/kotlin/app/tivi/home/TiviContent.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 |
---|---|---|
@@ -0,0 +1,92 @@ | ||
// Copyright 2023, Christopher Banes and the Tivi project contributors | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package app.tivi.home | ||
|
||
import androidx.compose.material3.windowsizeclass.ExperimentalMaterial3WindowSizeClassApi | ||
import androidx.compose.material3.windowsizeclass.calculateWindowSizeClass | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.CompositionLocalProvider | ||
import androidx.compose.runtime.LaunchedEffect | ||
import androidx.compose.runtime.remember | ||
import androidx.compose.ui.Modifier | ||
import app.tivi.common.compose.LocalWindowSizeClass | ||
import app.tivi.common.compose.shouldUseDarkColors | ||
import app.tivi.common.compose.shouldUseDynamicColors | ||
import app.tivi.common.compose.theme.TiviTheme | ||
import app.tivi.core.analytics.Analytics | ||
import app.tivi.overlays.LocalNavigator | ||
import app.tivi.screens.DiscoverScreen | ||
import app.tivi.screens.SettingsScreen | ||
import app.tivi.screens.TiviScreen | ||
import app.tivi.settings.TiviPreferences | ||
import com.slack.circuit.backstack.SaveableBackStack | ||
import com.slack.circuit.backstack.rememberSaveableBackStack | ||
import com.slack.circuit.foundation.push | ||
import com.slack.circuit.foundation.rememberCircuitNavigator | ||
import com.slack.circuit.foundation.screen | ||
import com.slack.circuit.runtime.Navigator | ||
import com.slack.circuit.runtime.Screen | ||
|
||
@OptIn(ExperimentalMaterial3WindowSizeClassApi::class) | ||
@Composable | ||
fun TiviContent( | ||
onRootPop: () -> Unit, | ||
onOpenSettings: () -> Unit, | ||
analytics: Analytics, | ||
preferences: TiviPreferences, | ||
modifier: Modifier = Modifier, | ||
) { | ||
val backstack: SaveableBackStack = rememberSaveableBackStack { push(DiscoverScreen) } | ||
val circuitNavigator = rememberCircuitNavigator(backstack, onRootPop) | ||
|
||
val navigator: Navigator = remember(circuitNavigator) { | ||
TiviNavigator(circuitNavigator, onOpenSettings) | ||
} | ||
|
||
// Launch an effect to track changes to the current back stack entry, and push them | ||
// as a screen views to analytics | ||
LaunchedEffect(backstack.topRecord) { | ||
val topScreen = backstack.topRecord?.screen as? TiviScreen | ||
analytics.trackScreenView( | ||
name = topScreen?.name ?: "unknown screen", | ||
arguments = topScreen?.arguments, | ||
) | ||
} | ||
|
||
CompositionLocalProvider( | ||
LocalNavigator provides navigator, | ||
LocalWindowSizeClass provides calculateWindowSizeClass(), | ||
) { | ||
TiviTheme( | ||
useDarkColors = preferences.shouldUseDarkColors(), | ||
useDynamicColors = preferences.shouldUseDynamicColors(), | ||
) { | ||
Home( | ||
backstack = backstack, | ||
navigator = navigator, | ||
modifier = modifier, | ||
) | ||
} | ||
} | ||
} | ||
|
||
private class TiviNavigator( | ||
private val navigator: Navigator, | ||
private val onOpenSettings: () -> Unit, | ||
) : Navigator { | ||
override fun goTo(screen: Screen) { | ||
when (screen) { | ||
is SettingsScreen -> onOpenSettings() | ||
else -> navigator.goTo(screen) | ||
} | ||
} | ||
|
||
override fun pop(): Screen? { | ||
return navigator.pop() | ||
} | ||
|
||
override fun resetRoot(newRoot: Screen): List<Screen> { | ||
return navigator.resetRoot(newRoot) | ||
} | ||
} |