Add helpers for creating deep link-enabled navigation destinations
This commit is contained in:
parent
abce7d0f31
commit
5afd7b70b3
4 changed files with 39 additions and 23 deletions
|
@ -0,0 +1,30 @@
|
|||
package app.k9mail.core.ui.compose.common.navigation
|
||||
|
||||
import android.net.Uri
|
||||
import androidx.compose.animation.AnimatedContentScope
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.core.net.toUri
|
||||
import androidx.navigation.NamedNavArgument
|
||||
import androidx.navigation.NavBackStackEntry
|
||||
import androidx.navigation.NavGraphBuilder
|
||||
import androidx.navigation.compose.composable
|
||||
import androidx.navigation.navDeepLink
|
||||
|
||||
fun NavGraphBuilder.deepLinkComposable(
|
||||
route: String,
|
||||
arguments: List<NamedNavArgument> = emptyList(),
|
||||
content: @Composable AnimatedContentScope.(NavBackStackEntry) -> Unit,
|
||||
) {
|
||||
composable(
|
||||
route = route,
|
||||
arguments = arguments,
|
||||
deepLinks = listOf(
|
||||
navDeepLink { uriPattern = route.toDeepLink() },
|
||||
),
|
||||
content = content,
|
||||
)
|
||||
}
|
||||
|
||||
fun String.toDeepLink(): String = "app://$this"
|
||||
|
||||
fun String.toDeepLinkUri(): Uri = toDeepLink().toUri()
|
|
@ -3,12 +3,10 @@ package app.k9mail.feature.account.setup.navigation
|
|||
import androidx.navigation.NavController
|
||||
import androidx.navigation.NavGraphBuilder
|
||||
import androidx.navigation.NavOptions
|
||||
import androidx.navigation.compose.composable
|
||||
import androidx.navigation.navDeepLink
|
||||
import app.k9mail.core.ui.compose.common.navigation.deepLinkComposable
|
||||
import app.k9mail.feature.account.setup.ui.AccountSetupScreen
|
||||
|
||||
const val NAVIGATION_ROUTE_ACCOUNT_SETUP = "/account/setup"
|
||||
const val DEEPLINK_ACCOUNT_SETUP = "app://$NAVIGATION_ROUTE_ACCOUNT_SETUP"
|
||||
|
||||
fun NavController.navigateToAccountSetup(navOptions: NavOptions? = null) {
|
||||
navigate(NAVIGATION_ROUTE_ACCOUNT_SETUP, navOptions)
|
||||
|
@ -18,12 +16,7 @@ fun NavGraphBuilder.accountSetupRoute(
|
|||
onBack: () -> Unit,
|
||||
onFinish: (String) -> Unit,
|
||||
) {
|
||||
composable(
|
||||
route = NAVIGATION_ROUTE_ACCOUNT_SETUP,
|
||||
deepLinks = listOf(
|
||||
navDeepLink { uriPattern = DEEPLINK_ACCOUNT_SETUP },
|
||||
),
|
||||
) {
|
||||
deepLinkComposable(route = NAVIGATION_ROUTE_ACCOUNT_SETUP) {
|
||||
AccountSetupScreen(
|
||||
onBack = onBack,
|
||||
onFinish = onFinish,
|
||||
|
|
|
@ -4,12 +4,12 @@ import android.app.Activity
|
|||
import android.content.Intent
|
||||
import android.os.Bundle
|
||||
import androidx.activity.ComponentActivity
|
||||
import androidx.core.net.toUri
|
||||
import androidx.core.view.WindowCompat
|
||||
import app.k9mail.core.ui.compose.common.activity.setActivityContent
|
||||
import app.k9mail.feature.account.setup.navigation.DEEPLINK_ACCOUNT_SETUP
|
||||
import app.k9mail.core.ui.compose.common.navigation.toDeepLinkUri
|
||||
import app.k9mail.feature.account.setup.navigation.NAVIGATION_ROUTE_ACCOUNT_SETUP
|
||||
import app.k9mail.feature.launcher.ui.FeatureLauncherApp
|
||||
import app.k9mail.feature.onboarding.navigation.DEEPLINK_ONBOARDING
|
||||
import app.k9mail.feature.onboarding.navigation.NAVIGATION_ROUTE_ONBOARDING
|
||||
|
||||
class FeatureLauncherActivity : ComponentActivity() {
|
||||
|
||||
|
@ -27,7 +27,7 @@ class FeatureLauncherActivity : ComponentActivity() {
|
|||
@JvmStatic
|
||||
fun launchOnboarding(context: Activity) {
|
||||
val intent = Intent(context, FeatureLauncherActivity::class.java).apply {
|
||||
data = DEEPLINK_ONBOARDING.toUri()
|
||||
data = NAVIGATION_ROUTE_ONBOARDING.toDeepLinkUri()
|
||||
flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK
|
||||
}
|
||||
context.startActivity(intent)
|
||||
|
@ -36,7 +36,7 @@ class FeatureLauncherActivity : ComponentActivity() {
|
|||
@JvmStatic
|
||||
fun launchSetupAccount(context: Activity) {
|
||||
val intent = Intent(context, FeatureLauncherActivity::class.java).apply {
|
||||
data = DEEPLINK_ACCOUNT_SETUP.toUri()
|
||||
data = NAVIGATION_ROUTE_ACCOUNT_SETUP.toDeepLinkUri()
|
||||
}
|
||||
context.startActivity(intent)
|
||||
}
|
||||
|
|
|
@ -3,12 +3,10 @@ package app.k9mail.feature.onboarding.navigation
|
|||
import androidx.navigation.NavController
|
||||
import androidx.navigation.NavGraphBuilder
|
||||
import androidx.navigation.NavOptions
|
||||
import androidx.navigation.compose.composable
|
||||
import androidx.navigation.navDeepLink
|
||||
import app.k9mail.core.ui.compose.common.navigation.deepLinkComposable
|
||||
import app.k9mail.feature.onboarding.ui.OnboardingScreen
|
||||
|
||||
const val NAVIGATION_ROUTE_ONBOARDING = "/onboarding"
|
||||
const val DEEPLINK_ONBOARDING = "app://$NAVIGATION_ROUTE_ONBOARDING"
|
||||
|
||||
fun NavController.navigateToOnboarding(
|
||||
navOptions: NavOptions? = null,
|
||||
|
@ -20,12 +18,7 @@ fun NavGraphBuilder.onboardingRoute(
|
|||
onStart: () -> Unit,
|
||||
onImport: () -> Unit,
|
||||
) {
|
||||
composable(
|
||||
route = NAVIGATION_ROUTE_ONBOARDING,
|
||||
deepLinks = listOf(
|
||||
navDeepLink { uriPattern = DEEPLINK_ONBOARDING },
|
||||
),
|
||||
) {
|
||||
deepLinkComposable(route = NAVIGATION_ROUTE_ONBOARDING) {
|
||||
OnboardingScreen(
|
||||
onStartClick = onStart,
|
||||
onImportClick = onImport,
|
||||
|
|
Loading…
Reference in a new issue