Skip to content

Commit

Permalink
[file_selector] Updates iOS to Pigeon 13 (flutter#5268)
Browse files Browse the repository at this point in the history
Picks up several breaking changes, including the switch to unwrapped BOOL properties.
  • Loading branch information
stuartmorgan authored Nov 1, 2023
1 parent 7dff4f1 commit 87cdab2
Show file tree
Hide file tree
Showing 8 changed files with 55 additions and 31 deletions.
4 changes: 4 additions & 0 deletions packages/file_selector/file_selector_ios/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.5.1+7

* Updates to Pigeon 13.

## 0.5.1+6

* Adds pub topics to package metadata.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ - (void)testPickerPresents {
plugin.documentPickerViewControllerOverride = picker;
plugin.presentingViewControllerOverride = mockPresentingVC;

[plugin openFileSelectorWithConfig:[FFSFileSelectorConfig makeWithUtis:@[]
allowMultiSelection:@NO]
[plugin openFileSelectorWithConfig:[FFSFileSelectorConfig makeWithUtis:@[] allowMultiSelection:NO]
completion:^(NSArray<NSString *> *paths, FlutterError *error){
}];

Expand All @@ -42,7 +41,7 @@ - (void)testReturnsPickedFiles {
inMode:UIDocumentPickerModeImport];
plugin.documentPickerViewControllerOverride = picker;
[plugin openFileSelectorWithConfig:[FFSFileSelectorConfig makeWithUtis:@[]
allowMultiSelection:@YES]
allowMultiSelection:YES]
completion:^(NSArray<NSString *> *paths, FlutterError *error) {
NSArray *expectedPaths = @[ @"/file1.txt", @"/file2.txt" ];
XCTAssertEqualObjects(paths, expectedPaths);
Expand All @@ -63,8 +62,7 @@ - (void)testCancellingPickerReturnsNil {
plugin.documentPickerViewControllerOverride = picker;

XCTestExpectation *completionWasCalled = [self expectationWithDescription:@"completion"];
[plugin openFileSelectorWithConfig:[FFSFileSelectorConfig makeWithUtis:@[]
allowMultiSelection:@NO]
[plugin openFileSelectorWithConfig:[FFSFileSelectorConfig makeWithUtis:@[] allowMultiSelection:NO]
completion:^(NSArray<NSString *> *paths, FlutterError *error) {
XCTAssertEqual(paths.count, 0);
[completionWasCalled fulfill];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ - (void)openFileSelectorWithConfig:(FFSFileSelectorConfig *)config
initWithDocumentTypes:config.utis
inMode:UIDocumentPickerModeImport];
documentPicker.delegate = self;
documentPicker.allowsMultipleSelection = config.allowMultiSelection.boolValue;
documentPicker.allowsMultipleSelection = config.allowMultiSelection;

UIViewController *presentingVC =
self.presentingViewControllerOverride
Expand All @@ -41,7 +41,7 @@ - (void)openFileSelectorWithConfig:(FFSFileSelectorConfig *)config

+ (void)registerWithRegistrar:(NSObject<FlutterPluginRegistrar> *)registrar {
FFSFileSelectorPlugin *plugin = [[FFSFileSelectorPlugin alloc] init];
FFSFileSelectorApiSetup(registrar.messenger, plugin);
SetUpFFSFileSelectorApi(registrar.messenger, plugin);
}

#pragma mark - UIDocumentPickerDelegate
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// 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.
// Autogenerated from Pigeon (v9.2.4), do not edit directly.
// Autogenerated from Pigeon (v13.0.0), do not edit directly.
// See also: https://pub.dev/packages/pigeon

#import <Foundation/Foundation.h>
Expand All @@ -19,9 +19,9 @@ NS_ASSUME_NONNULL_BEGIN
/// `init` unavailable to enforce nonnull fields, see the `make` class method.
- (instancetype)init NS_UNAVAILABLE;
+ (instancetype)makeWithUtis:(NSArray<NSString *> *)utis
allowMultiSelection:(NSNumber *)allowMultiSelection;
@property(nonatomic, strong) NSArray<NSString *> *utis;
@property(nonatomic, strong) NSNumber *allowMultiSelection;
allowMultiSelection:(BOOL)allowMultiSelection;
@property(nonatomic, copy) NSArray<NSString *> *utis;
@property(nonatomic, assign) BOOL allowMultiSelection;
@end

/// The codec used by FFSFileSelectorApi.
Expand All @@ -33,7 +33,7 @@ NSObject<FlutterMessageCodec> *FFSFileSelectorApiGetCodec(void);
FlutterError *_Nullable))completion;
@end

extern void FFSFileSelectorApiSetup(id<FlutterBinaryMessenger> binaryMessenger,
extern void SetUpFFSFileSelectorApi(id<FlutterBinaryMessenger> binaryMessenger,
NSObject<FFSFileSelectorApi> *_Nullable api);

NS_ASSUME_NONNULL_END
21 changes: 12 additions & 9 deletions packages/file_selector/file_selector_ios/ios/Classes/messages.g.m
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
// 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.
// Autogenerated from Pigeon (v9.2.4), do not edit directly.
// Autogenerated from Pigeon (v13.0.0), do not edit directly.
// See also: https://pub.dev/packages/pigeon

#import "messages.g.h"

#if TARGET_OS_OSX
#import <FlutterMacOS/FlutterMacOS.h>
#else
#import <Flutter/Flutter.h>
#endif

#if !__has_feature(objc_arc)
#error File requires ARC to be enabled.
Expand All @@ -32,7 +37,7 @@ - (NSArray *)toList;

@implementation FFSFileSelectorConfig
+ (instancetype)makeWithUtis:(NSArray<NSString *> *)utis
allowMultiSelection:(NSNumber *)allowMultiSelection {
allowMultiSelection:(BOOL)allowMultiSelection {
FFSFileSelectorConfig *pigeonResult = [[FFSFileSelectorConfig alloc] init];
pigeonResult.utis = utis;
pigeonResult.allowMultiSelection = allowMultiSelection;
Expand All @@ -41,18 +46,16 @@ + (instancetype)makeWithUtis:(NSArray<NSString *> *)utis
+ (FFSFileSelectorConfig *)fromList:(NSArray *)list {
FFSFileSelectorConfig *pigeonResult = [[FFSFileSelectorConfig alloc] init];
pigeonResult.utis = GetNullableObjectAtIndex(list, 0);
NSAssert(pigeonResult.utis != nil, @"");
pigeonResult.allowMultiSelection = GetNullableObjectAtIndex(list, 1);
NSAssert(pigeonResult.allowMultiSelection != nil, @"");
pigeonResult.allowMultiSelection = [GetNullableObjectAtIndex(list, 1) boolValue];
return pigeonResult;
}
+ (nullable FFSFileSelectorConfig *)nullableFromList:(NSArray *)list {
return (list) ? [FFSFileSelectorConfig fromList:list] : nil;
}
- (NSArray *)toList {
return @[
(self.utis ?: [NSNull null]),
(self.allowMultiSelection ?: [NSNull null]),
self.utis ?: [NSNull null],
@(self.allowMultiSelection),
];
}
@end
Expand Down Expand Up @@ -105,11 +108,11 @@ - (FlutterStandardReader *)readerWithData:(NSData *)data {
return sSharedObject;
}

void FFSFileSelectorApiSetup(id<FlutterBinaryMessenger> binaryMessenger,
void SetUpFFSFileSelectorApi(id<FlutterBinaryMessenger> binaryMessenger,
NSObject<FFSFileSelectorApi> *api) {
{
FlutterBasicMessageChannel *channel = [[FlutterBasicMessageChannel alloc]
initWithName:@"dev.flutter.pigeon.FileSelectorApi.openFile"
initWithName:@"dev.flutter.pigeon.file_selector_ios.FileSelectorApi.openFile"
binaryMessenger:binaryMessenger
codec:FFSFileSelectorApiGetCodec()];
if (api) {
Expand Down
15 changes: 13 additions & 2 deletions packages/file_selector/file_selector_ios/lib/src/messages.g.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// 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.
// Autogenerated from Pigeon (v9.2.4), do not edit directly.
// Autogenerated from Pigeon (v13.0.0), do not edit directly.
// See also: https://pub.dev/packages/pigeon
// ignore_for_file: public_member_api_docs, non_constant_identifier_names, avoid_as, unused_import, unnecessary_parenthesis, prefer_null_aware_operators, omit_local_variable_types, unused_shown_name, unnecessary_import

Expand All @@ -11,6 +11,17 @@ import 'dart:typed_data' show Float64List, Int32List, Int64List, Uint8List;
import 'package:flutter/foundation.dart' show ReadBuffer, WriteBuffer;
import 'package:flutter/services.dart';

List<Object?> wrapResponse(
{Object? result, PlatformException? error, bool empty = false}) {
if (empty) {
return <Object?>[];
}
if (error == null) {
return <Object?>[result];
}
return <Object?>[error.code, error.message, error.details];
}

class FileSelectorConfig {
FileSelectorConfig({
required this.utis,
Expand Down Expand Up @@ -72,7 +83,7 @@ class FileSelectorApi {

Future<List<String?>> openFile(FileSelectorConfig arg_config) async {
final BasicMessageChannel<Object?> channel = BasicMessageChannel<Object?>(
'dev.flutter.pigeon.FileSelectorApi.openFile', codec,
'dev.flutter.pigeon.file_selector_ios.FileSelectorApi.openFile', codec,
binaryMessenger: _binaryMessenger);
final List<Object?>? replyList =
await channel.send(<Object?>[arg_config]) as List<Object?>?;
Expand Down
4 changes: 2 additions & 2 deletions packages/file_selector/file_selector_ios/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: file_selector_ios
description: iOS implementation of the file_selector plugin.
repository: https://github.com/flutter/packages/tree/main/packages/file_selector/file_selector_ios
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+file_selector%22
version: 0.5.1+6
version: 0.5.1+7

environment:
sdk: ">=2.19.0 <4.0.0"
Expand All @@ -26,7 +26,7 @@ dev_dependencies:
flutter_test:
sdk: flutter
mockito: 5.4.1
pigeon: ^9.2.4
pigeon: ^13.0.0

topics:
- files
Expand Down
20 changes: 14 additions & 6 deletions packages/file_selector/file_selector_ios/test/test_api.g.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// 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.
// Autogenerated from Pigeon (v9.2.4), do not edit directly.
// Autogenerated from Pigeon (v13.0.0), do not edit directly.
// See also: https://pub.dev/packages/pigeon
// ignore_for_file: public_member_api_docs, non_constant_identifier_names, avoid_as, unused_import, unnecessary_parenthesis, unnecessary_import
// ignore_for_file: avoid_relative_lib_imports
Expand Down Expand Up @@ -47,7 +47,8 @@ abstract class TestFileSelectorApi {
{BinaryMessenger? binaryMessenger}) {
{
final BasicMessageChannel<Object?> channel = BasicMessageChannel<Object?>(
'dev.flutter.pigeon.FileSelectorApi.openFile', codec,
'dev.flutter.pigeon.file_selector_ios.FileSelectorApi.openFile',
codec,
binaryMessenger: binaryMessenger);
if (api == null) {
_testBinaryMessengerBinding!.defaultBinaryMessenger
Expand All @@ -57,14 +58,21 @@ abstract class TestFileSelectorApi {
.setMockDecodedMessageHandler<Object?>(channel,
(Object? message) async {
assert(message != null,
'Argument for dev.flutter.pigeon.FileSelectorApi.openFile was null.');
'Argument for dev.flutter.pigeon.file_selector_ios.FileSelectorApi.openFile was null.');
final List<Object?> args = (message as List<Object?>?)!;
final FileSelectorConfig? arg_config =
(args[0] as FileSelectorConfig?);
assert(arg_config != null,
'Argument for dev.flutter.pigeon.FileSelectorApi.openFile was null, expected non-null FileSelectorConfig.');
final List<String?> output = await api.openFile(arg_config!);
return <Object?>[output];
'Argument for dev.flutter.pigeon.file_selector_ios.FileSelectorApi.openFile was null, expected non-null FileSelectorConfig.');
try {
final List<String?> output = await api.openFile(arg_config!);
return <Object?>[output];
} on PlatformException catch (e) {
return wrapResponse(error: e);
} catch (e) {
return wrapResponse(
error: PlatformException(code: 'error', message: e.toString()));
}
});
}
}
Expand Down

0 comments on commit 87cdab2

Please sign in to comment.