Skip to content

A platform & framework agnostic kotlin multiplatform library pack that you can use to navigate though different destinations of your application.

License

Notifications You must be signed in to change notification settings

aSoft-Ltd/captain

Repository files navigation

captain

A platform & framework agnostic kotlin multiplatform library pack that you can use to navigate though different destinations of your application.

With captain, you can do all your navigation from your business logic (which should be in common code) and do your routing in the ui layer (which depending on your tech stack, may or may not be in common code)

Maven Kotlin Android Java Swift iOS JavaScript TypeScript

Router Samples

compose

Router {
    AppNavigation()
    Routes {
        Route("/") { Home() }
        Route("/settings") { Settings() }
        Route("/profile/{uid}") { (uid) ->
            Profile(uid)
        }
    }
}

react

<Router>
    <AppNavigation />
    <Routes>
        <Route path="/" element={<Home/>} />
        <Route path="/settings" element={<Settings/>} />
        <Route path="/profile/{uid}" element={<Profile/>} />
    </Routes>
</Router>

kotlin-react

Router {
    AppNavigation()
    Routes {
        Route("/", Home)
        Route("/settings", Settings)
        Route("/profile/{uid}", Profile)
    }
}

Router Setup

compose

repositories {
    mavenCentral()
}

dependencies {
    // for compose-multiplatform 
    implementation("tz.co.asoft:captain-router-compose-core:2.0.18")
    // for compose-html use
    implementation("tz.co.asoft:captain-router-compose-html:2.0.18")
}

kotlin-react

repositories {
    mavenCentral()
}

dependencies {
    // for react-core (can be used even in react-native applications)
    implementation("tz.co.asoft:captain-router-react-core:2.0.18")
    // for react-dom (can be used even in react-dom applications)
    implementation("tz.co.asoft:captain-router-react-dom:2.0.18")
}

Navigator Samples

common-main

src

Navigator.kt

expect fun getNavigator(): Navigator

NavigatorUtils.kt

fun goTo(destination: String = "/") {
    val nav: Navigator = getNavigator()
    nav.navigate(destination)
}

fun goBack() {
    val nav: Navigator = getNavigator()
    nav.go(-1)
}

fun goForward() {
    val nav: Navigator = getNavigator()
    nav.go(1)
}

dependencies

dependencies {
    implementation("tz.co.asoft:captain-navigator-api:2.0.18")
}

js-main (Browser specific)

To use the browser's history api and follow the address bar and back/forward presses

src

private val navigator = BrowserNavigator()
// to avoid creating a new navigator everytime we call getNavigator

actual fun getNavigator(): Navigator = navigator

dependencies

dependencies {
    implementation("tz.co.asoft:captain-navigator-browser:2.0.18")
}

other-main

src

private val navigator = BasicNavigator()
// to avoid creating a new navigator everytime we call getNavigator

actual fun getNavigator(): Navigator = navigator

dependencies

dependencies {
    implementation("tz.co.asoft:captain-navigator-basic:2.0.18")
}

Documentation

Full documentation will be published soon

Api Reference

The full api reference of the kollections can be found at https://asoft-ltd.github.io/captain

Support

There are multiple ways you can support this project

Star It

If you found it useful, just give it a star

Contribute

You can help by submitting pull request to available open tickets on the issues section

Report Issues

This makes it easier to catch bugs and offer enhancements required

Credits

About

A platform & framework agnostic kotlin multiplatform library pack that you can use to navigate though different destinations of your application.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published