Skip to content

Commit

Permalink
chore: moved integration modules to integration folder and avoid mist…
Browse files Browse the repository at this point in the history
…ake with root and core routing modules
  • Loading branch information
programadorthi committed Jan 28, 2024
1 parent 07baf57 commit 3eb7f64
Show file tree
Hide file tree
Showing 50 changed files with 110 additions and 43 deletions.
136 changes: 101 additions & 35 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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<Endpoint> {
// ...
}
}

// 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.
Expand All @@ -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<T>() // 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:
Expand Down Expand Up @@ -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<Endpoint> {
// ...
// 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<T>`. Its `onResult` function will be called
on any successfully `pop()` or `popUntil()` to the previous screen.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ kotlin {
sourceSets {
commonMain {
dependencies {
api(projects.compose)
api(projects.integration.compose)
implementation(compose.runtime)
implementation(compose.animation)
}
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ import io.ktor.util.logging.Logger
import kotlin.coroutines.CoroutineContext
import kotlin.coroutines.EmptyCoroutineContext

public val LocalRouting: ProvidableCompositionLocal<Routing> =
public val LocalVoyagerRouting: ProvidableCompositionLocal<Routing> =
staticCompositionLocalOf {
error("Composition local LocalRouting not found")
error("Composition local LocalVoyagerRouting not found")
}

@Composable
Expand All @@ -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,
Expand Down
File renamed without changes.
9 changes: 5 additions & 4 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit 3eb7f64

Please sign in to comment.