Created
June 25, 2021 00:09
-
-
Save ForceTower/ff967486704e8415e18e43ccc5a8d91c to your computer and use it in GitHub Desktop.
Navigation deep link emulation
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
fun NavDestination.buildExplicitly(): IntArray { | |
val hierarchy = ArrayDeque<NavDestination>() | |
var current: NavDestination? = this | |
do { | |
val parent = current!!.parent | |
if (parent == null || parent.startDestination != current.id) { | |
hierarchy.addFirst(current) | |
} | |
current = parent | |
} while (current != null) | |
val deepLinkIds = IntArray(hierarchy.size) | |
var index = 0 | |
for (destination in hierarchy) { | |
deepLinkIds[index++] = destination.id | |
} | |
return deepLinkIds | |
} |
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
val graph = NavInflater(this, PermissiveNavigatorProvider()).inflate(R.navigation.home_graph) | |
val node = graph.findNode(R.id.home) | |
val res = node!!.buildExplicitly() | |
intent.putExtra("android-support-nav:controller:deepLinkIds", res) | |
// res is graph, backstack ids, destination | |
// res is intArrayOf(R.id.home_graph_xml, R.id.home) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment