I currently have a deeplinking impl, which I wont ...
# decompose
s
I currently have a deeplinking impl, which I wont say is the ideal, but does work, it looks like below: Each Platform Listens to deeplinks and pass that after filterting and modeling it into a nice data class to RootComponent. RootComponent.kt
Copy code
private fun handleDeepLink(deepLink: DeepLink) {
  if (deepLink.schema == "soundbound") {
    if (deepLink.host == "login") {
      toaster.showInfoToast(SharedRes.strings.login_in_progress.value + "...")
      scope.launch {
        authManager.handleDeeplink(deepLink.data)
      }
      return
    }

    // add a repo intent
    installRepo(deepLink.data)
    return
  }

  // Playlist Intent
  processLink(deepLink.data)
}


override fun processLink(link: String) {
  runWithChild<Child.Home> {
    component.searchLink(link)
  }
}

// This will navigate to desired component and run some logic, as required by deeplink.
inline fun <reified T : Child> RootComponent.runWithChild(crossinline block: T.() -> Unit) {
  activeChild.subscribeUntilTrue {
    val currentChild = (it.active.instance as? T)?.run(block)
    currentChild != null
  }

  navigateToConfig(T::class.getConfig()) // getConfig is a when case which basically maps configs <> child.
}
Things I am not happy with the design of this: • Each Components bears the responsibility of doing such things, where as I believe it should be the Router, since router is also a Hierarchy. ◦ My components are too smart which they should not be. • Very Hard Coded, extending something is hard, requires modifications, would want this to be extensible, and not need modifications across the nested hierarchy. Things I am happy with: • Doesn't need to recreate the stacks/components, if app is up and running and intent comes later, things navigate down the hierarchy pretty good creating and modifying state as needed, but need manual hardwiring. • Very customisable to do things but also usually allows the developer to write bad nested code. Thoughts: Would prefer a SmartRouter, which knows about the possible configs it can create, since its a sealed interface already, and can handle it that level, allowing extensibility with a lamdba where we can invoke custom logic when intent is received. @Arkadii Ivanov thoughts?
a
Indeed, deep link handling with Decompose is pretty verbose. But on the other hand, it's safe and explicit. E.g. a hacker can't open random screens by sending intents, etc. I would still recreate the entire hierarchy on deep link, and use the provided
handleDeepLink
function on Android. Plus a similar approach on other platforms. This would reduce the verbosity and simplify the code.