Skip to content

Instantly share code, notes, and snippets.

@jayala
Created March 27, 2022 15:02
Show Gist options
  • Save jayala/6bf869c77e86ff6477e267baa6d74db1 to your computer and use it in GitHub Desktop.
Save jayala/6bf869c77e86ff6477e267baa6d74db1 to your computer and use it in GitHub Desktop.
RCT_EXPORT_METHOD(pick:(NSDictionary *)options
resolver:(RCTPromiseResolveBlock)resolve
rejecter:(RCTPromiseRejectBlock)reject)
{
mode = options[@"mode"] && [options[@"mode"] isEqualToString:@"open"] ? UIDocumentPickerModeOpen : UIDocumentPickerModeImport;
copyDestination = options[@"copyTo"];
UIModalPresentationStyle presentationStyle = [RCTConvert UIModalPresentationStyle:options[@"presentationStyle"]];
[promiseWrapper setPromiseWithInProgressCheck:resolve rejecter:reject fromCallSite:@"pick"];
NSArray *allowedUTIs = [RCTConvert NSArray:options[OPTION_TYPE]];
UIDocumentPickerViewController *documentPicker = [[UIDocumentPickerViewController alloc] initWithDocumentTypes:allowedUTIs inMode:mode];
documentPicker.modalPresentationStyle = presentationStyle;
documentPicker.delegate = self;
documentPicker.presentationController.delegate = self;
documentPicker.allowsMultipleSelection = [RCTConvert BOOL:options[OPTION_MULTIPLE]];
UIViewController *rootViewController = RCTPresentedViewController();
[rootViewController presentViewController:documentPicker animated:YES completion:nil];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment