-
-
Notifications
You must be signed in to change notification settings - Fork 97
Added handleDeepLink function with additional parameters #968
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
📝 WalkthroughWalkthroughThis PR refactors the deep link handling API in Decompose's Android module, introducing a new Changes
Sequence Diagram(s)sequenceDiagram
participant Activity
participant SavedStateRegistry as SavedState<br/>Registry
participant Predicate as Restart<br/>Predicate
participant Restart as TaskStack<br/>Builder
Activity->>Activity: handleDeepLink(deepLink, predicate, block)
Activity->>SavedStateRegistry: Check if deepLink already handled
alt deepLink handled previously
Activity-->>Activity: Return null (skip processing)
else deepLink not handled
Activity->>Predicate: shouldRestartInNewTask(deepLink)
alt Predicate returns true
rect rgb(255, 200, 150)
Note over Activity,Restart: Restart Flow (New)
Activity->>Activity: Set flags on intent<br/>(NEW_TASK, CLEAR_TASK)
Activity->>Restart: TaskStackBuilder.create()<br/>.addNextIntent()
Restart->>Activity: finish()
Activity->>Activity: Suppress animation
Activity-->>Activity: Return null
end
else Predicate returns false
rect rgb(200, 220, 255)
Note over Activity,SavedStateRegistry: Normal Flow
Activity->>Activity: Invoke block(deepLink)
Activity->>SavedStateRegistry: Mark deepLink as handled
Activity-->>Activity: Return result
end
end
end
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (1)
decompose/src/androidMain/kotlin/com/arkivanov/decompose/DeeplinkUtils.kt (1)
106-124: Consider clarifying the default parameter's unused lambda parameter.The default value for
shouldRestartInNewTaskon line 108 has the signature(D) -> Booleanbut the default implementation ignores theDparameter and only checks Activity intent flags:shouldRestartInNewTask: (D) -> Boolean = { HandleDeepLinkDefaults.shouldRestartInNewTask(this) }While this is functionally correct (allowing users to provide custom predicates that DO use the deep link value), it might be slightly confusing. The logic is sound, but adding a KDoc note explaining why the default ignores the deep link parameter could improve clarity.
The implementation itself is correct:
- Restart logic properly checks both deep link nullability and the predicate
- State management prevents re-processing after configuration changes
- The
takeUnlesson line 123 correctly filters already-handled deep links
📜 Review details
Configuration used: defaults
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
decompose/api/android/decompose.apidecompose/src/androidMain/kotlin/com/arkivanov/decompose/DeeplinkUtils.kt
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
- GitHub Check: Build on Linux
- GitHub Check: Build on macOS
🔇 Additional comments (8)
decompose/api/android/decompose.api (2)
96-98: LGTM! New API surface additions are correct.The new
handleDeepLinkoverload and its synthetic default variant are properly declared, matching the implementation in DeeplinkUtils.kt and following Kotlin/Java interop conventions.
133-137: LGTM! HandleDeepLinkDefaults properly declared.The new
HandleDeepLinkDefaultsobject is correctly represented in the API file with its singleton INSTANCE field andshouldRestartInNewTaskmethod.decompose/src/androidMain/kotlin/com/arkivanov/decompose/DeeplinkUtils.kt (6)
5-6: LGTM! Intent flag imports are appropriate.Direct imports of
FLAG_ACTIVITY_CLEAR_TASKandFLAG_ACTIVITY_NEW_TASKimprove code readability throughout the file.
56-62: LGTM! Backward-compatible delegation pattern.The original
handleDeepLinkfunction cleanly delegates to the new overload while maintaining backward compatibility. The refactoring preserves existing behavior by passingintent.dataas the deep link.
126-138: LGTM! Flag checking logic is correct.The
shouldRestartInNewTaskimplementation properly checks Android intent flags using bitwise operations:
- Returns
truewhenFLAG_ACTIVITY_NEW_TASKis set ANDFLAG_ACTIVITY_CLEAR_TASKis not set- This correctly identifies when an Activity restart with
CLEAR_TASKis needed to ensure a clean task stackThe logic aligns with Android deep linking best practices.
140-157: LGTM! Activity restart implementation is robust.The
restart()function follows Android best practices and is derived from AndroidX Navigation source:
- Correctly adds
FLAG_ACTIVITY_CLEAR_TASKto ensure clean task stack- Uses
TaskStackBuilderto rebuild the entire activity stack for predictable state- Disables transition animation to prevent visual glitches
- Properly wrapped with StrictMode handling
The implementation aligns with Android's deep link handling recommendations.
159-175: LGTM! Proper StrictMode handling with version compatibility.The StrictMode helper functions are well-implemented:
- Temporarily permits unsafe intent launch for
TaskStackBuilder.startActivities()- Properly restores original policy in
finallyblock- Includes API level check for
permitUnsafeIntentLaunch()(Android S+)inlinemodifier ensures zero-overhead abstraction
177-178: LGTM! Well-defined state keys.Private constants for SavedStateRegistry keys prevent magic strings and improve maintainability.
Summary by CodeRabbit
✏️ Tip: You can customize this high-level summary in your review settings.