-
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 pull request #569 from nimblehq/release/3.27.0
[Release] 3.27.0
- Loading branch information
Showing
40 changed files
with
496 additions
and
269 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
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
11 changes: 11 additions & 0 deletions
11
...le-compose/app/src/main/java/co/nimblehq/sample/compose/extensions/SavedStateHandleExt.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,11 @@ | ||
package co.nimblehq.sample.compose.extensions | ||
|
||
import androidx.lifecycle.SavedStateHandle | ||
|
||
fun <T> SavedStateHandle.getThenRemove(key: String): T? { | ||
return if (contains(key)) { | ||
val value = get<T>(key) | ||
remove<T>(key) | ||
value | ||
} else null | ||
} |
37 changes: 4 additions & 33 deletions
37
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,39 +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.ui.models.UiModel | ||
import co.nimblehq.sample.compose.ui.base.BaseDestination | ||
|
||
const val KeyId = "id" | ||
const val KeyModel = "model" | ||
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 | ||
|
||
object Up : AppDestination() | ||
|
||
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") | ||
} |
63 changes: 63 additions & 0 deletions
63
sample-compose/app/src/main/java/co/nimblehq/sample/compose/ui/AppNavGraph.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,63 @@ | ||
package co.nimblehq.sample.compose.ui | ||
|
||
import androidx.compose.runtime.Composable | ||
import androidx.navigation.NavBackStackEntry | ||
import androidx.navigation.NavGraphBuilder | ||
import androidx.navigation.NavHostController | ||
import androidx.navigation.compose.NavHost | ||
import androidx.navigation.compose.composable | ||
import androidx.navigation.navDeepLink | ||
import co.nimblehq.sample.compose.ui.base.BaseDestination | ||
import co.nimblehq.sample.compose.ui.screens.main.mainNavGraph | ||
|
||
@Composable | ||
fun AppNavGraph( | ||
navController: NavHostController, | ||
) { | ||
NavHost( | ||
navController = navController, | ||
route = AppDestination.RootNavGraph.route, | ||
startDestination = AppDestination.MainNavGraph.destination | ||
) { | ||
mainNavGraph(navController = navController) | ||
} | ||
} | ||
|
||
fun NavGraphBuilder.composable( | ||
destination: BaseDestination, | ||
content: @Composable (NavBackStackEntry) -> Unit, | ||
) { | ||
composable( | ||
route = destination.route, | ||
arguments = destination.arguments, | ||
deepLinks = destination.deepLinks.map { | ||
navDeepLink { | ||
uriPattern = it | ||
} | ||
}, | ||
content = content | ||
) | ||
} | ||
|
||
/** | ||
* Navigate to provided [BaseDestination] with a Pair of key value String and Data [parcel] | ||
* Caution to use this method. This method use savedStateHandle to store the Parcelable data. | ||
* When previousBackstackEntry is popped out from navigation stack, savedStateHandle will return null and cannot retrieve data. | ||
* eg.Login -> Home, the Login screen will be popped from the back-stack on logging in successfully. | ||
*/ | ||
fun NavHostController.navigate(destination: BaseDestination, parcel: Pair<String, Any?>? = null) { | ||
when (destination) { | ||
is BaseDestination.Up -> { | ||
destination.results.forEach { (key, value) -> | ||
previousBackStackEntry?.savedStateHandle?.set(key, value) | ||
} | ||
navigateUp() | ||
} | ||
else -> { | ||
parcel?.let { (key, value) -> | ||
currentBackStackEntry?.savedStateHandle?.set(key, value) | ||
} | ||
navigate(route = destination.destination) | ||
} | ||
} | ||
} |
78 changes: 0 additions & 78 deletions
78
sample-compose/app/src/main/java/co/nimblehq/sample/compose/ui/AppNavigation.kt
This file was deleted.
Oops, something went wrong.
26 changes: 26 additions & 0 deletions
26
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,26 @@ | ||
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 val deepLinks: List<String> = listOf( | ||
"https://android.nimblehq.co/$route", | ||
"android://$route", | ||
) | ||
|
||
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
2 changes: 1 addition & 1 deletion
2
...blehq/sample/compose/ui/screens/AppBar.kt → ...mblehq/sample/compose/ui/common/AppBar.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
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.