From fd9761636a06bf7203e46771715f3d875c244949 Mon Sep 17 00:00:00 2001 From: Artem Slinkin Date: Tue, 19 Jul 2022 18:07:25 +0500 Subject: [PATCH 1/2] custom navigations with params --- .../compose/navigation/NavigationGraph.kt | 2 +- .../common/compose/screens/ActionsScreen.kt | 3 +-- .../common/compose/screens/DrawerScreen.kt | 18 ++++++++++++------ .../common/compose/tabs/BottomConfiguration.kt | 3 +-- .../odyssey/compose/RootController.kt | 11 +++++++---- .../odyssey/compose/helpers/FlowBundle.kt | 3 ++- .../BottomNavConfiguration.kt | 2 +- 7 files changed, 25 insertions(+), 17 deletions(-) diff --git a/common/common-compose/src/commonMain/kotlin/ru/alexgladkov/common/compose/navigation/NavigationGraph.kt b/common/common-compose/src/commonMain/kotlin/ru/alexgladkov/common/compose/navigation/NavigationGraph.kt index 81e1067c..9c826757 100644 --- a/common/common-compose/src/commonMain/kotlin/ru/alexgladkov/common/compose/navigation/NavigationGraph.kt +++ b/common/common-compose/src/commonMain/kotlin/ru/alexgladkov/common/compose/navigation/NavigationGraph.kt @@ -47,7 +47,7 @@ fun RootComposeBuilder.topNavScreen() { fun RootComposeBuilder.customNavScreen() { customNavigation(name = "drawer", tabsNavModel = CustomConfiguration( - content = { DrawerScreen() } + content = { params -> DrawerScreen(params) } )) { tab(FeedTab()) { screen(name = "tab") { diff --git a/common/common-compose/src/commonMain/kotlin/ru/alexgladkov/common/compose/screens/ActionsScreen.kt b/common/common-compose/src/commonMain/kotlin/ru/alexgladkov/common/compose/screens/ActionsScreen.kt index e0e63c10..8582abc5 100644 --- a/common/common-compose/src/commonMain/kotlin/ru/alexgladkov/common/compose/screens/ActionsScreen.kt +++ b/common/common-compose/src/commonMain/kotlin/ru/alexgladkov/common/compose/screens/ActionsScreen.kt @@ -9,7 +9,6 @@ import androidx.compose.material.Text import androidx.compose.material.icons.Icons import androidx.compose.material.icons.filled.* import androidx.compose.runtime.Composable -import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.vector.ImageVector import androidx.compose.ui.unit.dp @@ -91,7 +90,7 @@ fun ActionsScreen(count: Int?) { "Show Drawer Navigation", icon = Icons.Filled.DashboardCustomize ) { - rootController.present("drawer") + rootController.present("drawer", params = "Custom Title from params") } } diff --git a/common/common-compose/src/commonMain/kotlin/ru/alexgladkov/common/compose/screens/DrawerScreen.kt b/common/common-compose/src/commonMain/kotlin/ru/alexgladkov/common/compose/screens/DrawerScreen.kt index 7bee1014..038a9beb 100644 --- a/common/common-compose/src/commonMain/kotlin/ru/alexgladkov/common/compose/screens/DrawerScreen.kt +++ b/common/common-compose/src/commonMain/kotlin/ru/alexgladkov/common/compose/screens/DrawerScreen.kt @@ -2,10 +2,7 @@ package ru.alexgladkov.common.compose.screens import androidx.compose.foundation.background import androidx.compose.foundation.clickable -import androidx.compose.foundation.layout.Column -import androidx.compose.foundation.layout.fillMaxSize -import androidx.compose.foundation.layout.fillMaxWidth -import androidx.compose.foundation.layout.height +import androidx.compose.foundation.layout.* import androidx.compose.material.* import androidx.compose.runtime.Composable import androidx.compose.runtime.collectAsState @@ -20,7 +17,7 @@ import ru.alexgladkov.odyssey.compose.controllers.MultiStackRootController import ru.alexgladkov.odyssey.compose.local.LocalRootController @Composable -fun DrawerScreen() { +fun DrawerScreen(params: Any?) { val rootController = LocalRootController.current as MultiStackRootController val tabItem = rootController.stackChangeObserver.collectAsState() val coroutineScope = rememberCoroutineScope() @@ -28,7 +25,7 @@ fun DrawerScreen() { drawerState = rememberDrawerState(DrawerValue.Open) ) - Scaffold ( + Scaffold( scaffoldState = scaffoldState, drawerContent = { Column( @@ -36,6 +33,15 @@ fun DrawerScreen() { .fillMaxSize() .background(color = Color.DarkGray) ) { + params?.toString()?.let { title -> + Text( + modifier = Modifier.height(40.dp).padding(10.dp).fillMaxWidth(), + text = title, + textAlign = TextAlign.Start, + color = Color.White + ) + } + rootController.tabItems.forEach { currentItem -> Text( modifier = Modifier.height(40.dp).fillMaxWidth() diff --git a/common/common-compose/src/commonMain/kotlin/ru/alexgladkov/common/compose/tabs/BottomConfiguration.kt b/common/common-compose/src/commonMain/kotlin/ru/alexgladkov/common/compose/tabs/BottomConfiguration.kt index dd34e99a..a844bbaa 100644 --- a/common/common-compose/src/commonMain/kotlin/ru/alexgladkov/common/compose/tabs/BottomConfiguration.kt +++ b/common/common-compose/src/commonMain/kotlin/ru/alexgladkov/common/compose/tabs/BottomConfiguration.kt @@ -1,7 +1,6 @@ package ru.alexgladkov.common.compose.tabs import androidx.compose.runtime.Composable -import androidx.compose.ui.graphics.Color import ru.alexgladkov.common.compose.theme.Odyssey import ru.alexgladkov.odyssey.compose.navigation.RootComposeBuilder import ru.alexgladkov.odyssey.compose.navigation.bottom_bar_navigation.* @@ -31,7 +30,7 @@ class TopConfiguration : TabsNavModel() { } } -class CustomConfiguration(private val content: @Composable () -> Unit) : +class CustomConfiguration(private val content: @Composable (params: Any?) -> Unit) : TabsNavModel() { override val navConfiguration: CustomNavConfiguration diff --git a/odyssey/odyssey-compose/src/commonMain/kotlin/ru/alexgladkov/odyssey/compose/RootController.kt b/odyssey/odyssey-compose/src/commonMain/kotlin/ru/alexgladkov/odyssey/compose/RootController.kt index 011e8c49..2ad028ca 100644 --- a/odyssey/odyssey-compose/src/commonMain/kotlin/ru/alexgladkov/odyssey/compose/RootController.kt +++ b/odyssey/odyssey-compose/src/commonMain/kotlin/ru/alexgladkov/odyssey/compose/RootController.kt @@ -169,7 +169,8 @@ open class RootController( tabsNavModel = screenType.tabsNavModel, launchFlag = launchFlag, startScreen = startScreen, - startTabPosition = startTabPosition + startTabPosition = startTabPosition, + params = params ) } } @@ -437,7 +438,8 @@ open class RootController( tabsNavModel: TabsNavModel<*>, startScreen: String? = null, startTabPosition: Int = 0, - launchFlag: LaunchFlag? + launchFlag: LaunchFlag?, + params: Any? = null, ) { if (rootControllerType == RootControllerType.Flow || rootControllerType == RootControllerType.MultiStack) throw IllegalStateException("Don't use flow inside flow, call findRootController instead") @@ -474,7 +476,8 @@ open class RootController( animationType = animationType, params = MultiStackBundle( rootController = rootController, - startScreen = startScreen + startScreen = startScreen, + params = params ) ) @@ -512,7 +515,7 @@ open class RootController( TabsNavType.Custom -> { val customNavConfiguration = bundle.rootController.tabsNavModel.navConfiguration as CustomNavConfiguration - customNavConfiguration.content() + customNavConfiguration.content(bundle.params) } } } diff --git a/odyssey/odyssey-compose/src/commonMain/kotlin/ru/alexgladkov/odyssey/compose/helpers/FlowBundle.kt b/odyssey/odyssey-compose/src/commonMain/kotlin/ru/alexgladkov/odyssey/compose/helpers/FlowBundle.kt index d046eb68..705de632 100644 --- a/odyssey/odyssey-compose/src/commonMain/kotlin/ru/alexgladkov/odyssey/compose/helpers/FlowBundle.kt +++ b/odyssey/odyssey-compose/src/commonMain/kotlin/ru/alexgladkov/odyssey/compose/helpers/FlowBundle.kt @@ -13,7 +13,8 @@ data class FlowBundle( data class MultiStackBundle( val startScreen: String?, - val rootController: MultiStackRootController + val rootController: MultiStackRootController, + val params: Any? = null ) data class DeepLinkBundle( diff --git a/odyssey/odyssey-compose/src/commonMain/kotlin/ru/alexgladkov/odyssey/compose/navigation/bottom_bar_navigation/BottomNavConfiguration.kt b/odyssey/odyssey-compose/src/commonMain/kotlin/ru/alexgladkov/odyssey/compose/navigation/bottom_bar_navigation/BottomNavConfiguration.kt index 8577595d..b9fff277 100644 --- a/odyssey/odyssey-compose/src/commonMain/kotlin/ru/alexgladkov/odyssey/compose/navigation/bottom_bar_navigation/BottomNavConfiguration.kt +++ b/odyssey/odyssey-compose/src/commonMain/kotlin/ru/alexgladkov/odyssey/compose/navigation/bottom_bar_navigation/BottomNavConfiguration.kt @@ -47,7 +47,7 @@ data class TopNavConfiguration( } data class CustomNavConfiguration( - val content: @Composable () -> Unit + val content: @Composable (params: Any?) -> Unit ) : TabsNavConfiguration { override val type = TabsNavType.Custom } From cfa38d8bb132e0d5b68d71d1dd8ccc04e82e0608 Mon Sep 17 00:00:00 2001 From: Artem Slinkin Date: Tue, 19 Jul 2022 18:09:40 +0500 Subject: [PATCH 2/2] Version increase --- buildSrc/buildSrc/src/main/kotlin/Dependencies.kt | 2 +- documentation/GETTING_STARTED.md | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/buildSrc/buildSrc/src/main/kotlin/Dependencies.kt b/buildSrc/buildSrc/src/main/kotlin/Dependencies.kt index 3b9fd183..86270ad9 100644 --- a/buildSrc/buildSrc/src/main/kotlin/Dependencies.kt +++ b/buildSrc/buildSrc/src/main/kotlin/Dependencies.kt @@ -1,6 +1,6 @@ object Dependencies { - val odyssey = "1.0.0-beta12" + val odyssey = "1.0.0-beta13" val odysseyPackage = "io.github.alexgladkov" object DI { diff --git a/documentation/GETTING_STARTED.md b/documentation/GETTING_STARTED.md index ae3de722..a0072aac 100644 --- a/documentation/GETTING_STARTED.md +++ b/documentation/GETTING_STARTED.md @@ -4,8 +4,8 @@ Add dependencies to gradle ```kotlin named("commonMain") { dependencies { - implementation("io.github.alexgladkov:odyssey-core:1.0.0-beta12") // For core classes - implementation("io.github.alexgladkov:odyssey-compose:1.0.0-beta12") // For compose extensions + implementation("io.github.alexgladkov:odyssey-core:1.0.0-beta13") // For core classes + implementation("io.github.alexgladkov:odyssey-compose:1.0.0-beta13") // For compose extensions } } ``` \ No newline at end of file