From a02deb49c1f6bcb8bb895dd67fbf36ac2c9738bd Mon Sep 17 00:00:00 2001 From: Sinyu Date: Tue, 10 Dec 2024 23:59:05 +0800 Subject: [PATCH] [quick_action_ios] add localizedSubtitle for iOS (#8149) This is prequel PR for: https://github.com/flutter/packages/pull/8038 Containing only changes to quick_action_ios package. Add the localizedSubtitle field on quick actions for iOS https://github.com/flutter/flutter/issues/129759 --- .../quick_actions_ios/CHANGELOG.md | 3 +- .../ios/RunnerUITests/RunnerUITests.swift | 3 +- .../quick_actions_ios/example/lib/main.dart | 1 + .../QuickActionsPlugin.swift | 9 ++---- .../quick_actions_ios/messages.g.swift | 10 ++++++- .../quick_actions_ios/lib/messages.g.dart | 8 +++++- .../lib/quick_actions_ios.dart | 1 + .../quick_actions_ios/pigeons/messages.dart | 4 +++ .../quick_actions_ios/pubspec.yaml | 4 +-- .../test/quick_actions_ios_test.dart | 28 +++++++++++++++---- 10 files changed, 53 insertions(+), 18 deletions(-) diff --git a/packages/quick_actions/quick_actions_ios/CHANGELOG.md b/packages/quick_actions/quick_actions_ios/CHANGELOG.md index 92d4fe6b1df7..b49fb3602909 100644 --- a/packages/quick_actions/quick_actions_ios/CHANGELOG.md +++ b/packages/quick_actions/quick_actions_ios/CHANGELOG.md @@ -1,5 +1,6 @@ -## NEXT +## 1.2.0 +* Adds localizedSubtitle field for iOS quick actions. * Updates minimum supported SDK version to Flutter 3.19/Dart 3.3. ## 1.1.1 diff --git a/packages/quick_actions/quick_actions_ios/example/ios/RunnerUITests/RunnerUITests.swift b/packages/quick_actions/quick_actions_ios/example/ios/RunnerUITests/RunnerUITests.swift index ad4c03f008ea..3bc0d2109be9 100644 --- a/packages/quick_actions/quick_actions_ios/example/ios/RunnerUITests/RunnerUITests.swift +++ b/packages/quick_actions/quick_actions_ios/example/ios/RunnerUITests/RunnerUITests.swift @@ -75,7 +75,8 @@ class RunnerUITests: XCTestCase { } findAndTapQuickActionButton( - buttonName: "Action one", quickActionsAppIcon: quickActionsAppIcon, springboard: springboard) + buttonName: "Action one, Action one subtitle", quickActionsAppIcon: quickActionsAppIcon, + springboard: springboard) let actionOneConfirmation = exampleApp.otherElements["action_one"] if !actionOneConfirmation.waitForExistence(timeout: elementWaitingTime) { diff --git a/packages/quick_actions/quick_actions_ios/example/lib/main.dart b/packages/quick_actions/quick_actions_ios/example/lib/main.dart index f3e9f92b2cbb..a170376135d9 100644 --- a/packages/quick_actions/quick_actions_ios/example/lib/main.dart +++ b/packages/quick_actions/quick_actions_ios/example/lib/main.dart @@ -51,6 +51,7 @@ class _MyHomePageState extends State { const ShortcutItem( type: 'action_one', localizedTitle: 'Action one', + localizedSubtitle: 'Action one subtitle', icon: 'AppIcon', ), const ShortcutItem( diff --git a/packages/quick_actions/quick_actions_ios/ios/quick_actions_ios/Sources/quick_actions_ios/QuickActionsPlugin.swift b/packages/quick_actions/quick_actions_ios/ios/quick_actions_ios/Sources/quick_actions_ios/QuickActionsPlugin.swift index dc8ffb812f36..fb7938f7b54e 100644 --- a/packages/quick_actions/quick_actions_ios/ios/quick_actions_ios/Sources/quick_actions_ios/QuickActionsPlugin.swift +++ b/packages/quick_actions/quick_actions_ios/ios/quick_actions_ios/Sources/quick_actions_ios/QuickActionsPlugin.swift @@ -90,18 +90,15 @@ public final class QuickActionsPlugin: NSObject, FlutterPlugin, IOSQuickActionsA -> UIApplicationShortcutItem? { - let type = shortcut.type - let localizedTitle = shortcut.localizedTitle - let icon = (shortcut.icon).map { UIApplicationShortcutIcon(templateImageName: $0) } // type and localizedTitle are required. return UIApplicationShortcutItem( - type: type, - localizedTitle: localizedTitle, - localizedSubtitle: nil, + type: shortcut.type, + localizedTitle: shortcut.localizedTitle, + localizedSubtitle: shortcut.localizedSubtitle, icon: icon, userInfo: nil) } diff --git a/packages/quick_actions/quick_actions_ios/ios/quick_actions_ios/Sources/quick_actions_ios/messages.g.swift b/packages/quick_actions/quick_actions_ios/ios/quick_actions_ios/Sources/quick_actions_ios/messages.g.swift index f4a4091c333e..dbfea4f1e026 100644 --- a/packages/quick_actions/quick_actions_ios/ios/quick_actions_ios/Sources/quick_actions_ios/messages.g.swift +++ b/packages/quick_actions/quick_actions_ios/ios/quick_actions_ios/Sources/quick_actions_ios/messages.g.swift @@ -81,6 +81,8 @@ struct ShortcutItemMessage { var type: String /// Localized title of the item. var localizedTitle: String + /// Localized subtitle of the item. + var localizedSubtitle: String? = nil /// Name of native resource to be displayed as the icon for this item. var icon: String? = nil @@ -88,11 +90,13 @@ struct ShortcutItemMessage { static func fromList(_ __pigeon_list: [Any?]) -> ShortcutItemMessage? { let type = __pigeon_list[0] as! String let localizedTitle = __pigeon_list[1] as! String - let icon: String? = nilOrValue(__pigeon_list[2]) + let localizedSubtitle: String? = nilOrValue(__pigeon_list[2]) + let icon: String? = nilOrValue(__pigeon_list[3]) return ShortcutItemMessage( type: type, localizedTitle: localizedTitle, + localizedSubtitle: localizedSubtitle, icon: icon ) } @@ -100,10 +104,12 @@ struct ShortcutItemMessage { return [ type, localizedTitle, + localizedSubtitle, icon, ] } } + private class messagesPigeonCodecReader: FlutterStandardReader { override func readValue(ofType type: UInt8) -> Any? { switch type { @@ -195,12 +201,14 @@ class IOSQuickActionsApiSetup { } } } + /// Generated protocol from Pigeon that represents Flutter messages that can be called from Swift. protocol IOSQuickActionsFlutterApiProtocol { /// Sends a string representing a shortcut from the native platform to the app. func launchAction( action actionArg: String, completion: @escaping (Result) -> Void) } + class IOSQuickActionsFlutterApi: IOSQuickActionsFlutterApiProtocol { private let binaryMessenger: FlutterBinaryMessenger private let messageChannelSuffix: String diff --git a/packages/quick_actions/quick_actions_ios/lib/messages.g.dart b/packages/quick_actions/quick_actions_ios/lib/messages.g.dart index 199871ff803c..6678bbc840be 100644 --- a/packages/quick_actions/quick_actions_ios/lib/messages.g.dart +++ b/packages/quick_actions/quick_actions_ios/lib/messages.g.dart @@ -34,6 +34,7 @@ class ShortcutItemMessage { ShortcutItemMessage({ required this.type, required this.localizedTitle, + this.localizedSubtitle, this.icon, }); @@ -43,6 +44,9 @@ class ShortcutItemMessage { /// Localized title of the item. String localizedTitle; + /// Localized subtitle of the item. + String? localizedSubtitle; + /// Name of native resource to be displayed as the icon for this item. String? icon; @@ -50,6 +54,7 @@ class ShortcutItemMessage { return [ type, localizedTitle, + localizedSubtitle, icon, ]; } @@ -59,7 +64,8 @@ class ShortcutItemMessage { return ShortcutItemMessage( type: result[0]! as String, localizedTitle: result[1]! as String, - icon: result[2] as String?, + localizedSubtitle: result[2] as String?, + icon: result[3] as String?, ); } } diff --git a/packages/quick_actions/quick_actions_ios/lib/quick_actions_ios.dart b/packages/quick_actions/quick_actions_ios/lib/quick_actions_ios.dart index b002e0ec136d..e90b68333ed4 100644 --- a/packages/quick_actions/quick_actions_ios/lib/quick_actions_ios.dart +++ b/packages/quick_actions/quick_actions_ios/lib/quick_actions_ios.dart @@ -47,6 +47,7 @@ class QuickActionsIos extends QuickActionsPlatform { return ShortcutItemMessage( type: item.type, localizedTitle: item.localizedTitle, + localizedSubtitle: item.localizedSubtitle, icon: item.icon, ); } diff --git a/packages/quick_actions/quick_actions_ios/pigeons/messages.dart b/packages/quick_actions/quick_actions_ios/pigeons/messages.dart index 7cf7d20d587f..043d4ba7cc3f 100644 --- a/packages/quick_actions/quick_actions_ios/pigeons/messages.dart +++ b/packages/quick_actions/quick_actions_ios/pigeons/messages.dart @@ -15,6 +15,7 @@ class ShortcutItemMessage { ShortcutItemMessage( this.type, this.localizedTitle, + this.localizedSubtitle, this.icon, ); @@ -24,6 +25,9 @@ class ShortcutItemMessage { /// Localized title of the item. String localizedTitle; + /// Localized subtitle of the item. + String? localizedSubtitle; + /// Name of native resource to be displayed as the icon for this item. String? icon; } diff --git a/packages/quick_actions/quick_actions_ios/pubspec.yaml b/packages/quick_actions/quick_actions_ios/pubspec.yaml index b4cc92f3a897..a3ba140e2e81 100644 --- a/packages/quick_actions/quick_actions_ios/pubspec.yaml +++ b/packages/quick_actions/quick_actions_ios/pubspec.yaml @@ -2,7 +2,7 @@ name: quick_actions_ios description: An implementation for the iOS platform of the Flutter `quick_actions` plugin. repository: https://github.com/flutter/packages/tree/main/packages/quick_actions/quick_actions_ios issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+in_app_purchase%22 -version: 1.1.1 +version: 1.2.0 environment: sdk: ^3.3.0 @@ -19,7 +19,7 @@ flutter: dependencies: flutter: sdk: flutter - quick_actions_platform_interface: ^1.0.0 + quick_actions_platform_interface: ^1.1.0 dev_dependencies: flutter_test: diff --git a/packages/quick_actions/quick_actions_ios/test/quick_actions_ios_test.dart b/packages/quick_actions/quick_actions_ios/test/quick_actions_ios_test.dart index eff84081274d..b53137dcc9db 100644 --- a/packages/quick_actions/quick_actions_ios/test/quick_actions_ios_test.dart +++ b/packages/quick_actions/quick_actions_ios/test/quick_actions_ios_test.dart @@ -26,19 +26,28 @@ void main() { test('setShortcutItems', () async { await quickActions.initialize((String type) {}); - const ShortcutItem item = - ShortcutItem(type: 'test', localizedTitle: 'title', icon: 'icon.svg'); + const ShortcutItem item = ShortcutItem( + type: 'test', + localizedTitle: 'title', + localizedSubtitle: 'subtitle', + icon: 'icon.svg', + ); await quickActions.setShortcutItems([item]); expect(api.items.first.type, item.type); expect(api.items.first.localizedTitle, item.localizedTitle); + expect(api.items.first.localizedSubtitle, item.localizedSubtitle); expect(api.items.first.icon, item.icon); }); test('clearShortCutItems', () { quickActions.initialize((String type) {}); - const ShortcutItem item = - ShortcutItem(type: 'test', localizedTitle: 'title', icon: 'icon.svg'); + const ShortcutItem item = ShortcutItem( + type: 'test', + localizedTitle: 'title', + localizedSubtitle: 'subtitle', + icon: 'icon.svg', + ); quickActions.setShortcutItems([item]); quickActions.clearShortcutItems(); @@ -48,13 +57,19 @@ void main() { test('Shortcut item can be constructed', () { const String type = 'type'; const String localizedTitle = 'title'; + const String localizedSubtitle = 'subtitle'; const String icon = 'foo'; - const ShortcutItem item = - ShortcutItem(type: type, localizedTitle: localizedTitle, icon: icon); + const ShortcutItem item = ShortcutItem( + type: type, + localizedTitle: localizedTitle, + localizedSubtitle: localizedSubtitle, + icon: icon, + ); expect(item.type, type); expect(item.localizedTitle, localizedTitle); + expect(item.localizedSubtitle, localizedSubtitle); expect(item.icon, icon); }); } @@ -83,6 +98,7 @@ ShortcutItem shortcutItemMessageToShortcutItem(ShortcutItemMessage item) { return ShortcutItem( type: item.type, localizedTitle: item.localizedTitle, + localizedSubtitle: item.localizedSubtitle, icon: item.icon, ); }