Skip to content

Commit

Permalink
Refactor platform screen and unwrap extra android nav controller
Browse files Browse the repository at this point in the history
  • Loading branch information
vkatz committed May 28, 2024
1 parent e76bf09 commit bec82a8
Show file tree
Hide file tree
Showing 13 changed files with 95 additions and 159 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import androidx.activity.compose.setContent
import androidx.activity.enableEdgeToEdge
import androidx.compose.runtime.DisposableEffect
import com.composegears.tiamat.navigationFadeInOut
import composegears.tiamat.example.common.PlatformExampleScreen
import composegears.tiamat.example.platform.DeeplinkScreen

class MainActivity : ComponentActivity() {

Expand All @@ -18,7 +18,7 @@ class MainActivity : ComponentActivity() {
super.onCreate(savedInstanceState)
deepLinkController.onIntent(intent)
setContent {
App { rootNavController ->
App { rootNavController, content ->
// pass deeplink deeper and handle inside screen
val deeplink = deepLinkController.deeplink
// using disposable effect as it runs faster then LaunchedEffect
Expand All @@ -27,9 +27,10 @@ class MainActivity : ComponentActivity() {
rootNavController.editBackStack {
clear()
add(MainScreen)
add(PlatformExamplesScreen)
}
rootNavController.replace(
dest = PlatformExampleScreen,
dest = DeeplinkScreen,
freeArgs = deeplink,
// we only animate root content switch
// all nested items should use navigationNone() transition to prevent `blink`
Expand All @@ -39,6 +40,7 @@ class MainActivity : ComponentActivity() {
}
onDispose { }
}
content()
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package composegears.tiamat.example

import composegears.tiamat.example.PlatformConfig.PlatformDestination
import composegears.tiamat.example.platform.AndroidViewLifecycleScreen
import composegears.tiamat.example.platform.DeeplinkScreen
import composegears.tiamat.example.platform.SavedStateScreen
import composegears.tiamat.sample.koin.KoinIntegrationScreen

actual val platformExamplesConfig = PlatformConfig(
platformName = "Android",
availableScreens = listOf(
PlatformDestination(
name = "Android SavedState",
destination = SavedStateScreen
),
PlatformDestination(
name = "AndroidView + Lifecycle handle",
destination = AndroidViewLifecycleScreen
),
PlatformDestination(
name = "Deeplink",
destination = DeeplinkScreen
),
PlatformDestination(
name = "Koin (ViewModel/SharedViewModel)",
destination = KoinIntegrationScreen
)
)
)

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,19 @@ import com.composegears.tiamat.NavController
import com.composegears.tiamat.Navigation
import com.composegears.tiamat.StorageMode
import com.composegears.tiamat.rememberNavController
import composegears.tiamat.example.common.PlatformExampleScreen
import composegears.tiamat.example.multimodule.MultiModuleRoot
import composegears.tiamat.example.ui.core.AppTheme

@Composable
fun App(configure: @Composable (NavController) -> Unit = {}) {
@Suppress("SpreadOperator")
fun App(
configure: @Composable (
NavController,
@Composable () -> Unit
) -> Unit = { _, content ->
content()
}
) {
AppTheme {
Surface {
val rootNavController = rememberNavController(
Expand Down Expand Up @@ -46,14 +53,16 @@ fun App(configure: @Composable (NavController) -> Unit = {}) {
MultiModuleRoot,
BackStackAlterationRoot,
TwoPaneResizableRoot,
PlatformExampleScreen
PlatformExamplesScreen,
*platformExamplesConfig.destinations()
)
)
configure(rootNavController)
Navigation(
navController = rootNavController,
modifier = Modifier.fillMaxSize().systemBarsPadding()
)
configure(rootNavController) {
Navigation(
navController = rootNavController,
modifier = Modifier.fillMaxSize().systemBarsPadding()
)
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import com.composegears.tiamat.navController
import com.composegears.tiamat.navDestination
import composegears.tiamat.example.common.PlatformExampleScreen
import composegears.tiamat.example.multimodule.MultiModuleRoot

val MainScreen by navDestination<Unit> {
Expand All @@ -33,7 +32,7 @@ val MainScreen by navDestination<Unit> {
"Multi-module" to { navController.navigate(MultiModuleRoot) },
"Back stack alteration" to { navController.navigate(BackStackAlterationRoot) },
"2 Pane (list + detail, resizable)" to { navController.navigate(TwoPaneResizableRoot) },
"Platform specific" to { navController.navigate(PlatformExampleScreen) }
"Platform specific" to { navController.navigate(PlatformExamplesScreen) }
)
}
Box(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package composegears.tiamat.example.common
package composegears.tiamat.example

import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.PaddingValues
Expand All @@ -18,16 +18,19 @@ import com.composegears.tiamat.NavDestination
import com.composegears.tiamat.navController
import com.composegears.tiamat.navDestination
import composegears.tiamat.example.ui.core.SimpleScreen
import composegears.tiamat.example.ui.core.TextCaption

val PlatformScreen by navDestination<Unit> {
val PlatformExamplesScreen by navDestination<Unit> {
val navController = navController()

SimpleScreen("Platform ${platformConfig.platformName}") {
LazyColumn(
SimpleScreen("Platform ${platformExamplesConfig.platformName}") {
if (platformExamplesConfig.availableScreens.isEmpty()) {
TextCaption("Nothing platform specific yet")
} else LazyColumn(
contentPadding = PaddingValues(24.dp),
verticalArrangement = Arrangement.spacedBy(4.dp)
) {
items(platformConfig.availableScreens) { (name, screen) ->
items(platformExamplesConfig.availableScreens) { (name, screen) ->
Button(
modifier = Modifier.widthIn(max = 450.dp),
onClick = {
Expand All @@ -45,8 +48,7 @@ val PlatformScreen by navDestination<Unit> {
}
}

expect val PlatformExampleScreen: NavDestination<Unit>
expect val platformConfig: PlatformConfig
expect val platformExamplesConfig: PlatformConfig

class PlatformConfig(
val platformName: String,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package composegears.tiamat.example

import composegears.tiamat.example.PlatformConfig.PlatformDestination
import composegears.tiamat.sample.koin.KoinIntegrationScreen

actual val platformExamplesConfig = PlatformConfig(
platformName = "Desktop",
availableScreens = listOf(
PlatformDestination(
name = "Koin (ViewModel/SharedViewModel)",
destination = KoinIntegrationScreen
)
)
)

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package composegears.tiamat.example

import composegears.tiamat.sample.koin.KoinIntegrationScreen

actual val platformExamplesConfig = PlatformConfig(
platformName = "iOS",
availableScreens = listOf(
PlatformConfig.PlatformDestination(
name = "Koin (ViewModel/SharedViewModel)",
destination = KoinIntegrationScreen
)
)
)

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package composegears.tiamat.example

actual val platformExamplesConfig = PlatformConfig(
platformName = "Wasm",
availableScreens = emptyList()
)

This file was deleted.

2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ android.nonTransitiveRClass=true
android.useAndroidX=true

#MPP
kotlin.mpp.androidSourceSetLayoutVersion=2
kotlin.mpp.enableCInteropCommonization=true
kotlin.native.ignoreDisabledTargets=true

#WASM
org.jetbrains.compose.experimental.wasm.enabled=true
Expand Down

0 comments on commit bec82a8

Please sign in to comment.