Skip to content

Commit a02deb4

Browse files
authored
[quick_action_ios] add localizedSubtitle for iOS (#8149)
This is prequel PR for: #8038 Containing only changes to quick_action_ios package. Add the localizedSubtitle field on quick actions for iOS flutter/flutter#129759
1 parent 0f1fd49 commit a02deb4

File tree

10 files changed

+53
-18
lines changed

10 files changed

+53
-18
lines changed

packages/quick_actions/quick_actions_ios/CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
## NEXT
1+
## 1.2.0
22

3+
* Adds localizedSubtitle field for iOS quick actions.
34
* Updates minimum supported SDK version to Flutter 3.19/Dart 3.3.
45

56
## 1.1.1

packages/quick_actions/quick_actions_ios/example/ios/RunnerUITests/RunnerUITests.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,8 @@ class RunnerUITests: XCTestCase {
7575
}
7676

7777
findAndTapQuickActionButton(
78-
buttonName: "Action one", quickActionsAppIcon: quickActionsAppIcon, springboard: springboard)
78+
buttonName: "Action one, Action one subtitle", quickActionsAppIcon: quickActionsAppIcon,
79+
springboard: springboard)
7980

8081
let actionOneConfirmation = exampleApp.otherElements["action_one"]
8182
if !actionOneConfirmation.waitForExistence(timeout: elementWaitingTime) {

packages/quick_actions/quick_actions_ios/example/lib/main.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ class _MyHomePageState extends State<MyHomePage> {
5151
const ShortcutItem(
5252
type: 'action_one',
5353
localizedTitle: 'Action one',
54+
localizedSubtitle: 'Action one subtitle',
5455
icon: 'AppIcon',
5556
),
5657
const ShortcutItem(

packages/quick_actions/quick_actions_ios/ios/quick_actions_ios/Sources/quick_actions_ios/QuickActionsPlugin.swift

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -90,18 +90,15 @@ public final class QuickActionsPlugin: NSObject, FlutterPlugin, IOSQuickActionsA
9090
-> UIApplicationShortcutItem?
9191
{
9292

93-
let type = shortcut.type
94-
let localizedTitle = shortcut.localizedTitle
95-
9693
let icon = (shortcut.icon).map {
9794
UIApplicationShortcutIcon(templateImageName: $0)
9895
}
9996

10097
// type and localizedTitle are required.
10198
return UIApplicationShortcutItem(
102-
type: type,
103-
localizedTitle: localizedTitle,
104-
localizedSubtitle: nil,
99+
type: shortcut.type,
100+
localizedTitle: shortcut.localizedTitle,
101+
localizedSubtitle: shortcut.localizedSubtitle,
105102
icon: icon,
106103
userInfo: nil)
107104
}

packages/quick_actions/quick_actions_ios/ios/quick_actions_ios/Sources/quick_actions_ios/messages.g.swift

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,29 +81,35 @@ struct ShortcutItemMessage {
8181
var type: String
8282
/// Localized title of the item.
8383
var localizedTitle: String
84+
/// Localized subtitle of the item.
85+
var localizedSubtitle: String? = nil
8486
/// Name of native resource to be displayed as the icon for this item.
8587
var icon: String? = nil
8688

8789
// swift-format-ignore: AlwaysUseLowerCamelCase
8890
static func fromList(_ __pigeon_list: [Any?]) -> ShortcutItemMessage? {
8991
let type = __pigeon_list[0] as! String
9092
let localizedTitle = __pigeon_list[1] as! String
91-
let icon: String? = nilOrValue(__pigeon_list[2])
93+
let localizedSubtitle: String? = nilOrValue(__pigeon_list[2])
94+
let icon: String? = nilOrValue(__pigeon_list[3])
9295

9396
return ShortcutItemMessage(
9497
type: type,
9598
localizedTitle: localizedTitle,
99+
localizedSubtitle: localizedSubtitle,
96100
icon: icon
97101
)
98102
}
99103
func toList() -> [Any?] {
100104
return [
101105
type,
102106
localizedTitle,
107+
localizedSubtitle,
103108
icon,
104109
]
105110
}
106111
}
112+
107113
private class messagesPigeonCodecReader: FlutterStandardReader {
108114
override func readValue(ofType type: UInt8) -> Any? {
109115
switch type {
@@ -195,12 +201,14 @@ class IOSQuickActionsApiSetup {
195201
}
196202
}
197203
}
204+
198205
/// Generated protocol from Pigeon that represents Flutter messages that can be called from Swift.
199206
protocol IOSQuickActionsFlutterApiProtocol {
200207
/// Sends a string representing a shortcut from the native platform to the app.
201208
func launchAction(
202209
action actionArg: String, completion: @escaping (Result<Void, PigeonError>) -> Void)
203210
}
211+
204212
class IOSQuickActionsFlutterApi: IOSQuickActionsFlutterApiProtocol {
205213
private let binaryMessenger: FlutterBinaryMessenger
206214
private let messageChannelSuffix: String

packages/quick_actions/quick_actions_ios/lib/messages.g.dart

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ class ShortcutItemMessage {
3434
ShortcutItemMessage({
3535
required this.type,
3636
required this.localizedTitle,
37+
this.localizedSubtitle,
3738
this.icon,
3839
});
3940

@@ -43,13 +44,17 @@ class ShortcutItemMessage {
4344
/// Localized title of the item.
4445
String localizedTitle;
4546

47+
/// Localized subtitle of the item.
48+
String? localizedSubtitle;
49+
4650
/// Name of native resource to be displayed as the icon for this item.
4751
String? icon;
4852

4953
Object encode() {
5054
return <Object?>[
5155
type,
5256
localizedTitle,
57+
localizedSubtitle,
5358
icon,
5459
];
5560
}
@@ -59,7 +64,8 @@ class ShortcutItemMessage {
5964
return ShortcutItemMessage(
6065
type: result[0]! as String,
6166
localizedTitle: result[1]! as String,
62-
icon: result[2] as String?,
67+
localizedSubtitle: result[2] as String?,
68+
icon: result[3] as String?,
6369
);
6470
}
6571
}

packages/quick_actions/quick_actions_ios/lib/quick_actions_ios.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ class QuickActionsIos extends QuickActionsPlatform {
4747
return ShortcutItemMessage(
4848
type: item.type,
4949
localizedTitle: item.localizedTitle,
50+
localizedSubtitle: item.localizedSubtitle,
5051
icon: item.icon,
5152
);
5253
}

packages/quick_actions/quick_actions_ios/pigeons/messages.dart

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ class ShortcutItemMessage {
1515
ShortcutItemMessage(
1616
this.type,
1717
this.localizedTitle,
18+
this.localizedSubtitle,
1819
this.icon,
1920
);
2021

@@ -24,6 +25,9 @@ class ShortcutItemMessage {
2425
/// Localized title of the item.
2526
String localizedTitle;
2627

28+
/// Localized subtitle of the item.
29+
String? localizedSubtitle;
30+
2731
/// Name of native resource to be displayed as the icon for this item.
2832
String? icon;
2933
}

packages/quick_actions/quick_actions_ios/pubspec.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: quick_actions_ios
22
description: An implementation for the iOS platform of the Flutter `quick_actions` plugin.
33
repository: https://github.com/flutter/packages/tree/main/packages/quick_actions/quick_actions_ios
44
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+in_app_purchase%22
5-
version: 1.1.1
5+
version: 1.2.0
66

77
environment:
88
sdk: ^3.3.0
@@ -19,7 +19,7 @@ flutter:
1919
dependencies:
2020
flutter:
2121
sdk: flutter
22-
quick_actions_platform_interface: ^1.0.0
22+
quick_actions_platform_interface: ^1.1.0
2323

2424
dev_dependencies:
2525
flutter_test:

packages/quick_actions/quick_actions_ios/test/quick_actions_ios_test.dart

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,19 +26,28 @@ void main() {
2626

2727
test('setShortcutItems', () async {
2828
await quickActions.initialize((String type) {});
29-
const ShortcutItem item =
30-
ShortcutItem(type: 'test', localizedTitle: 'title', icon: 'icon.svg');
29+
const ShortcutItem item = ShortcutItem(
30+
type: 'test',
31+
localizedTitle: 'title',
32+
localizedSubtitle: 'subtitle',
33+
icon: 'icon.svg',
34+
);
3135
await quickActions.setShortcutItems(<ShortcutItem>[item]);
3236

3337
expect(api.items.first.type, item.type);
3438
expect(api.items.first.localizedTitle, item.localizedTitle);
39+
expect(api.items.first.localizedSubtitle, item.localizedSubtitle);
3540
expect(api.items.first.icon, item.icon);
3641
});
3742

3843
test('clearShortCutItems', () {
3944
quickActions.initialize((String type) {});
40-
const ShortcutItem item =
41-
ShortcutItem(type: 'test', localizedTitle: 'title', icon: 'icon.svg');
45+
const ShortcutItem item = ShortcutItem(
46+
type: 'test',
47+
localizedTitle: 'title',
48+
localizedSubtitle: 'subtitle',
49+
icon: 'icon.svg',
50+
);
4251
quickActions.setShortcutItems(<ShortcutItem>[item]);
4352
quickActions.clearShortcutItems();
4453

@@ -48,13 +57,19 @@ void main() {
4857
test('Shortcut item can be constructed', () {
4958
const String type = 'type';
5059
const String localizedTitle = 'title';
60+
const String localizedSubtitle = 'subtitle';
5161
const String icon = 'foo';
5262

53-
const ShortcutItem item =
54-
ShortcutItem(type: type, localizedTitle: localizedTitle, icon: icon);
63+
const ShortcutItem item = ShortcutItem(
64+
type: type,
65+
localizedTitle: localizedTitle,
66+
localizedSubtitle: localizedSubtitle,
67+
icon: icon,
68+
);
5569

5670
expect(item.type, type);
5771
expect(item.localizedTitle, localizedTitle);
72+
expect(item.localizedSubtitle, localizedSubtitle);
5873
expect(item.icon, icon);
5974
});
6075
}
@@ -83,6 +98,7 @@ ShortcutItem shortcutItemMessageToShortcutItem(ShortcutItemMessage item) {
8398
return ShortcutItem(
8499
type: item.type,
85100
localizedTitle: item.localizedTitle,
101+
localizedSubtitle: item.localizedSubtitle,
86102
icon: item.icon,
87103
);
88104
}

0 commit comments

Comments
 (0)