All Downloads are FREE. Search and download functionalities are using the official Maven repository.

commonMain.com.blucky8649.decompose_navhost.navigation.NavGraph.kt Maven / Gradle / Ivy

Go to download

A Decompose extension library which facilitate writing Jetpack based navigation style code for Compose Multiplatform.

There is a newer version: 1.0.0-alpha04
Show newest version
package com.blucky8649.decompose_navhost.navigation

import androidx.compose.animation.AnimatedVisibilityScope
import androidx.compose.runtime.Composable

class NavGraph (
    val startDestination: String,
    private val destinations: Map
) {
    fun findDestination(route: String) : Destination = destinations[route]
        ?: error("Destination not found")
}

class NavGraphBuilder {
    private val destinations = mutableMapOf()

    private var _startDestination: String? = null
    var startDestination: String get() {
        return _startDestination ?: error("Start destination is not set")
    }
        set(value) { _startDestination = value }

    fun composable(
        route: String,
        content: @Composable AnimatedVisibilityScope.(NavBackStackEntry) -> Unit
    ) {
        destinations[route] = Destination(route, content = content)
    }

    internal fun build() = NavGraph(startDestination, destinations)
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy