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

commonMain.moe.tlaster.precompose.navigation.RouteMatch.kt Maven / Gradle / Ivy

Go to download

A third-party Jetbrains Compose library with ViewModel, LiveData and Navigation support.

There is a newer version: 1.7.0-alpha03
Show newest version
package moe.tlaster.precompose.navigation

import moe.tlaster.precompose.navigation.route.ComposeRoute
import kotlin.math.min

internal class RouteMatch {
    var matches = false
    var route: ComposeRoute? = null
    var vars = arrayListOf()
    var keys = arrayListOf()
    var pathMap = linkedMapOf()
    fun key() {
        val size = min(keys.size, vars.size)
        for (i in 0 until size) {
            pathMap[keys[i]] = vars[i]
        }
        for (i in 0 until size) {
            vars.removeFirst()
        }
    }

    fun truncate(size: Int) {
        var sizeInt = size
        while (sizeInt < vars.size) {
            vars.removeAt(sizeInt++)
        }
    }

    fun value(value: String) {
        vars.add(value)
    }

    fun pop() {
        if (vars.isNotEmpty()) {
            vars.removeLast()
        }
    }

    fun found(route: ComposeRoute): RouteMatch {
        this.route = route
        matches = true
        return this
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy