rootstrap / android-base-compose

5 stars 2 forks source link

Add nav config and deep links config example #69

Closed amaury901130 closed 1 year ago

amaury901130 commented 1 year ago

Description

Note: To add deep links: Add the .well-known/assetlinks.json file to your server to register the app Check the documentation: Docs

To test deep link locally call with adb:

 adb shell am start -a android.intent.action.VIEW \
                -c android.intent.category.BROWSABLE \
                -d "http://awesomewebpage.com"

Note: Once you upload the app to Google Play Store you will find the .well-known/assetlinks.json file config in the signature menu

To verify the assetlinks.json was registered with the app use:

- adb shell pm verify-app-links --re-verify PACKAGE_NAME'
- adb shell pm get-app-links PACKAGE_NAME

When verified, you should see the following output:

            com.rs.androidcomposebase
                ID: 01234567-89ab-cdef-0123-456789abcdef
                Signatures: [***]
                Domain verification state:
                    awesomewebpage.com: verified

Navigations: Example of nav with arguments:

        composable(
             route = NavRoutes.BusinessDetails.route,
             arguments = listOf(navArgument("id") { type = NavType.StringType })
         ) { backStackEntry ->
             backStackEntry.arguments?.getString("id")?.run {
              BusinessDetailPage(this)
               } ?: run {
                 ErrorPage(message = "404")
               }
         }

Example of calling a route with arguments:

        AppData.mainNavController.navigate(
             NavRoutes.BusinessDetailPage.withArg(
                 business.id
             )
         )

To set deep links:

       composable(
            route = NavRoutes.BusinessDetailPage.route,
            arguments = listOf(navArgument("id") { type = NavType.StringType }),
            // URI is your page deeplink in this case "awesomewebpage.com",
        // get your uri from your desired configuration: const var, env, gradle, etc..
            deepLinks = listOf(navDeepLink { uriPattern = "https://awesomewebpage.com/business/{id}"}),
         ) { backStackEntry ->
              backStackEntry.arguments?.getString("id")?.run {
                  BusinessDetailPage(this)
              } ?: run {
                  ErrorPage(message = "404")
              }
         }
sfiamene commented 1 year ago

can we have a readme with this? I'm thinking that by having it we could increase the visibility of it