Skip to content

Commit

Permalink
feat: add presentationStyle option on iOS (#1961)
Browse files Browse the repository at this point in the history
Resolves #1820
  • Loading branch information
luoxuhai committed Apr 27, 2022
1 parent 8657dd6 commit d650952
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ The `callback` will be called with a response object, refer to [The Response Obj
| includeExtra | OK | OK | If true, will include extra data which requires library permissions to be requested (i.e. exif data) |
| saveToPhotos | OK | OK | (Boolean) Only for launchCamera, saves the image/video file captured to public photo |
| selectionLimit | OK | OK | Default is `1`, use `0` to allow any number of files. Only iOS version >= 14 support `0` and also it supports providing any integer value |
| presentationStyle | OK | NO | Controls how the picker is presented. 'pageSheet', 'fullScreen', 'pageSheet', 'formSheet', 'popover', 'overFullScreen', 'overCurrentContext'. Default is 'currentContext' |
## The Response Object
Expand Down
20 changes: 20 additions & 0 deletions ios/ImagePickerManager.h
Original file line number Diff line number Diff line change
@@ -1,11 +1,31 @@
#import <React/RCTBridgeModule.h>
#import <UIKit/UIKit.h>
#import <React/RCTConvert.h>

typedef NS_ENUM(NSInteger, RNImagePickerTarget) {
camera = 1,
library
};

@implementation RCTConvert(PresentationStyle)

// see: https://developer.apple.com/documentation/uikit/uimodalpresentationstyle?language=objc
RCT_ENUM_CONVERTER(
UIModalPresentationStyle,
(@{
@"currentContext": @(UIModalPresentationCurrentContext),
@"fullScreen": @(UIModalPresentationFullScreen),
@"pageSheet": @(UIModalPresentationPageSheet),
@"formSheet": @(UIModalPresentationFormSheet),
@"popover": @(UIModalPresentationPopover),
@"overFullScreen": @(UIModalPresentationOverFullScreen),
@"overCurrentContext": @(UIModalPresentationOverCurrentContext)
}),
UIModalPresentationCurrentContext,
integerValue)

@end

@interface ImagePickerManager : NSObject <RCTBridgeModule>

@end
1 change: 1 addition & 0 deletions ios/ImagePickerManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ - (void)launchImagePicker:(NSDictionary *)options callback:(RCTResponseSenderBlo
PHPickerConfiguration *configuration = [ImagePickerUtils makeConfigurationFromOptions:options target:target];
PHPickerViewController *picker = [[PHPickerViewController alloc] initWithConfiguration:configuration];
picker.delegate = self;
picker.modalPresentationStyle = [RCTConvert UIModalPresentationStyle:options[@"presentationStyle"]];
picker.presentationController.delegate = self;

if([self.options[@"includeExtra"] boolValue]) {
Expand Down
2 changes: 1 addition & 1 deletion ios/ImagePickerUtils.m
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ + (void) setupPickerFromOptions:(UIImagePickerController *)picker options:(NSDic
picker.mediaTypes = @[(NSString *)kUTTypeImage, (NSString *)kUTTypeMovie];
}

picker.modalPresentationStyle = UIModalPresentationCurrentContext;
picker.modalPresentationStyle = [RCTConvert UIModalPresentationStyle:options[@"presentationStyle"]];
}

+ (PHPickerConfiguration *)makeConfigurationFromOptions:(NSDictionary *)options target:(RNImagePickerTarget)target API_AVAILABLE(ios(14))
Expand Down
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ const DEFAULT_OPTIONS: ImageLibraryOptions & CameraOptions = {
saveToPhotos: false,
durationLimit: 0,
includeExtra: false,
presentationStyle: 'pageSheet'
};

export function launchCamera(options: CameraOptions, callback?: Callback) : Promise<ImagePickerResponse> {
Expand Down
8 changes: 8 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,14 @@ export interface ImageLibraryOptions {
videoQuality?: AndroidVideoOptions | iOSVideoOptions;
includeBase64?: boolean;
includeExtra?: boolean;
presentationStyle?:
| 'currentContext'
| 'fullScreen'
| 'pageSheet'
| 'formSheet'
| 'popover'
| 'overFullScreen'
| 'overCurrentContext';
}

export interface CameraOptions
Expand Down

0 comments on commit d650952

Please sign in to comment.