This repository was archived by the owner on Feb 22, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9.7k
[quick_actions]Migrate the plugin class to Swift, and remove custom modulemap #6369
Merged
auto-submit
merged 10 commits into
flutter:main
from
hellohuanlin:quick_actions_remove_custom_module_map_and_migration_plugin_class
Sep 22, 2022
Merged
Changes from 7 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
619709f
[quick_actions]remove custom module map and private header files
hellohuanlin ff69557
migrated quick actions plugin class
hellohuanlin e6955ae
update podspec to include swift
hellohuanlin 6d63647
fix unit test class name and add back umbrella header since we don't …
hellohuanlin 569eb63
format
hellohuanlin a548386
nit
hellohuanlin f5b80bc
swift format
hellohuanlin e1e5835
remove umbrella header since it's automatically generated
hellohuanlin ef032a4
bump patch version
hellohuanlin 8cf6109
fix typo
hellohuanlin File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
14 changes: 0 additions & 14 deletions
14
packages/quick_actions/quick_actions_ios/ios/Classes/FLTQuickActionsPlugin.h
This file was deleted.
Oops, something went wrong.
99 changes: 0 additions & 99 deletions
99
packages/quick_actions/quick_actions_ios/ios/Classes/FLTQuickActionsPlugin.m
This file was deleted.
Oops, something went wrong.
File renamed without changes.
23 changes: 0 additions & 23 deletions
23
...s/quick_actions/quick_actions_ios/ios/Classes/PrivateHeaders/FLTQuickActionsPlugin_Test.h
This file was deleted.
Oops, something went wrong.
11 changes: 0 additions & 11 deletions
11
packages/quick_actions/quick_actions_ios/ios/Classes/QuickActionsPlugin.modulemap
This file was deleted.
Oops, something went wrong.
90 changes: 90 additions & 0 deletions
90
packages/quick_actions/quick_actions_ios/ios/Classes/QuickActionsPlugin.swift
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,90 @@ | ||
| // Copyright 2013 The Flutter Authors. All rights reserved. | ||
| // Use of this source code is governed by a BSD-style license that can be | ||
| // found in the LICENSE file. | ||
|
|
||
| import Flutter | ||
|
|
||
| public final class QuickActionsPlugin: NSObject, FlutterPlugin { | ||
|
|
||
| public static func register(with registrar: FlutterPluginRegistrar) { | ||
| let channel = FlutterMethodChannel( | ||
| name: "plugins.flutter.io/quick_actions_ios", | ||
| binaryMessenger: registrar.messenger()) | ||
| let instance = QuickActionsPlugin(channel: channel) | ||
| registrar.addMethodCallDelegate(instance, channel: channel) | ||
| registrar.addApplicationDelegate(instance) | ||
| } | ||
|
|
||
| private let channel: FlutterMethodChannel | ||
| private let shortcutStateManager: FLTShortcutStateManager | ||
| /// The type of the shortcut item selected when launching the app. | ||
| private var launchingShortcutType: String? = nil | ||
|
|
||
| // TODO: (hellohuanlin) remove `@objc` attribute and make it non-public after migrating tests to Swift. | ||
| @objc | ||
| public init( | ||
| channel: FlutterMethodChannel, | ||
| shortcutStateManager: FLTShortcutStateManager = FLTShortcutStateManager() | ||
| ) { | ||
| self.channel = channel | ||
| self.shortcutStateManager = shortcutStateManager | ||
| } | ||
|
|
||
| public func handle(_ call: FlutterMethodCall, result: @escaping FlutterResult) { | ||
| switch call.method { | ||
| case "setShortcutItems": | ||
| // `arguments` must be a list of dictionaries | ||
| let items = call.arguments as! [[String: Any]] | ||
| shortcutStateManager.setShortcutItems(items) | ||
| result(nil) | ||
| case "clearShortcutItems": | ||
| shortcutStateManager.setShortcutItems([]) | ||
| result(nil) | ||
| case "getLaunchAction": | ||
| result(nil) | ||
| case _: | ||
| result(FlutterMethodNotImplemented) | ||
| } | ||
| } | ||
|
|
||
| public func application( | ||
| _ application: UIApplication, performActionFor shortcutItem: UIApplicationShortcutItem, | ||
| completionHandler: @escaping (Bool) -> Void | ||
| ) -> Bool { | ||
| handleShortcut(shortcutItem.type) | ||
| return true | ||
| } | ||
|
|
||
| public func application( | ||
| _ application: UIApplication, | ||
| didFinishLaunchingWithOptions launchOptions: [AnyHashable: Any] = [:] | ||
| ) -> Bool { | ||
| if let shortcutItem = launchOptions[UIApplication.LaunchOptionsKey.shortcutItem] | ||
| as? UIApplicationShortcutItem | ||
| { | ||
| // Keep hold of the shortcut type and handle it in the | ||
| // `applicationDidBecomeActure:` method once the Dart MethodChannel | ||
hellohuanlin marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| // is initialized. | ||
| launchingShortcutType = shortcutItem.type | ||
|
|
||
| // Return false to indicate we handled the quick action to ensure | ||
| // the `application:performActionFor:` method is not called (as | ||
| // per Apple's documentation: | ||
| // https://developer.apple.com/documentation/uikit/uiapplicationdelegate/1622935-application). | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. these comments are copied over from objc. |
||
| return false | ||
| } | ||
| return true | ||
| } | ||
|
|
||
| public func applicationDidBecomeActive(_ application: UIApplication) { | ||
| if let shortcutType = launchingShortcutType { | ||
| handleShortcut(shortcutType) | ||
| launchingShortcutType = nil | ||
| } | ||
| } | ||
|
|
||
| private func handleShortcut(_ shortcut: String) { | ||
| channel.invokeMethod("launch", arguments: shortcut) | ||
| } | ||
|
|
||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Force unwrap it to keep the same behavior as ObjC. Whether to crash on platform code or to surface an error is discussed here in this proposal.
Uh oh!
There was an error while loading. Please reload this page.
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.
If
itemsis nil, it doesn't crash on Objective-C(here). It actually sets the[UIApplication sharedApplication].shortcutItemsto an empty array, which results the same behavior as "clearShortcutItems". On the other hand, it would crash in this swift version due to force unwrapping.I think the current Objective-C behavior is more like?
I'm not sure the original design of an implicit "clearShortcutItems" is intended but for migration I feel like we should keep the behavior the same if possible and have a follow up PR to handle the error.
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.
If wrong type it should crash:
But I see your point about
nilvalue. The equivalent swift should be this instead:Not sure if it's worth to do tho. The corresponding dart side guarantees that the argument is non-null. So the
elseblock actually never run.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.
SGTM