-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'chore/improve-the-base-navigation' into feature/define-…
…results-for-up-navigation
- Loading branch information
Showing
22 changed files
with
185 additions
and
125 deletions.
There are no files selected for viewing
21 changes: 21 additions & 0 deletions
21
sample-compose/app/src/androidTest/java/co/nimblehq/sample/compose/test/MockUtil.kt
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package co.nimblehq.sample.compose.test | ||
|
||
import co.nimblehq.sample.compose.domain.model.Model | ||
|
||
object MockUtil { | ||
|
||
val models = listOf( | ||
Model( | ||
id = 1, | ||
username = "name1", | ||
), | ||
Model( | ||
id = 2, | ||
username = "name2", | ||
), | ||
Model( | ||
id = 3, | ||
username = "name3", | ||
), | ||
) | ||
} |
This file contains 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
47 changes: 4 additions & 43 deletions
47
sample-compose/app/src/main/java/co/nimblehq/sample/compose/ui/AppDestination.kt
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,49 +1,10 @@ | ||
package co.nimblehq.sample.compose.ui | ||
|
||
import androidx.navigation.NamedNavArgument | ||
import androidx.navigation.NavType | ||
import androidx.navigation.navArgument | ||
import co.nimblehq.sample.compose.model.UiModel | ||
import co.nimblehq.sample.compose.ui.base.BaseDestination | ||
|
||
const val KeyId = "id" | ||
const val KeyModel = "model" | ||
const val KeyResultOk = "keyResultOk" | ||
sealed class AppDestination { | ||
|
||
sealed class AppDestination(val route: String = "") { | ||
object RootNavGraph : BaseDestination("rootNavGraph") | ||
|
||
open val arguments: List<NamedNavArgument> = emptyList() | ||
|
||
open var destination: String = route | ||
|
||
open var parcelableArgument: Pair<String, Any?> = "" to null | ||
|
||
data class Up(val results: HashMap<String, Any> = hashMapOf()) : AppDestination() { | ||
|
||
fun addResult(key: String, value: Any) = apply { | ||
results[key] = value | ||
} | ||
} | ||
|
||
object RootNavGraph : AppDestination("rootNavGraph") | ||
|
||
object MainNavGraph : AppDestination("mainNavGraph") | ||
|
||
object Home : AppDestination("home") | ||
|
||
object Second : AppDestination("second/{$KeyId}") { | ||
|
||
override val arguments = listOf( | ||
navArgument(KeyId) { type = NavType.StringType } | ||
) | ||
|
||
fun createRoute(id: String) = apply { | ||
destination = "second/$id" | ||
} | ||
} | ||
|
||
object Third : AppDestination("third") { | ||
fun addParcel(value: UiModel) = apply { | ||
parcelableArgument = KeyModel to value | ||
} | ||
} | ||
object MainNavGraph : BaseDestination("mainNavGraph") | ||
} |
This file contains 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
21 changes: 21 additions & 0 deletions
21
sample-compose/app/src/main/java/co/nimblehq/sample/compose/ui/base/BaseDestination.kt
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package co.nimblehq.sample.compose.ui.base | ||
|
||
import androidx.navigation.NamedNavArgument | ||
|
||
const val KeyResultOk = "keyResultOk" | ||
|
||
abstract class BaseDestination(val route: String = "") { | ||
|
||
open val arguments: List<NamedNavArgument> = emptyList() | ||
|
||
open var destination: String = route | ||
|
||
open var parcelableArgument: Pair<String, Any?> = "" to null | ||
|
||
data class Up(val results: HashMap<String, Any> = hashMapOf()) : BaseDestination() { | ||
|
||
fun addResult(key: String, value: Any) = apply { | ||
results[key] = value | ||
} | ||
} | ||
} |
This file contains 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
31 changes: 31 additions & 0 deletions
31
...e-compose/app/src/main/java/co/nimblehq/sample/compose/ui/screens/main/MainDestination.kt
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package co.nimblehq.sample.compose.ui.screens.main | ||
|
||
import androidx.navigation.NavType | ||
import androidx.navigation.navArgument | ||
import co.nimblehq.sample.compose.model.UiModel | ||
import co.nimblehq.sample.compose.ui.base.BaseDestination | ||
|
||
const val KeyId = "id" | ||
const val KeyModel = "model" | ||
|
||
sealed class MainDestination { | ||
|
||
object Home : BaseDestination("home") | ||
|
||
object Second : BaseDestination("second/{$KeyId}") { | ||
|
||
override val arguments = listOf( | ||
navArgument(KeyId) { type = NavType.StringType } | ||
) | ||
|
||
fun createRoute(id: String) = apply { | ||
destination = "second/$id" | ||
} | ||
} | ||
|
||
object Third : BaseDestination("third") { | ||
fun addParcel(value: UiModel) = apply { | ||
parcelableArgument = KeyModel to value | ||
} | ||
} | ||
} |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Oops, something went wrong.