Skip to content

Commit

Permalink
feat: multi-module navigation
Browse files Browse the repository at this point in the history
  • Loading branch information
adrielcafe committed Aug 24, 2021
1 parent c39c80a commit b71b0c9
Show file tree
Hide file tree
Showing 29 changed files with 123 additions and 98 deletions.
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<h1 align="center">
<img height="150" src="https://user-images.githubusercontent.com/2512298/127723355-f56b3040-47cb-44fd-8504-a1868721c1a3.png"/>
<br>
<a href="https://en.wikipedia.org/wiki/USS_Voyager_(Star_Trek)">Voyager</a>: Compose on Warp Speed
<a href="https://voyager.adriel.cafe">Voyager</a>: Compose on Warp Speed
</h1>

A lightweight and pragmatic navigation library built for, and seamlessly integrated with, [Jetpack Compose](https://developer.android.com/jetpack/compose).
Expand All @@ -19,7 +19,7 @@ class HomeScreen : Screen {

@Composable
override fun Content() {
// ...
// Your awesome UI goes here
}
}

Expand All @@ -43,7 +43,7 @@ See the [project website](https://voyager.adriel.cafe) for documentation and API
- [Tab navigation](https://voyager.adriel.cafe/navigation/tab-navigation) like [Youtube app](https://play.google.com/store/apps/details?id=com.google.android.youtube)
- [Nested navigation](https://voyager.adriel.cafe/navigation/nested-navigation) if you need to manage multiple stacks
- [State restoration](https://voyager.adriel.cafe/state-restoration) after Activity recreation
- [Multi-module navigation](https://voyager.adriel.cafe/navigation/multi-module-navigation) based on Dependency Injection
- Type-safe [multi-module navigation](https://voyager.adriel.cafe/navigation/multi-module-navigation)
- State-aware [Stack API](https://voyager.adriel.cafe/stack-api)
- Built-in [transitions](https://voyager.adriel.cafe/transitions)
- Pluggable [hooks](https://voyager.adriel.cafe/hooks)
Expand All @@ -55,10 +55,10 @@ See the [project website](https://voyager.adriel.cafe) for documentation and API
- [Compose for Desktop](https://github.com/JetBrains/compose-jb) support

### Samples
| [Stack API](https://github.com/adrielcafe/voyager/tree/main/sample/src/main/java/cafe/adriel/voyager/sample/stateStack) | [AndroidX ViewModel](https://github.com/adrielcafe/voyager/tree/main/sample/src/main/java/cafe/adriel/voyager/sample/androidNavigation) | [Multi-module nav.](https://github.com/adrielcafe/voyager/tree/main/sample-multi-module) |
| [Stack API](https://github.com/adrielcafe/voyager/tree/main/sample/src/main/java/cafe/adriel/voyager/sample/stateStack) | [AndroidX ViewModel](https://github.com/adrielcafe/voyager/tree/main/sample/src/main/java/cafe/adriel/voyager/sample/androidNavigation) | [Basic nav.](https://github.com/adrielcafe/voyager/tree/main/sample/src/main/java/cafe/adriel/voyager/sample/basicNavigation) |
|------------|----------|-------------|
| ![navigation-stack](https://user-images.githubusercontent.com/2512298/126323192-9b6349fe-7b96-4acf-b62e-c75165d909e1.gif) | ![navigation-androidx](https://user-images.githubusercontent.com/2512298/130377801-c350b4f5-bcca-4d28-9403-0d9d4c1e99f7.gif) | ![navigation-multi-module](https://user-images.githubusercontent.com/2512298/130377815-fca83cf6-c90b-49fc-81ea-1ea9081f1086.gif) |
| ![navigation-stack](https://user-images.githubusercontent.com/2512298/126323192-9b6349fe-7b96-4acf-b62e-c75165d909e1.gif) | ![navigation-androidx](https://user-images.githubusercontent.com/2512298/130377801-c350b4f5-bcca-4d28-9403-0d9d4c1e99f7.gif) | ![navigation-basic](https://user-images.githubusercontent.com/2512298/126323165-47760eec-2ba2-48ee-8e3a-841d50098d33.gif) |

| [Basic nav.](https://github.com/adrielcafe/voyager/tree/main/sample/src/main/java/cafe/adriel/voyager/sample/basicNavigation) | [Tab nav.](https://github.com/adrielcafe/voyager/tree/main/sample/src/main/java/cafe/adriel/voyager/sample/tabNavigation) | [Nested nav.](https://github.com/adrielcafe/voyager/tree/main/sample/src/main/java/cafe/adriel/voyager/sample/nestedNavigation) |
| [Tab nav.](https://github.com/adrielcafe/voyager/tree/main/sample/src/main/java/cafe/adriel/voyager/sample/tabNavigation) | [Multi-module nav.](https://github.com/adrielcafe/voyager/tree/main/sample-multi-module) | [Nested nav.](https://github.com/adrielcafe/voyager/tree/main/sample/src/main/java/cafe/adriel/voyager/sample/nestedNavigation) |
|------------|----------|-------------|
| ![navigation-basic](https://user-images.githubusercontent.com/2512298/126323165-47760eec-2ba2-48ee-8e3a-841d50098d33.gif) | ![navigation-tab](https://user-images.githubusercontent.com/2512298/126323588-2f970953-0adb-47f8-b2fb-91c5854656bd.gif) | ![navigation-nested](https://user-images.githubusercontent.com/2512298/126323027-a2633aef-9402-4df8-9384-45935d7986cf.gif) |
| ![navigation-tab](https://user-images.githubusercontent.com/2512298/126323588-2f970953-0adb-47f8-b2fb-91c5854656bd.gif) | ![navigation-multi-module](https://user-images.githubusercontent.com/2512298/130662717-c15caf88-350e-42a0-837c-3453805b68f2.gif) | ![navigation-nested](https://user-images.githubusercontent.com/2512298/126323027-a2633aef-9402-4df8-9384-45935d7986cf.gif) |
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ kotlin.code.style=official

# Maven
GROUP=cafe.adriel.voyager
VERSION_NAME=1.0.0-beta06
VERSION_NAME=1.0.0-beta07

POM_DESCRIPTION=A pragmatic navigation library for Jetpack Compose
POM_INCEPTION_YEAR=2021
Expand Down
4 changes: 0 additions & 4 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@ plugin-ktlint = "10.1.0"
plugin-maven = "0.17.0"

kotlin = "1.5.21"
kodein = "7.7.0"
koin = "3.1.2"

appCompat = "1.3.1"
compose = "1.0.1"
composeActivity = "1.3.0"
Expand All @@ -20,9 +18,7 @@ plugin-kotlin = { module = "org.jetbrains.kotlin:kotlin-gradle-plugin", version.
plugin-ktlint = { module = "org.jlleitschuh.gradle:ktlint-gradle", version.ref = "plugin-ktlint" }
plugin-maven = { module = "com.vanniktech:gradle-maven-publish-plugin", version.ref = "plugin-maven" }

kodein = { module = "org.kodein.di:kodein-di-framework-compose", version.ref = "kodein" }
koin = { module = "io.insert-koin:koin-androidx-compose", version.ref = "koin" }

appCompat = { module = "androidx.appcompat:appcompat", version.ref = "appCompat" }
compose-compiler = { module = "androidx.compose.compiler:compiler", version.ref = "compose" }
compose-runtime = { module = "androidx.compose.runtime:runtime", version.ref = "compose" }
Expand Down
5 changes: 2 additions & 3 deletions sample-multi-module/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,9 @@ android {
dependencies {
implementation projects.voyagerNavigator

implementation projects.sampleMultiModule.featureA
implementation projects.sampleMultiModule.featureB
implementation projects.sampleMultiModule.featureHome
implementation projects.sampleMultiModule.featurePosts

implementation libs.kodein
implementation libs.appCompat
implementation libs.compose.compiler
implementation libs.compose.runtime
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import cafe.adriel.voyager.navigator.Navigator
import cafe.adriel.voyager.sample.multimodule.featurea.FeatureAScreen
import cafe.adriel.voyager.sample.multimodule.home.HomeScreen

class SampleActivity : ComponentActivity() {

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)

setContent {
Navigator(FeatureAScreen())
Navigator(HomeScreen())
}
}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
package cafe.adriel.voyager.sample.multimodule

import android.app.Application
import cafe.adriel.voyager.sample.multimodule.featureb.featureBModule
import org.kodein.di.DI
import org.kodein.di.DIAware
import cafe.adriel.voyager.core.registry.ScreenRegistry
import cafe.adriel.voyager.sample.multimodule.posts.featurePostsScreenModule

class SampleApp : Application(), DIAware {
class SampleApp : Application() {

override val di by DI.lazy {
importAll(featureBModule)
override fun onCreate() {
super.onCreate()

ScreenRegistry {
featurePostsScreenModule()
}
}
}
2 changes: 0 additions & 2 deletions sample-multi-module/feature-a/src/main/AndroidManifest.xml

This file was deleted.

2 changes: 0 additions & 2 deletions sample-multi-module/feature-b/src/main/AndroidManifest.xml

This file was deleted.

This file was deleted.

File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,9 @@ android
dependencies {
implementation projects.voyagerNavigator

implementation projects.sampleMultiModule.shared
implementation projects.sampleMultiModule.navigation

implementation libs.kodein
implementation libs.appCompat
implementation libs.compose.compiler
implementation libs.compose.runtime
implementation libs.compose.activity
implementation libs.compose.material
}
2 changes: 2 additions & 0 deletions sample-multi-module/feature-home/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest package="cafe.adriel.voyager.sample.multimodule.home"/>
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package cafe.adriel.voyager.sample.multimodule.featurea
package cafe.adriel.voyager.sample.multimodule.home

import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
Expand All @@ -12,52 +12,52 @@ import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import cafe.adriel.voyager.core.registry.rememberScreen
import cafe.adriel.voyager.core.screen.Screen
import cafe.adriel.voyager.navigator.LocalNavigator
import cafe.adriel.voyager.navigator.currentOrThrow
import cafe.adriel.voyager.sample.multimodule.shared.SharedFeatureBParamScreen
import cafe.adriel.voyager.sample.multimodule.shared.SharedFeatureBScreen
import org.kodein.di.compose.rememberInstance
import cafe.adriel.voyager.sample.multimodule.navigation.SharedScreen
import java.util.UUID

class FeatureAScreen : Screen {
class HomeScreen : Screen {

private val randomId: String
get() = UUID.randomUUID().toString()

@Composable
override fun Content() {
val navigator = LocalNavigator.currentOrThrow
val sharedFeatureBScreen: SharedFeatureBScreen by rememberInstance()
val sharedFeatureBParamScreen: SharedFeatureBParamScreen by rememberInstance(
arg = SharedFeatureBParamScreen.Params(message = UUID.randomUUID().toString())
)
val postListScreen = rememberScreen(SharedScreen.PostList)
val postDetailsScreen = rememberScreen(SharedScreen.PostDetails(id = randomId))

Column(
verticalArrangement = Arrangement.Center,
horizontalAlignment = Alignment.CenterHorizontally,
modifier = Modifier.fillMaxSize()
) {
Text(
text = "Feature A",
text = "Home",
style = MaterialTheme.typography.h5
)

Spacer(modifier = Modifier.height(16.dp))

Button(
onClick = { navigator.push(sharedFeatureBScreen) }
onClick = { navigator.push(postListScreen) }
) {
Text(
text = "To Feature B without param",
text = "To Post List",
style = MaterialTheme.typography.button
)
}

Spacer(modifier = Modifier.height(16.dp))

Button(
onClick = { navigator.push(sharedFeatureBParamScreen) }
onClick = { navigator.push(postDetailsScreen) }
) {
Text(
text = "To Feature B with param",
text = "To Post Details",
style = MaterialTheme.typography.button
)
}
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,9 @@ android
dependencies {
implementation projects.voyagerNavigator

implementation projects.sampleMultiModule.shared
implementation projects.sampleMultiModule.navigation

implementation libs.kodein
implementation libs.appCompat
implementation libs.compose.compiler
implementation libs.compose.runtime
implementation libs.compose.activity
implementation libs.compose.material
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest package="cafe.adriel.voyager.sample.multimodule.posts"/>
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package cafe.adriel.voyager.sample.multimodule.featureb
package cafe.adriel.voyager.sample.multimodule.posts

import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
Expand All @@ -15,11 +15,10 @@ import androidx.compose.ui.unit.dp
import cafe.adriel.voyager.core.screen.Screen
import cafe.adriel.voyager.navigator.LocalNavigator
import cafe.adriel.voyager.navigator.currentOrThrow
import cafe.adriel.voyager.sample.multimodule.shared.SharedFeatureBParamScreen

data class FeatureBParamScreen(
override val params: SharedFeatureBParamScreen.Params
) : SharedFeatureBParamScreen, Screen {
data class DetailsScreen(
val id: String
) : Screen {

@Composable
override fun Content() {
Expand All @@ -31,14 +30,14 @@ data class FeatureBParamScreen(
modifier = Modifier.fillMaxSize()
) {
Text(
text = "Feature B with param",
text = "Post Details",
style = MaterialTheme.typography.h5
)

Spacer(modifier = Modifier.height(16.dp))

Text(
text = params.message,
text = "ID: $id",
style = MaterialTheme.typography.body1
)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package cafe.adriel.voyager.sample.multimodule.featureb
package cafe.adriel.voyager.sample.multimodule.posts

import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
Expand All @@ -15,9 +15,8 @@ import androidx.compose.ui.unit.dp
import cafe.adriel.voyager.core.screen.Screen
import cafe.adriel.voyager.navigator.LocalNavigator
import cafe.adriel.voyager.navigator.currentOrThrow
import cafe.adriel.voyager.sample.multimodule.shared.SharedFeatureBScreen

class FeatureBScreen : SharedFeatureBScreen, Screen {
class ListScreen : Screen {

@Composable
override fun Content() {
Expand All @@ -29,7 +28,7 @@ class FeatureBScreen : SharedFeatureBScreen, Screen {
modifier = Modifier.fillMaxSize()
) {
Text(
text = "Feature B without param",
text = "Post List",
style = MaterialTheme.typography.h5
)

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package cafe.adriel.voyager.sample.multimodule.posts

import cafe.adriel.voyager.core.registry.screenModule
import cafe.adriel.voyager.sample.multimodule.navigation.SharedScreen

val featurePostsScreenModule = screenModule {
register<SharedScreen.PostList> {
ListScreen()
}
register<SharedScreen.PostDetails> { provider ->
DetailsScreen(id = provider.id)
}
}
File renamed without changes.
File renamed without changes.
2 changes: 2 additions & 0 deletions sample-multi-module/navigation/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest package="cafe.adriel.voyager.sample.multimodule.navigation"/>
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package cafe.adriel.voyager.sample.multimodule.navigation

import cafe.adriel.voyager.core.registry.ScreenProvider

sealed class SharedScreen : ScreenProvider {
object PostList : SharedScreen()
data class PostDetails(val id: String) : SharedScreen()
}
2 changes: 0 additions & 2 deletions sample-multi-module/shared/src/main/AndroidManifest.xml

This file was deleted.

This file was deleted.

6 changes: 3 additions & 3 deletions settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ include(
':sample',

':sample-multi-module:app',
':sample-multi-module:shared',
':sample-multi-module:feature-a',
':sample-multi-module:feature-b',
':sample-multi-module:navigation',
':sample-multi-module:feature-home',
':sample-multi-module:feature-posts',

':voyager-core',
':voyager-navigator',
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package cafe.adriel.voyager.core.registry

private typealias ScreenModule = ScreenRegistry.() -> Unit

public fun screenModule(block: ScreenModule): ScreenModule =
{ block() }
Loading

0 comments on commit b71b0c9

Please sign in to comment.