Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
6e7f572
Basic iOS implementation
spesholized Apr 27, 2022
b4e8697
Merge branch 'flutter:main' into main
spesholized Apr 28, 2022
75a1bdc
[file_selector] Basic iOS implementation
spesholized Apr 27, 2022
15f2741
Merge branch 'main' of https://github.com/spesholized/plugins
spesholized Apr 28, 2022
62c60cb
Fix formatting and update environment sdk version
spesholized Apr 28, 2022
696cb78
Basic native unit test for plugin
spesholized Apr 29, 2022
11504f4
Update packages/file_selector/file_selector_ios/example/ios/Runner.xc…
spesholized May 2, 2022
252e110
Add placeholder integration test
spesholized May 3, 2022
cb76a80
Remove unused overrides in file_selector_ios.dart, update pubspec
spesholized May 25, 2022
ecfad9a
Use pigeon, fix Obj-C prefix typo
spesholized May 26, 2022
4ecda0e
Add native unit tests
spesholized May 27, 2022
2a69911
Update tests to use pigeon, change prefix to FFS, update wildcard typ…
spesholized Aug 2, 2022
38742a3
Use non-null properties in messages.dart, use objc associated for the…
spesholized Aug 2, 2022
ec291b6
Merge branch 'main' into file_selector_ios
stuartmorgan-g Aug 19, 2022
f0bbcf1
Remove local analysis options
stuartmorgan-g Aug 19, 2022
edc2881
Resync examples and tweak UTIs
stuartmorgan-g Aug 19, 2022
e521edc
Analysis fixes
stuartmorgan-g Aug 19, 2022
eabcce5
Autoformat
stuartmorgan-g Aug 19, 2022
d39d953
Missing copyright header
stuartmorgan-g Aug 19, 2022
170c260
Supress deprecation warning on legacy codepath
stuartmorgan-g Aug 19, 2022
129a097
Review comments
stuartmorgan-g Aug 21, 2022
0cfa61c
Format
stuartmorgan-g Aug 22, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Autoformat
  • Loading branch information
stuartmorgan-g committed Aug 19, 2022
commit eabcce5c16ec2a7073682af4e88138b9b756fff4
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
#import "messages.g.h"

// This header is available in the Test module. Import via "@import file_selector_ios.Test;".
@interface FFSFileSelectorPlugin() <FFSFileSelectorApi, UIDocumentPickerDelegate>
@interface FFSFileSelectorPlugin () <FFSFileSelectorApi, UIDocumentPickerDelegate>

/**
* Overrides the view controller used for presenting the document picker.
*/
@property(nonatomic) UIViewController * _Nullable presentingViewControllerOverride;
@property(nonatomic) UIViewController *_Nullable presentingViewControllerOverride;

/**
* Overrides the UIDocumentPickerViewController used for file picking.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,21 @@ 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:(NSNumber *)allowMultiSelection;
@property(nonatomic, strong) NSArray<NSString *> *utis;
@property(nonatomic, strong) NSNumber *allowMultiSelection;
@end

/// The codec used by FFSFileSelectorApi.
NSObject<FlutterMessageCodec> *FFSFileSelectorApiGetCodec(void);

@protocol FFSFileSelectorApi
- (void)openFileSelectorWithConfig:(FFSFileSelectorConfig *)config completion:(void(^)(NSArray<NSString *> *_Nullable, FlutterError *_Nullable))completion;
- (void)openFileSelectorWithConfig:(FFSFileSelectorConfig *)config
completion:(void (^)(NSArray<NSString *> *_Nullable,
FlutterError *_Nullable))completion;
@end

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

NS_ASSUME_NONNULL_END
73 changes: 37 additions & 36 deletions packages/file_selector/file_selector_ios/ios/Classes/messages.g.m
Original file line number Diff line number Diff line change
Expand Up @@ -14,26 +14,25 @@
NSDictionary *errorDict = (NSDictionary *)[NSNull null];
if (error) {
errorDict = @{
@"code": (error.code ?: [NSNull null]),
@"message": (error.message ?: [NSNull null]),
@"details": (error.details ?: [NSNull null]),
};
@"code" : (error.code ?: [NSNull null]),
@"message" : (error.message ?: [NSNull null]),
@"details" : (error.details ?: [NSNull null]),
};
}
return @{
@"result": (result ?: [NSNull null]),
@"error": errorDict,
};
@"result" : (result ?: [NSNull null]),
@"error" : errorDict,
};
}
static id GetNullableObject(NSDictionary* dict, id key) {
static id GetNullableObject(NSDictionary *dict, id key) {
id result = dict[key];
return (result == [NSNull null]) ? nil : result;
}
static id GetNullableObjectAtIndex(NSArray* array, NSInteger key) {
static id GetNullableObjectAtIndex(NSArray *array, NSInteger key) {
id result = array[key];
return (result == [NSNull null]) ? nil : result;
}


@interface FFSFileSelectorConfig ()
+ (FFSFileSelectorConfig *)fromMap:(NSDictionary *)dict;
+ (nullable FFSFileSelectorConfig *)nullableFromMap:(NSDictionary *)dict;
Expand All @@ -42,8 +41,8 @@ - (NSDictionary *)toMap;

@implementation FFSFileSelectorConfig
+ (instancetype)makeWithUtis:(NSArray<NSString *> *)utis
allowMultiSelection:(NSNumber *)allowMultiSelection {
FFSFileSelectorConfig* pigeonResult = [[FFSFileSelectorConfig alloc] init];
allowMultiSelection:(NSNumber *)allowMultiSelection {
FFSFileSelectorConfig *pigeonResult = [[FFSFileSelectorConfig alloc] init];
pigeonResult.utis = utis;
pigeonResult.allowMultiSelection = allowMultiSelection;
return pigeonResult;
Expand All @@ -56,7 +55,9 @@ + (FFSFileSelectorConfig *)fromMap:(NSDictionary *)dict {
NSAssert(pigeonResult.allowMultiSelection != nil, @"");
return pigeonResult;
}
+ (nullable FFSFileSelectorConfig *)nullableFromMap:(NSDictionary *)dict { return (dict) ? [FFSFileSelectorConfig fromMap:dict] : nil; }
+ (nullable FFSFileSelectorConfig *)nullableFromMap:(NSDictionary *)dict {
return (dict) ? [FFSFileSelectorConfig fromMap:dict] : nil;
}
- (NSDictionary *)toMap {
return @{
@"utis" : (self.utis ?: [NSNull null]),
Expand All @@ -68,29 +69,25 @@ - (NSDictionary *)toMap {
@interface FFSFileSelectorApiCodecReader : FlutterStandardReader
@end
@implementation FFSFileSelectorApiCodecReader
- (nullable id)readValueOfType:(UInt8)type
{
- (nullable id)readValueOfType:(UInt8)type {
switch (type) {
case 128:
case 128:
return [FFSFileSelectorConfig fromMap:[self readValue]];
default:

default:
return [super readValueOfType:type];

}
}
@end

@interface FFSFileSelectorApiCodecWriter : FlutterStandardWriter
@end
@implementation FFSFileSelectorApiCodecWriter
- (void)writeValue:(id)value
{
- (void)writeValue:(id)value {
if ([value isKindOfClass:[FFSFileSelectorConfig class]]) {
[self writeByte:128];
[self writeValue:[value toMap]];
} else
{
} else {
[super writeValue:value];
}
}
Expand All @@ -111,31 +108,35 @@ - (FlutterStandardReader *)readerWithData:(NSData *)data {
static dispatch_once_t sPred = 0;
static FlutterStandardMessageCodec *sSharedObject = nil;
dispatch_once(&sPred, ^{
FFSFileSelectorApiCodecReaderWriter *readerWriter = [[FFSFileSelectorApiCodecReaderWriter alloc] init];
FFSFileSelectorApiCodecReaderWriter *readerWriter =
[[FFSFileSelectorApiCodecReaderWriter alloc] init];
sSharedObject = [FlutterStandardMessageCodec codecWithReaderWriter:readerWriter];
});
return sSharedObject;
}


void FFSFileSelectorApiSetup(id<FlutterBinaryMessenger> binaryMessenger, NSObject<FFSFileSelectorApi> *api) {
void FFSFileSelectorApiSetup(id<FlutterBinaryMessenger> binaryMessenger,
NSObject<FFSFileSelectorApi> *api) {
{
FlutterBasicMessageChannel *channel =
[[FlutterBasicMessageChannel alloc]
initWithName:@"dev.flutter.pigeon.FileSelectorApi.openFile"
FlutterBasicMessageChannel *channel = [[FlutterBasicMessageChannel alloc]
initWithName:@"dev.flutter.pigeon.FileSelectorApi.openFile"
binaryMessenger:binaryMessenger
codec:FFSFileSelectorApiGetCodec() ];
codec:FFSFileSelectorApiGetCodec()];
if (api) {
NSCAssert([api respondsToSelector:@selector(openFileSelectorWithConfig:completion:)], @"FFSFileSelectorApi api (%@) doesn't respond to @selector(openFileSelectorWithConfig:completion:)", api);
NSCAssert([api respondsToSelector:@selector(openFileSelectorWithConfig:completion:)],
@"FFSFileSelectorApi api (%@) doesn't respond to "
@"@selector(openFileSelectorWithConfig:completion:)",
api);
[channel setMessageHandler:^(id _Nullable message, FlutterReply callback) {
NSArray *args = message;
FFSFileSelectorConfig *arg_config = GetNullableObjectAtIndex(args, 0);
[api openFileSelectorWithConfig:arg_config completion:^(NSArray<NSString *> *_Nullable output, FlutterError *_Nullable error) {
callback(wrapResult(output, error));
}];
[api openFileSelectorWithConfig:arg_config
completion:^(NSArray<NSString *> *_Nullable output,
FlutterError *_Nullable error) {
callback(wrapResult(output, error));
}];
}];
}
else {
} else {
[channel setMessageHandler:nil];
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,20 +42,19 @@ class _FileSelectorApiCodec extends StandardMessageCodec {
if (value is FileSelectorConfig) {
buffer.putUint8(128);
writeValue(buffer, value.encode());
} else
{
} else {
super.writeValue(buffer, value);
}
}

@override
Object? readValueOfType(int type, ReadBuffer buffer) {
switch (type) {
case 128:
case 128:
return FileSelectorConfig.decode(readValue(buffer)!);
default:

default:
return super.readValueOfType(type, buffer);

}
}
}
Expand All @@ -64,15 +63,17 @@ class FileSelectorApi {
/// Constructor for [FileSelectorApi]. The [binaryMessenger] named argument is
/// available for dependency injection. If it is left null, the default
/// BinaryMessenger will be used which routes to the host platform.
FileSelectorApi({BinaryMessenger? binaryMessenger}) : _binaryMessenger = binaryMessenger;
FileSelectorApi({BinaryMessenger? binaryMessenger})
: _binaryMessenger = binaryMessenger;

final BinaryMessenger? _binaryMessenger;

static const MessageCodec<Object?> codec = _FileSelectorApiCodec();

Future<List<String?>> openFile(FileSelectorConfig arg_config) async {
final BasicMessageChannel<Object?> channel = BasicMessageChannel<Object?>(
'dev.flutter.pigeon.FileSelectorApi.openFile', codec, binaryMessenger: _binaryMessenger);
'dev.flutter.pigeon.FileSelectorApi.openFile', codec,
binaryMessenger: _binaryMessenger);
final Map<Object?, Object?>? replyMap =
await channel.send(<Object?>[arg_config]) as Map<Object?, Object?>?;
if (replyMap == null) {
Expand All @@ -81,7 +82,8 @@ class FileSelectorApi {
message: 'Unable to establish connection on channel.',
);
} else if (replyMap['error'] != null) {
final Map<Object?, Object?> error = (replyMap['error'] as Map<Object?, Object?>?)!;
final Map<Object?, Object?> error =
(replyMap['error'] as Map<Object?, Object?>?)!;
throw PlatformException(
code: (error['code'] as String?)!,
message: error['message'] as String?,
Expand Down