feat: Add UIScene life cycle support#405
Conversation
|
To view this pull requests documentation preview, visit the following URL: docs.page/abausg/home_widget~405 Documentation is deployed and generated using docs.page. |
WalkthroughThis change adds iOS 13+ scene lifecycle support to HomeWidgetPlugin by implementing the FlutterSceneLifeCycleDelegate protocol through a new extension. It handles scene connection and URL context events to detect and track widget URLs. Changes
Sequence Diagram(s)sequenceDiagram
participant iOS as iOS System
participant Scene as Scene Delegate
participant Plugin as HomeWidgetPlugin
participant State as Plugin State
iOS->>Scene: App launches/scene connects
Scene->>Plugin: scene(_:willConnectTo:options:)
Plugin->>Plugin: Check connectionOptions.urlContexts
Plugin->>Plugin: Detect widget URLs via isWidgetUrl()
Plugin->>State: Set initialUrl & latestUrl from first match
Plugin-->>Scene: Return Bool result
iOS->>Scene: User opens widget URL
Scene->>Plugin: scene(_:openURLContexts:)
Plugin->>Plugin: Iterate URLContexts
Plugin->>Plugin: Check if widget URL via isWidgetUrl()
Plugin->>State: Update latestUrl on match
Plugin-->>Scene: Return Bool result
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Possibly related issues
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Tip Try Coding Plans. Let us write the prompt for your AI agent so you can ship faster (with fewer bugs). 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.
🧹 Nitpick comments (1)
packages/home_widget/ios/home_widget/Sources/home_widget/HomeWidgetPlugin+SceneDelegate.swift (1)
11-21: Consider whether returningfalseis the intended behavior.The method always returns
false(line 21), even when a widget URL is successfully handled. The parallelapplication(_:didFinishLaunchingWithOptions:)returnstrue. While the return value semantics may differ between these delegate protocols, confirm this is intentional forFlutterSceneLifeCycleDelegate.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@packages/home_widget/ios/home_widget/Sources/home_widget/HomeWidgetPlugin`+SceneDelegate.swift around lines 11 - 21, The method currently always returns false even when a widget URL is handled; update the return to reflect whether a widget URL was found and handled: iterate connectionOptions?.urlContexts as you do, set initialUrl and latestUrl when isWidgetUrl(url:) matches, and then return true after handling (or return a boolean flag like handled that is true when you break on a widget URL and false otherwise) so the method's Bool return communicates that the scene handled a widget URL.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In
`@packages/home_widget/ios/home_widget/Sources/home_widget/HomeWidgetPlugin`+SceneDelegate.swift:
- Around line 11-21: The method currently always returns false even when a
widget URL is handled; update the return to reflect whether a widget URL was
found and handled: iterate connectionOptions?.urlContexts as you do, set
initialUrl and latestUrl when isWidgetUrl(url:) matches, and then return true
after handling (or return a boolean flag like handled that is true when you
break on a widget URL and false otherwise) so the method's Bool return
communicates that the scene handled a widget URL.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: 682a3b55-a608-4bb0-9b20-b6d0d089292c
📒 Files selected for processing (2)
packages/home_widget/ios/home_widget/Sources/home_widget/HomeWidgetPlugin+SceneDelegate.swiftpackages/home_widget/ios/home_widget/Sources/home_widget/HomeWidgetPlugin.swift
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #405 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 3 3
Lines 115 115
=========================================
Hits 115 115 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
ABausG
left a comment
There was a problem hiding this comment.
Looking good thanks! Just the nit comment as well as the formatting issue!
| if isWidgetUrl(url: url) { | ||
| initialUrl = url | ||
| latestUrl = url | ||
| break |
There was a problem hiding this comment.
See nitpicker comment from CodeRabbit:
#405 (review)
not sure if it would be sensible to return true here to match the previous logic as well as the other function
|
Please approve this pr as it's affecting the Appstore new releases |
feat: add UIScene support for widget launch URLs on iOSDescription
Adds iOS 13+ UIScene lifecycle support so that widget launch URLs are handled when the app uses a scene-based lifecycle (e.g. default Flutter iOS template with
SceneDelegate).Existing behavior: Widget taps were delivered only via
UIApplicationDelegate(application(_:didFinishLaunchingWithOptions:)andapplication(_:open:options:)). Apps that rely onUISceneDelegatefor URL handling did not receive these URLs.Changes:
FlutterSceneLifeCycleDelegatewithscene(_:willConnectToSession:options:)(initial launch URL fromconnectionOptions.urlContexts) andscene(_:openURLContexts:)(URL when app is already running). This mirrors the existing AppDelegate URL handling soinitiallyLaunchedFromHomeWidgetand the updates stream work for scene-based apps.addSceneDelegate:on the registrar (using the same runtimeresponds(to:)/performpattern asaddApplicationDelegate:for backward compatibility). Only registers on iOS 13+ and when the registrar supports it.isWidgetUrl(url:)is made internal so the scene delegate extension can reuse it.No Dart API changes. AppDelegate-based apps continue to work unchanged.
Checklist
exampleor documentation.Breaking Change?
Related Issues
#399