-
Notifications
You must be signed in to change notification settings - Fork 3.6k
[quick_actions] convert to pigeon #5159
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
Changes from 1 commit
409cd34
cbbd121
9eaaaf2
f23b103
01599f2
975dcb2
2ca3980
110a311
20796bb
e2dc2b7
bfe3748
f8bf4b2
249d3f8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,18 +8,17 @@ public final class QuickActionsPlugin: NSObject, FlutterPlugin, IOSQuickActionsA | |
|
|
||
| public static func register(with registrar: FlutterPluginRegistrar) { | ||
| let messenger = registrar.messenger() | ||
| let instance = QuickActionsPlugin(messenger: messenger) | ||
| let flutterApi = IOSQuickActionsFlutterApi(binaryMessenger: messenger) | ||
| let instance = QuickActionsPlugin(flutterApi: flutterApi) | ||
| IOSQuickActionsApiSetup.setUp(binaryMessenger: messenger, api: instance) | ||
| registrar.addApplicationDelegate(instance) | ||
| } | ||
|
|
||
| private let shortcutItemProvider: ShortcutItemProviding | ||
| private let shortcutItemParser: ShortcutItemParser = DefaultShortcutItemParser() | ||
| private let flutterApi: IOSQuickActionsFlutterApiProtocol | ||
| /// The type of the shortcut item selected when launching the app. | ||
| private var launchingShortcutType: String? = nil | ||
|
|
||
| // This init is meant for unit testing only. | ||
| init( | ||
| flutterApi: IOSQuickActionsFlutterApiProtocol, | ||
| shortcutItemProvider: ShortcutItemProviding = UIApplication.shared | ||
|
|
@@ -28,27 +27,19 @@ public final class QuickActionsPlugin: NSObject, FlutterPlugin, IOSQuickActionsA | |
| self.shortcutItemProvider = shortcutItemProvider | ||
| } | ||
|
|
||
| convenience init( | ||
| messenger: FlutterBinaryMessenger, | ||
| shortcutItemProvider: ShortcutItemProviding = UIApplication.shared | ||
| ) { | ||
| let flutterApi = IOSQuickActionsFlutterApi(binaryMessenger: messenger) | ||
| self.init(flutterApi: flutterApi, shortcutItemProvider: shortcutItemProvider) | ||
| } | ||
|
|
||
| func setShortcutItems(itemsList: [ShortcutItemMessage]) { | ||
| shortcutItemProvider.shortcutItems = shortcutItemParser.parseShortcutItems(itemsList) | ||
| self.shortcutItemProvider.shortcutItems = QuickActionsPlugin.parseShortcutItems(itemsList) | ||
| } | ||
|
|
||
| func clearShortcutItems() { | ||
| shortcutItemProvider.shortcutItems = [] | ||
| self.shortcutItemProvider.shortcutItems = [] | ||
| } | ||
|
|
||
| public func application( | ||
| _ application: UIApplication, performActionFor shortcutItem: UIApplicationShortcutItem, | ||
| completionHandler: @escaping (Bool) -> Void | ||
| ) -> Bool { | ||
| handleShortcut(shortcutItem.type) | ||
| self.handleShortcut(shortcutItem.type) | ||
| return true | ||
| } | ||
|
|
||
|
|
@@ -75,14 +66,38 @@ public final class QuickActionsPlugin: NSObject, FlutterPlugin, IOSQuickActionsA | |
|
|
||
| public func applicationDidBecomeActive(_ application: UIApplication) { | ||
| if let shortcutType = launchingShortcutType { | ||
| handleShortcut(shortcutType) | ||
| self.handleShortcut(shortcutType) | ||
| self.launchingShortcutType = nil | ||
| } | ||
| } | ||
|
|
||
| func handleShortcut(_ shortcut: String) { | ||
| flutterApi.launchAction(action: shortcut) { _ in | ||
| self.flutterApi.launchAction(action: shortcut) { _ in | ||
| // noop | ||
| } | ||
| } | ||
|
|
||
| static func parseShortcutItems(_ items: [ShortcutItemMessage]) -> [UIApplicationShortcutItem] { | ||
|
||
| return items.compactMap { deserializeShortcutItem(with: $0) } | ||
| } | ||
|
|
||
| static private func deserializeShortcutItem(with serialized: ShortcutItemMessage) | ||
| -> UIApplicationShortcutItem? | ||
| { | ||
|
|
||
| let type = serialized.type | ||
| let localizedTitle = serialized.localizedTitle | ||
|
|
||
| let icon = (serialized.icon).map { | ||
| UIApplicationShortcutIcon(templateImageName: $0) | ||
| } | ||
|
|
||
| // type and localizedTitle are required. | ||
| return UIApplicationShortcutItem( | ||
| type: type, | ||
| localizedTitle: localizedTitle, | ||
| localizedSubtitle: nil, | ||
| icon: icon, | ||
| userInfo: nil) | ||
| } | ||
| } | ||
tarrinneal marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
This file was deleted.
Uh oh!
There was an error while loading. Please reload this page.