diff --git a/README.md b/README.md index f8a5162..c9220b5 100644 --- a/README.md +++ b/README.md @@ -182,9 +182,47 @@ val router = routing( ) { } ``` -## Compose Routing (compose module) +## Other modules to interest + +- `auth` - [Authentication and Authorization](https://ktor.io/docs/authentication.html) +- `call-logging` - [Call Logging](https://ktor.io/docs/call-logging.html) +- `sessions` - [Sessions](https://ktor.io/docs/sessions.html) + +## Limitations + +- Any type-safe behavior combined with Nested routing does not support navigation from parent to child using the Type. You have to use path routing. +```kotlin +@Resource("/endpoint") +class Endpoint + +val parent = routing { } + +val router = routing( + rootPath = "/child", + parent = parent, +) { + handle { + // ... + } +} + +// IT WORKS +router.call(Endpoint()) -> This module is just for study or simple compose application. +// IT DOES NOT WORK +parent.call(Endpoint()) + +// IT WORKS +parent.call(uri = "/child/endpoint") +``` + +## Integration modules + +> These kind of modules are inspirations showing how do you own integration with the target framework. + +### Compose Routing (compose module) + +> This module is just for study or simple compose application. > I recommend use Voyager module for more robust application. Are you using Jetpack or Multiplatform Compose Runtime only? This module is for you. @@ -202,23 +240,25 @@ val routing = routing { @Composable fun MyComposeApp() { - Routing(routing = routing) { + Routing(routing = routing, initial = { // Initial content - } + LocalRouting.current // Available inside compositions to do routing + }) } // And in any place that have the routing instance call: -routing.call(uri = "/login") +routing.push(path = "/login") val lastPoppedCall = routing.poppedCall() // The call that was popped after call `routing.pop()` val result = lastPoppedCall?.popResult() // To get the result after call `routing.pop(result = T)` ``` -## Compose Animation (compose animation module) +### Compose Animation (compose-animation module) > This module is just for study or simple compose application. > I recommend use Voyager module for more robust application. -> At the moment Compose Animation has limited targets and is not available to all routing targets +> At the moment Compose Multiplatform Animation (not the routing module) has limited targets and it +> is not available to all routing targets Are you using Jetpack or Multiplatform Compose that requires animation? This module is for you. Easily route any composable you have just doing: @@ -246,48 +286,74 @@ fun MyComposeApp() { exitTransition = {...}, // on exit current composable in forward direction popEnterTransition = {...}, // on enter previous composable in backward direction popExitTransition = {...}, // on exit current composable in backward direction - ) { - // Initial content - } + initial = { + // Initial animated content + }) } // And in any place that have the routing instance call: -routing.call(uri = "/login") +routing.push(path = "/login") ``` -> The kotlin-routing author is not expert in Compose Animation. So, yes, the behavior here is close +> The kotlin-routing author is not expert in Compose Animation. So, yes, the behavior here is close > to [Navigation with Compose](https://developer.android.com/jetpack/compose/navigation) and will help people that come from it. -## Other modules to interest +### Web Routing (javascript module still in development) -- `auth` - [Authentication and Authorization](https://ktor.io/docs/authentication.html) -- `call-logging` - [Call Logging](https://ktor.io/docs/call-logging.html) -- `sessions` - [Sessions](https://ktor.io/docs/sessions.html) +> Are you building a DOM application? This module is for you. -## Limitations - -- Any type-safe behavior combined with Nested routing does not support navigation from parent to child using the Type. You have to use path routing. ```kotlin -@Resource("/endpoint") -class Endpoint +val routing = routing { + jsRoute(path = "/page1") { + // create and return your DOM Element + } + jsRoute(path = "/page2") { + // create and return your DOM Element + } +} -val parent = routing { } +fun main() { + render( + routing = routing, + root = document.getElementById("root") ?: document.create.div(), + initial = document.create.h1 { + +"I am the initial content" + onClickFunction = { + routing.push(path = "/page1") + } + } + ) +} -val router = routing( - rootPath = "/child", - parent = parent, -) { - handle { - // ... +// And in any place that have the routing instance call: +routing.push(path = "/page2") +``` + +### Voyager Routing (voyager module) + +> Are you building a Voyager application and need routing support? This module is for you. + +```kotlin +val routing = routing { + screen(path = "/page1") { + // create and return your Screen instance } } -// IT WORKS -router.call(Endpoint()) - -// IT DOES NOT WORK -parent.call(Endpoint()) +@Composable +fun App() { + VoyagerRouting( + routing = routing, + initialScreen = SplashScreen() // The first screen rendered + ... // Any other Voyager related config + ) +} -// IT WORKS -parent.call(uri = "/child/endpoint") +// And in any place that have the routing instance call: +routing.push(path = "/page1") ``` + +Voyager is a screen based library. So the result put in a pop call is passed to the screen and not +to the composition. And here it is different from `compose` module. To get the result after a pop call +do the previous screen implement `VoyagerRoutingPopResult`. Its `onResult` function will be called +on any successfully `pop()` or `popUntil()` to the previous screen. diff --git a/compose-animation/.gitignore b/integration/compose-animation/.gitignore similarity index 100% rename from compose-animation/.gitignore rename to integration/compose-animation/.gitignore diff --git a/compose-animation/build.gradle.kts b/integration/compose-animation/build.gradle.kts similarity index 97% rename from compose-animation/build.gradle.kts rename to integration/compose-animation/build.gradle.kts index b138b50..ef94c42 100644 --- a/compose-animation/build.gradle.kts +++ b/integration/compose-animation/build.gradle.kts @@ -34,7 +34,7 @@ kotlin { sourceSets { commonMain { dependencies { - api(projects.compose) + api(projects.integration.compose) implementation(compose.runtime) implementation(compose.animation) } diff --git a/compose-animation/common/src/dev/programadorthi/routing/compose/animation/ComposeAnimationScope.kt b/integration/compose-animation/common/src/dev/programadorthi/routing/compose/animation/ComposeAnimationScope.kt similarity index 100% rename from compose-animation/common/src/dev/programadorthi/routing/compose/animation/ComposeAnimationScope.kt rename to integration/compose-animation/common/src/dev/programadorthi/routing/compose/animation/ComposeAnimationScope.kt diff --git a/compose-animation/common/src/dev/programadorthi/routing/compose/animation/ComposeAnimations.kt b/integration/compose-animation/common/src/dev/programadorthi/routing/compose/animation/ComposeAnimations.kt similarity index 100% rename from compose-animation/common/src/dev/programadorthi/routing/compose/animation/ComposeAnimations.kt rename to integration/compose-animation/common/src/dev/programadorthi/routing/compose/animation/ComposeAnimations.kt diff --git a/compose-animation/common/src/dev/programadorthi/routing/compose/animation/ComposeRouting.kt b/integration/compose-animation/common/src/dev/programadorthi/routing/compose/animation/ComposeRouting.kt similarity index 100% rename from compose-animation/common/src/dev/programadorthi/routing/compose/animation/ComposeRouting.kt rename to integration/compose-animation/common/src/dev/programadorthi/routing/compose/animation/ComposeRouting.kt diff --git a/compose-animation/common/src/dev/programadorthi/routing/compose/animation/ComposeRoutingBuilder.kt b/integration/compose-animation/common/src/dev/programadorthi/routing/compose/animation/ComposeRoutingBuilder.kt similarity index 100% rename from compose-animation/common/src/dev/programadorthi/routing/compose/animation/ComposeRoutingBuilder.kt rename to integration/compose-animation/common/src/dev/programadorthi/routing/compose/animation/ComposeRoutingBuilder.kt diff --git a/compose-animation/gradle.properties b/integration/compose-animation/gradle.properties similarity index 100% rename from compose-animation/gradle.properties rename to integration/compose-animation/gradle.properties diff --git a/compose-animation/jvm/test/dev/programadorthi/routing/compose/animation/ComposeAnimationRoutingTest.kt b/integration/compose-animation/jvm/test/dev/programadorthi/routing/compose/animation/ComposeAnimationRoutingTest.kt similarity index 100% rename from compose-animation/jvm/test/dev/programadorthi/routing/compose/animation/ComposeAnimationRoutingTest.kt rename to integration/compose-animation/jvm/test/dev/programadorthi/routing/compose/animation/ComposeAnimationRoutingTest.kt diff --git a/compose-animation/jvm/test/dev/programadorthi/routing/compose/animation/ComposeAnimationsTest.kt b/integration/compose-animation/jvm/test/dev/programadorthi/routing/compose/animation/ComposeAnimationsTest.kt similarity index 100% rename from compose-animation/jvm/test/dev/programadorthi/routing/compose/animation/ComposeAnimationsTest.kt rename to integration/compose-animation/jvm/test/dev/programadorthi/routing/compose/animation/ComposeAnimationsTest.kt diff --git a/compose/.gitignore b/integration/compose/.gitignore similarity index 100% rename from compose/.gitignore rename to integration/compose/.gitignore diff --git a/compose/build.gradle.kts b/integration/compose/build.gradle.kts similarity index 100% rename from compose/build.gradle.kts rename to integration/compose/build.gradle.kts diff --git a/compose/common/src/dev/programadorthi/routing/compose/ComposeContent.kt b/integration/compose/common/src/dev/programadorthi/routing/compose/ComposeContent.kt similarity index 100% rename from compose/common/src/dev/programadorthi/routing/compose/ComposeContent.kt rename to integration/compose/common/src/dev/programadorthi/routing/compose/ComposeContent.kt diff --git a/compose/common/src/dev/programadorthi/routing/compose/ComposeManager.kt b/integration/compose/common/src/dev/programadorthi/routing/compose/ComposeManager.kt similarity index 100% rename from compose/common/src/dev/programadorthi/routing/compose/ComposeManager.kt rename to integration/compose/common/src/dev/programadorthi/routing/compose/ComposeManager.kt diff --git a/compose/common/src/dev/programadorthi/routing/compose/ComposePopResult.kt b/integration/compose/common/src/dev/programadorthi/routing/compose/ComposePopResult.kt similarity index 100% rename from compose/common/src/dev/programadorthi/routing/compose/ComposePopResult.kt rename to integration/compose/common/src/dev/programadorthi/routing/compose/ComposePopResult.kt diff --git a/compose/common/src/dev/programadorthi/routing/compose/ComposeResource.kt b/integration/compose/common/src/dev/programadorthi/routing/compose/ComposeResource.kt similarity index 100% rename from compose/common/src/dev/programadorthi/routing/compose/ComposeResource.kt rename to integration/compose/common/src/dev/programadorthi/routing/compose/ComposeResource.kt diff --git a/compose/common/src/dev/programadorthi/routing/compose/ComposeRouting.kt b/integration/compose/common/src/dev/programadorthi/routing/compose/ComposeRouting.kt similarity index 100% rename from compose/common/src/dev/programadorthi/routing/compose/ComposeRouting.kt rename to integration/compose/common/src/dev/programadorthi/routing/compose/ComposeRouting.kt diff --git a/compose/common/src/dev/programadorthi/routing/compose/ComposeRoutingBuilder.kt b/integration/compose/common/src/dev/programadorthi/routing/compose/ComposeRoutingBuilder.kt similarity index 100% rename from compose/common/src/dev/programadorthi/routing/compose/ComposeRoutingBuilder.kt rename to integration/compose/common/src/dev/programadorthi/routing/compose/ComposeRoutingBuilder.kt diff --git a/compose/common/src/dev/programadorthi/routing/compose/ComposeRoutingExt.kt b/integration/compose/common/src/dev/programadorthi/routing/compose/ComposeRoutingExt.kt similarity index 100% rename from compose/common/src/dev/programadorthi/routing/compose/ComposeRoutingExt.kt rename to integration/compose/common/src/dev/programadorthi/routing/compose/ComposeRoutingExt.kt diff --git a/compose/common/test/dev/programadorthi/routing/compose/ComposeResourcesTest.kt b/integration/compose/common/test/dev/programadorthi/routing/compose/ComposeResourcesTest.kt similarity index 100% rename from compose/common/test/dev/programadorthi/routing/compose/ComposeResourcesTest.kt rename to integration/compose/common/test/dev/programadorthi/routing/compose/ComposeResourcesTest.kt diff --git a/compose/common/test/dev/programadorthi/routing/compose/ComposeRoutingTest.kt b/integration/compose/common/test/dev/programadorthi/routing/compose/ComposeRoutingTest.kt similarity index 100% rename from compose/common/test/dev/programadorthi/routing/compose/ComposeRoutingTest.kt rename to integration/compose/common/test/dev/programadorthi/routing/compose/ComposeRoutingTest.kt diff --git a/compose/common/test/dev/programadorthi/routing/compose/helper/ComposeTestHelper.kt b/integration/compose/common/test/dev/programadorthi/routing/compose/helper/ComposeTestHelper.kt similarity index 100% rename from compose/common/test/dev/programadorthi/routing/compose/helper/ComposeTestHelper.kt rename to integration/compose/common/test/dev/programadorthi/routing/compose/helper/ComposeTestHelper.kt diff --git a/compose/common/test/dev/programadorthi/routing/compose/helper/FakeContent.kt b/integration/compose/common/test/dev/programadorthi/routing/compose/helper/FakeContent.kt similarity index 100% rename from compose/common/test/dev/programadorthi/routing/compose/helper/FakeContent.kt rename to integration/compose/common/test/dev/programadorthi/routing/compose/helper/FakeContent.kt diff --git a/compose/common/test/dev/programadorthi/routing/compose/helper/TestApplier.kt b/integration/compose/common/test/dev/programadorthi/routing/compose/helper/TestApplier.kt similarity index 100% rename from compose/common/test/dev/programadorthi/routing/compose/helper/TestApplier.kt rename to integration/compose/common/test/dev/programadorthi/routing/compose/helper/TestApplier.kt diff --git a/compose/gradle.properties b/integration/compose/gradle.properties similarity index 100% rename from compose/gradle.properties rename to integration/compose/gradle.properties diff --git a/javascript/.gitignore b/integration/javascript/.gitignore similarity index 100% rename from javascript/.gitignore rename to integration/javascript/.gitignore diff --git a/javascript/build.gradle.kts b/integration/javascript/build.gradle.kts similarity index 100% rename from javascript/build.gradle.kts rename to integration/javascript/build.gradle.kts diff --git a/javascript/gradle.properties b/integration/javascript/gradle.properties similarity index 100% rename from javascript/gradle.properties rename to integration/javascript/gradle.properties diff --git a/javascript/js/src/dev/programadorthi/routing/javascript/JavascriptRouting.kt b/integration/javascript/js/src/dev/programadorthi/routing/javascript/JavascriptRouting.kt similarity index 100% rename from javascript/js/src/dev/programadorthi/routing/javascript/JavascriptRouting.kt rename to integration/javascript/js/src/dev/programadorthi/routing/javascript/JavascriptRouting.kt diff --git a/javascript/js/src/dev/programadorthi/routing/javascript/JavascriptRoutingAttribute.kt b/integration/javascript/js/src/dev/programadorthi/routing/javascript/JavascriptRoutingAttribute.kt similarity index 100% rename from javascript/js/src/dev/programadorthi/routing/javascript/JavascriptRoutingAttribute.kt rename to integration/javascript/js/src/dev/programadorthi/routing/javascript/JavascriptRoutingAttribute.kt diff --git a/javascript/js/src/dev/programadorthi/routing/javascript/JavascriptRoutingBuilder.kt b/integration/javascript/js/src/dev/programadorthi/routing/javascript/JavascriptRoutingBuilder.kt similarity index 100% rename from javascript/js/src/dev/programadorthi/routing/javascript/JavascriptRoutingBuilder.kt rename to integration/javascript/js/src/dev/programadorthi/routing/javascript/JavascriptRoutingBuilder.kt diff --git a/javascript/js/src/dev/programadorthi/routing/javascript/JavascriptRoutingExt.kt b/integration/javascript/js/src/dev/programadorthi/routing/javascript/JavascriptRoutingExt.kt similarity index 100% rename from javascript/js/src/dev/programadorthi/routing/javascript/JavascriptRoutingExt.kt rename to integration/javascript/js/src/dev/programadorthi/routing/javascript/JavascriptRoutingExt.kt diff --git a/javascript/js/src/dev/programadorthi/routing/javascript/JavascriptRoutingState.kt b/integration/javascript/js/src/dev/programadorthi/routing/javascript/JavascriptRoutingState.kt similarity index 100% rename from javascript/js/src/dev/programadorthi/routing/javascript/JavascriptRoutingState.kt rename to integration/javascript/js/src/dev/programadorthi/routing/javascript/JavascriptRoutingState.kt diff --git a/voyager/.gitignore b/integration/voyager/.gitignore similarity index 100% rename from voyager/.gitignore rename to integration/voyager/.gitignore diff --git a/voyager/build.gradle.kts b/integration/voyager/build.gradle.kts similarity index 100% rename from voyager/build.gradle.kts rename to integration/voyager/build.gradle.kts diff --git a/voyager/common/src/dev/programadorthi/routing/voyager/VoyagerNavigatorAttribute.kt b/integration/voyager/common/src/dev/programadorthi/routing/voyager/VoyagerNavigatorAttribute.kt similarity index 100% rename from voyager/common/src/dev/programadorthi/routing/voyager/VoyagerNavigatorAttribute.kt rename to integration/voyager/common/src/dev/programadorthi/routing/voyager/VoyagerNavigatorAttribute.kt diff --git a/voyager/common/src/dev/programadorthi/routing/voyager/VoyagerResourcesBuilder.kt b/integration/voyager/common/src/dev/programadorthi/routing/voyager/VoyagerResourcesBuilder.kt similarity index 100% rename from voyager/common/src/dev/programadorthi/routing/voyager/VoyagerResourcesBuilder.kt rename to integration/voyager/common/src/dev/programadorthi/routing/voyager/VoyagerResourcesBuilder.kt diff --git a/voyager/common/src/dev/programadorthi/routing/voyager/VoyagerRouting.kt b/integration/voyager/common/src/dev/programadorthi/routing/voyager/VoyagerRouting.kt similarity index 93% rename from voyager/common/src/dev/programadorthi/routing/voyager/VoyagerRouting.kt rename to integration/voyager/common/src/dev/programadorthi/routing/voyager/VoyagerRouting.kt index 2dae2bd..6d29eea 100644 --- a/voyager/common/src/dev/programadorthi/routing/voyager/VoyagerRouting.kt +++ b/integration/voyager/common/src/dev/programadorthi/routing/voyager/VoyagerRouting.kt @@ -23,9 +23,9 @@ import io.ktor.util.logging.Logger import kotlin.coroutines.CoroutineContext import kotlin.coroutines.EmptyCoroutineContext -public val LocalRouting: ProvidableCompositionLocal = +public val LocalVoyagerRouting: ProvidableCompositionLocal = staticCompositionLocalOf { - error("Composition local LocalRouting not found") + error("Composition local LocalVoyagerRouting not found") } @Composable @@ -37,7 +37,7 @@ public fun VoyagerRouting( key: String = compositionUniqueId(), content: NavigatorContent = { CurrentScreen() }, ) { - CompositionLocalProvider(LocalRouting provides routing) { + CompositionLocalProvider(LocalVoyagerRouting provides routing) { Navigator( screen = initialScreen, disposeBehavior = disposeBehavior, diff --git a/voyager/common/src/dev/programadorthi/routing/voyager/VoyagerRoutingBuilder.kt b/integration/voyager/common/src/dev/programadorthi/routing/voyager/VoyagerRoutingBuilder.kt similarity index 100% rename from voyager/common/src/dev/programadorthi/routing/voyager/VoyagerRoutingBuilder.kt rename to integration/voyager/common/src/dev/programadorthi/routing/voyager/VoyagerRoutingBuilder.kt diff --git a/voyager/common/src/dev/programadorthi/routing/voyager/VoyagerRoutingExt.kt b/integration/voyager/common/src/dev/programadorthi/routing/voyager/VoyagerRoutingExt.kt similarity index 100% rename from voyager/common/src/dev/programadorthi/routing/voyager/VoyagerRoutingExt.kt rename to integration/voyager/common/src/dev/programadorthi/routing/voyager/VoyagerRoutingExt.kt diff --git a/voyager/common/src/dev/programadorthi/routing/voyager/VoyagerRoutingPopResult.kt b/integration/voyager/common/src/dev/programadorthi/routing/voyager/VoyagerRoutingPopResult.kt similarity index 100% rename from voyager/common/src/dev/programadorthi/routing/voyager/VoyagerRoutingPopResult.kt rename to integration/voyager/common/src/dev/programadorthi/routing/voyager/VoyagerRoutingPopResult.kt diff --git a/voyager/common/test/dev/programadorthi/routing/voyager/VoyagerResourcesRoutingTest.kt b/integration/voyager/common/test/dev/programadorthi/routing/voyager/VoyagerResourcesRoutingTest.kt similarity index 100% rename from voyager/common/test/dev/programadorthi/routing/voyager/VoyagerResourcesRoutingTest.kt rename to integration/voyager/common/test/dev/programadorthi/routing/voyager/VoyagerResourcesRoutingTest.kt diff --git a/voyager/common/test/dev/programadorthi/routing/voyager/VoyagerRoutingTest.kt b/integration/voyager/common/test/dev/programadorthi/routing/voyager/VoyagerRoutingTest.kt similarity index 100% rename from voyager/common/test/dev/programadorthi/routing/voyager/VoyagerRoutingTest.kt rename to integration/voyager/common/test/dev/programadorthi/routing/voyager/VoyagerRoutingTest.kt diff --git a/voyager/common/test/dev/programadorthi/routing/voyager/helper/ComposeTestHelper.kt b/integration/voyager/common/test/dev/programadorthi/routing/voyager/helper/ComposeTestHelper.kt similarity index 100% rename from voyager/common/test/dev/programadorthi/routing/voyager/helper/ComposeTestHelper.kt rename to integration/voyager/common/test/dev/programadorthi/routing/voyager/helper/ComposeTestHelper.kt diff --git a/voyager/common/test/dev/programadorthi/routing/voyager/helper/FakeResourceScreen.kt b/integration/voyager/common/test/dev/programadorthi/routing/voyager/helper/FakeResourceScreen.kt similarity index 100% rename from voyager/common/test/dev/programadorthi/routing/voyager/helper/FakeResourceScreen.kt rename to integration/voyager/common/test/dev/programadorthi/routing/voyager/helper/FakeResourceScreen.kt diff --git a/voyager/common/test/dev/programadorthi/routing/voyager/helper/FakeScreen.kt b/integration/voyager/common/test/dev/programadorthi/routing/voyager/helper/FakeScreen.kt similarity index 100% rename from voyager/common/test/dev/programadorthi/routing/voyager/helper/FakeScreen.kt rename to integration/voyager/common/test/dev/programadorthi/routing/voyager/helper/FakeScreen.kt diff --git a/voyager/common/test/dev/programadorthi/routing/voyager/helper/Path.kt b/integration/voyager/common/test/dev/programadorthi/routing/voyager/helper/Path.kt similarity index 100% rename from voyager/common/test/dev/programadorthi/routing/voyager/helper/Path.kt rename to integration/voyager/common/test/dev/programadorthi/routing/voyager/helper/Path.kt diff --git a/voyager/common/test/dev/programadorthi/routing/voyager/helper/TestApplier.kt b/integration/voyager/common/test/dev/programadorthi/routing/voyager/helper/TestApplier.kt similarity index 100% rename from voyager/common/test/dev/programadorthi/routing/voyager/helper/TestApplier.kt rename to integration/voyager/common/test/dev/programadorthi/routing/voyager/helper/TestApplier.kt diff --git a/voyager/gradle.properties b/integration/voyager/gradle.properties similarity index 100% rename from voyager/gradle.properties rename to integration/voyager/gradle.properties diff --git a/settings.gradle.kts b/settings.gradle.kts index 701e0a2..a452276 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -22,16 +22,17 @@ rootProject.name = "kotlin-routing" include(":auth") include(":call-logging") -include(":compose") -include(":compose-animation") include(":core") include(":events") include(":events-resources") -include(":javascript") include(":resources") include(":sessions") include(":status-pages") -include(":voyager") + +include(":integration:compose") +include(":integration:compose-animation") +include(":integration:javascript") +include(":integration:voyager") // Samples are disabled by default to avoid sync their. //include(":samples:android-sample")