Created
October 31, 2021 11:49
-
-
Save smokelaboratory/0f03be4cef9239f93c529f6b25b788dc to your computer and use it in GitHub Desktop.
Route in NavHelper - Jetpack Compose
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| abstract class Route { | |
| abstract val label: String | |
| abstract val arguments: List<String>? | |
| abstract val optionalArguments: List<String>? | |
| val route: String by lazy { | |
| StringBuilder(label).apply { | |
| arguments?.let { | |
| it.forEach { | |
| append("/{$it}") | |
| } | |
| } | |
| optionalArguments?.let { | |
| it.forEach { | |
| append("?$it={$it}") | |
| } | |
| } | |
| }.toString() | |
| } | |
| fun address(args: Map<String, String>? = null): String { | |
| var address: String = route | |
| args?.entries?.forEach { | |
| address = address.replace("{${it.key}}", it.value) | |
| } | |
| return address | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment