-
Notifications
You must be signed in to change notification settings - Fork 3
Compose Integration
Important
This module is a case of studies that shows how you can extend Kotlin Routing to your context.
Important
There are a lot of navigation libraries like Voyager, Jetpack Navigation, Decompose, etc. If your project is full Compose Multiplatform they are all you need for routing and navigating. Kotlin routing is general purpose and not a replacing to them.
Compose Multiplatform is a reality for kotlin developers and it is loved by them. Support to compose is required to any library that target kotlin frontend development.
So this module extend route handle to return a composable instead of just handle it.
sourceSets {
androidMain.dependencies {
implementation("dev.programadorthi.routing:compose:$version")
}
}
By the way that Compose works you need to use the Routing composable:
val router = routing {
// ...
}
@Composable
fun App() {
Routing(
routing = router,
startUri = "/start",
)
}
val router = routing {
composable(path = "/start") {
YourComposable()
}
}
composable
is a route handler on the hood and you can name it, change the route method, get call infos, and other behaviors as any route handler have.
There is an extension function that need to be called to pop a composable. It works getting the previous route and invoking it.
import dev.programadorthi.routing.compose.pop
// ...
router.pop()
import dev.programadorthi.routing.compose.pop
// ...
val router = routing {
composable(path = "/previous-route") {
val poppedCall = LocalRouting.current.poppedCall
val value = poppedCall?.popResult<AnyValueInstance>()
YouComposable(poppedValue = value)
}
}
router.pop(result = AnyValueInstance)