Replies: 3 comments 4 replies
-
This would be a new standalone doc page, or even a blog post. PRs are welcome. The doc reference you mention is emphasizing their |
Beta Was this translation helpful? Give feedback.
-
Recently, I was also looking into deeplinking to different screen using Circuit. Base on my understanding, here is how I was able to kinda deep link to different screen. Depending on where you create the // Add the intent to `PendingIntent` if using notification or other relevant location
val intent =
context.packageManager.getLaunchIntentForPackage(context.packageName)?.apply {
flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_SINGLE_TOP
// `UserProfileDetailsScreen` is your circuit screen with params if applicable
putExtra("destination_screen", UserProfileDetailsScreen(userId))
} Assuming app uses single entry point activity called // In your `MainActivity`
override fun onNewIntent(intent: Intent) {
super.onNewIntent(intent)
handleDeepLink(intent)
}
private fun handleDeepLink(intent: Intent) {
val destinationScreen =
intent.extras?.let { bundle ->
BundleCompat.getParcelable(
bundle,
"destination_screen", // bundle key for Circuit Screen
Screen::class.java,
)
}
if (destinationScreen != null) {
navigator.goTo(destinationScreen)
}
} This worked fine when activity was alive in the background, the However, I am not sure how to modify the circuit initialization to create new stack from For example, would something like this be ideal? 😕 // In your`MainActivity`
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContent {
// ... code omitted for brevity
val deepLinkScreen: Screen? = deepLinkScreen(intent?.extras)
val backStack: SaveableBackStack = if (deepLinkScreen != null) {
rememberSaveableBackStack(listOf(AppHomeScreen(), deepLinkScreen))
} else {
rememberSaveableBackStack(root = AppHomeScreen())
}
navigator = rememberCircuitNavigator(backStack)
// ... more code omitted
NavigableCircuitContent(
navigator = navigator,
) If this is not ideal path, how can I build stack of screen based on bundle data from If feel like deep linking is a broad topic and may be hard to document, however a basic guide/pointer would definitely be helpful for starters like me. I can take a stab at documenting based on feedback received here. |
Beta Was this translation helpful? Give feedback.
-
👋🏽 Hi folks, here is the draft I could come up with to give some idea about deep linking on Android. However, Circuit is a multi-platform library, I am not sure how useful this would be as a guide, at the same time I don't have expertise on multi-platform realm. This can stay as a discussion post and let users discover it through search. Basically, I am not too confident about this doc graduating to https://slackhq.github.io/circuit/ 😅 Here is something I still wasn't able to figure out properly:
Thanks! 🙏🏽 Deep-linking using CircuitDeep linking to app is a vast topic and the implementation detail can vary based on your application needs. To keep things very simple and easy to understand, we will be focusing on deep linking to Android platform only. Important Pre-requisite: You should have basic understanding of deep linking and should go through the Android's official training guide that contains useful information about deep linking to Android app. Deep linking strategyEssentially, you need to define a strategy for you app to handle the incoming deep link. We will take a look at Circuit's email app from the tutorial with following screens:
By default, the app launches with Inbox Screen as the root screen. To deep link into other two screens, we will define URI path segment as:
Assuming, our app's URI scheme is
Once you have added intent-filter in your Handling deep link in CircuitIn our case, we will create a // In your `MainActivity.kt` or activity that has the `intent-filter` for custom URI scheme
override fun onCreate(savedInstanceState: Bundle?) {
// ...
setContent {
ComposeAppTheme {
// When there is no deeplink data in the intent, default to Inbox Screen as root screen
val screensStack: List<Screen> = parseDeepLink(intent) ?: listOf(InboxScreen)
val backStack = rememberSaveableBackStack(screensStack)
val navigator = rememberCircuitNavigator(backStack)
// ...
}
}
} And here is a simple implementation of /**
* Parses the deep link from the given [Intent.getData] and returns a list of screens to navigate to.
*/
private fun parseDeepLink(intent: Intent): List<Screen>? {
val dataUri = intent.data ?: return null
val screens = mutableListOf<Screen>()
dataUri.pathSegments.filter { it.isNotBlank() }.forEach { pathSegment ->
when (pathSegment) {
"inbox" -> screens.add(InboxScreen)
"view_email" ->
dataUri.getQueryParameter("emailId")?.let {
screens.add(DetailScreen(it))
}
"new_email" -> screens.add(DraftNewEmailScreen)
else -> Log.d("App", "Unknown path segment: $pathSegment")
}
}
return screens.takeIf { it.isNotEmpty() }
} Tip Ideally, you would have deep link components that does the parsing and building screens based on parameters provided in the deep link URI. To test try the following command from the terminal: adb shell am start -W \
-a android.intent.action.VIEW \
-d "circuitapp://emailonthego/inbox/view_email/new_email/?emailId=2" It should launch the app and navigate to the Draft Screen with backstack containing Details Screen and Inbox Screen. Quick demo of deep linking working (src) using the sample code: ![]() |
Beta Was this translation helpful? Give feedback.
-
Description
I'd like to request adding documentation about Navigation deeplink in the Circuit documentation.
This would help developers understand how to implement deep linking features in their applications.
It would be helpful if the documentation could include:
Motivation
While browsing the Circuit documentation's Screen tab, I found the phrase "easy deeplinking". However, without any implementation examples or detailed explanations, it's difficult to understand what makes Circuit's deeplinking feature easy to use compared to alternatives.
Expected Outcome
Having this documentation would greatly help developers in understanding and implementing deep linking functionality using Circuit.
Beta Was this translation helpful? Give feedback.
All reactions