Shabinder Singh
12/01/2024, 3:06 PMprivate 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?Arkadii Ivanov
12/01/2024, 6:23 PMhandleDeepLink
function on Android. Plus a similar approach on other platforms. This would reduce the verbosity and simplify the code.