Skip to content

Commit

Permalink
Merge branch 'dev-2.22'
Browse files Browse the repository at this point in the history
  • Loading branch information
birdofpreyru committed Jan 25, 2024
2 parents a7d8c61 + a0f1fc0 commit 4512e1e
Show file tree
Hide file tree
Showing 7 changed files with 317 additions and 238 deletions.
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -837,11 +837,17 @@ For more information read the [Adding an App to an App Group](https://developer.
```ts
function pickFile(options?: PickFileOptionsT): Promise<string[]>;
```
**SUPPORTED**: Android, iOS. **NOT YET SUPPORTED**: macOS, Windows.
**SUPPORTED**: Android, iOS, macOS. **NOT YET SUPPORTED**: Windows.

Prompts the user to select file(s) using a platform-provided file picker UI,
which also allows to access files outside the app sandbox.

**BEWARE:** On **macOS (Catalyst)** for this function to work you MUST go to
_Signing & Capabilities_ settings of your project, and inside its _App Sandbox_
section to set _File Access_ > _User Selected Files_ to _Read/Write_ or _Read_
value. If it is left at the default _None_ value the call to [pickFile()] will
crash the app.

- `options` &mdash; [PickFileOptionsT] &mdash; Optional parameters. By default,
this function allows user to select a single file of any kind.

Expand Down
8 changes: 4 additions & 4 deletions example/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ PODS:
- boost (1.83.0)
- CocoaAsyncSocket (7.6.5)
- DoubleConversion (1.1.6)
- dr-pogodin-react-native-fs (2.22.0):
- dr-pogodin-react-native-fs (2.22.1):
- glog
- hermes-engine
- RCT-Folly (= 2022.05.16.00)
Expand All @@ -21,7 +21,7 @@ PODS:
- ReactCommon/turbomodule/bridging
- ReactCommon/turbomodule/core
- Yoga
- dr-pogodin-react-native-static-server (0.10.3):
- dr-pogodin-react-native-static-server (0.10.4):
- glog
- hermes-engine
- RCT-Folly (= 2022.05.16.00)
Expand Down Expand Up @@ -1402,8 +1402,8 @@ SPEC CHECKSUMS:
boost: d3f49c53809116a5d38da093a8aa78bf551aed09
CocoaAsyncSocket: 065fd1e645c7abab64f7a6a2007a48038fdc6a99
DoubleConversion: fea03f2699887d960129cc54bba7e52542b6f953
dr-pogodin-react-native-fs: 01eba775da8cb4667844f809fb8f788a9a1d745d
dr-pogodin-react-native-static-server: 24deaa9bb6a60ef12c1f27689376d5896294fe38
dr-pogodin-react-native-fs: 60d98fc542ed310f57d9b497628f6e72fa2d5e2a
dr-pogodin-react-native-static-server: a0ab88663817dfc8791b3e88295d0d9b6d212c5f
FBLazyVector: fbc4957d9aa695250b55d879c1d86f79d7e69ab4
Flipper: c7a0093234c4bdd456e363f2f19b2e4b27652d44
Flipper-Boost-iOSX: fd1e2b8cbef7e662a122412d7ac5f5bea715403c
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
<dict>
<key>com.apple.security.app-sandbox</key>
<true/>
<key>com.apple.security.files.user-selected.read-write</key>
<true/>
<key>com.apple.security.network.client</key>
<true/>
<key>com.apple.security.network.server</key>
Expand Down
12 changes: 6 additions & 6 deletions example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,22 @@
"build:ios": "cd ios && xcodebuild -workspace ReactNativeFsExample.xcworkspace -scheme ReactNativeFsExample -configuration Debug -sdk iphonesimulator CC=clang CPLUSPLUS=clang++ LD=clang LDPLUSPLUS=clang++ GCC_OPTIMIZATION_LEVEL=0 GCC_PRECOMPILE_PREFIX_HEADER=YES ASSETCATALOG_COMPILER_OPTIMIZATION=time DEBUG_INFORMATION_FORMAT=dwarf COMPILER_INDEX_STORE_ENABLE=NO"
},
"dependencies": {
"@dr.pogodin/react-native-static-server": "^0.10.3",
"@dr.pogodin/react-native-static-server": "^0.10.4",
"@types/lodash": "^4.14.202",
"lodash": "^4.17.21",
"react": "^18.2.0",
"react-native": "0.73.2",
"react-native-windows": "^0.73.4"
},
"devDependencies": {
"@babel/core": "^7.23.7",
"@babel/preset-env": "^7.23.8",
"@babel/runtime": "^7.23.8",
"@react-native/babel-preset": "^0.73.19",
"@babel/core": "^7.23.9",
"@babel/preset-env": "^7.23.9",
"@babel/runtime": "^7.23.9",
"@react-native/babel-preset": "^0.73.20",
"@react-native/metro-config": "^0.73.3",
"@react-native/typescript-config": "^0.73.1",
"babel-plugin-module-resolver": "^5.0.0",
"metro-config": "^0.80.4"
"metro-config": "^0.80.5"
},
"engines": {
"node": ">=18"
Expand Down
108 changes: 53 additions & 55 deletions ios/ReactNativeFs.mm
Original file line number Diff line number Diff line change
Expand Up @@ -654,9 +654,7 @@ - (instancetype) init
}
}

RCT_EXPORT_METHOD(completeHandlerIOS:(double)jobId
resolve:(RCTPromiseResolveBlock)resolve
reject:(RCTPromiseRejectBlock)reject)
RCT_EXPORT_METHOD(completeHandlerIOS:(double)jobId)
{
if (self.uuids) {
NSNumber *jid = [NSNumber numberWithDouble:jobId];
Expand All @@ -667,7 +665,6 @@ - (instancetype) init
[completionHandlers removeObjectForKey:uuid];
}
}
resolve(nil);
}

RCT_EXPORT_METHOD(uploadFiles:(JS::NativeReactNativeFs::NativeUploadFileOptionsT &)options
Expand Down Expand Up @@ -810,9 +807,6 @@ - (instancetype) init
}
}


// [PHAsset fetchAssetsWithALAssetURLs] is deprecated and not supported in Mac Catalyst
#if !TARGET_OS_UIKITFORMAC && !TARGET_OS_OSX
/**
* iOS Only: copy images from the assets-library (camera-roll) to a specific path, asuming
* JPEG-Images.
Expand All @@ -839,6 +833,8 @@ - (instancetype) init
reject: (RCTPromiseRejectBlock) reject)

{
// [PHAsset fetchAssetsWithALAssetURLs] is deprecated and not supported in Mac Catalyst
# if !TARGET_OS_UIKITFORMAC && !TARGET_OS_OSX
CGSize size = CGSizeMake(width, height);

NSURL* url = [NSURL URLWithString:imageUri];
Expand Down Expand Up @@ -905,11 +901,11 @@ - (instancetype) init

}
}];
# else
[[RNFSException NOT_IMPLEMENTED] reject:reject details:@"copyAssetsFileIOS() is not supported for macOS"];
# endif
}
#endif

// [PHAsset fetchAssetsWithALAssetURLs] is deprecated and not supported in Mac Catalyst
#if !TARGET_OS_UIKITFORMAC && !TARGET_OS_OSX
/**
* iOS Only: copy videos from the assets-library (camera-roll) to a specific path as mp4-file.
*
Expand All @@ -920,6 +916,8 @@ - (instancetype) init
resolve: (RCTPromiseResolveBlock) resolve
reject: (RCTPromiseRejectBlock) reject)
{
// [PHAsset fetchAssetsWithALAssetURLs] is deprecated and not supported in Mac Catalyst
# if !TARGET_OS_UIKITFORMAC && !TARGET_OS_OSX
NSURL* url = [NSURL URLWithString:imageUri];
//unused?
//__block NSURL* videoURL = [NSURL URLWithString:destination];
Expand Down Expand Up @@ -974,8 +972,10 @@ - (instancetype) init
}

return resolve(destination);
# else
[[RNFSException NOT_IMPLEMENTED] reject:reject details:@"copyAssetsVideoIOS() is not supported for macOS"];
# endif
}
#endif

RCT_EXPORT_METHOD(touch:(NSString*)filepath
options:(JS::NativeReactNativeFs::TouchOptions &) options
Expand Down Expand Up @@ -1139,60 +1139,58 @@ - (void)documentPickerWasCancelled:(UIDocumentPickerViewController *)picker
resolve:(RCTPromiseResolveBlock)resolve
reject:(RCTPromiseRejectBlock)reject
) {
if (TARGET_OS_MACCATALYST) {
[[RNFSException NOT_IMPLEMENTED]
reject:reject
details:@"pickFile() does not work on macOS yet"];
return;
}

dispatch_async(dispatch_get_main_queue(), ^() {
UIDocumentPickerViewController *picker;
@try {
UIDocumentPickerViewController *picker;

# ifdef RCT_NEW_ARCH_ENABLED
facebook::react::LazyVector<NSString*> mimeTypes = options.mimeTypes();
int numMimeTypes = mimeTypes.size();
facebook::react::LazyVector<NSString*> mimeTypes = options.mimeTypes();
int numMimeTypes = mimeTypes.size();
# else
NSArray<NSString*>* mimeTypes = options[@"mimeTypes"];
int numMimeTypes = mimeTypes.count;
NSArray<NSString*>* mimeTypes = options[@"mimeTypes"];
int numMimeTypes = mimeTypes.count;
# endif

if (@available(iOS 14.0, *)) {
NSMutableArray<UTType*> *types = [NSMutableArray arrayWithCapacity:numMimeTypes];
for (int i = 0; i < numMimeTypes; ++i) {
NSString *mime = mimeTypes[i];
UTType *type;
if ([mime isEqual:@"*/*"]) type = UTTypeItem;
else type = [UTType typeWithMIMEType:mime];
[types addObject:type];
if (@available(iOS 14.0, *)) {
NSMutableArray<UTType*> *types = [NSMutableArray arrayWithCapacity:numMimeTypes];
for (int i = 0; i < numMimeTypes; ++i) {
NSString *mime = mimeTypes[i];
UTType *type;
if ([mime isEqual:@"*/*"]) type = UTTypeItem;
else type = [UTType typeWithMIMEType:mime];
[types addObject:type];
}
picker = [[UIDocumentPickerViewController alloc]
initForOpeningContentTypes:types];
} else {
// TODO: There is no UTType object on iOS < 14.0, just UTType strings that
// can be found here:
// https://developer.apple.com/library/archive/documentation/Miscellaneous/Reference/UTIRef/Articles/System-DeclaredUniformTypeIdentifiers.html#//apple_ref/doc/uid/TP40009259-SW1
// though I have not found a function for converting MIME types into UTTypes
// on iOS < 14.0. If the only option is to implement this conversion ourselves,
// at least for now we can leave without iOS < 14.0 support (RN presumably
// supports iOS 13.4 and above, but according to Wiki iOS 13.x are considered
// obsolete by now, and presumably all devices running iOS 13.x originally
// have been upgraded to iOS 14+ by now).
[[RNFSException NOT_IMPLEMENTED]
reject:reject details:@"pickFile() is implemented for iOS 14+ only"];
return;
}
picker = [[UIDocumentPickerViewController alloc]
initForOpeningContentTypes:types];
} else {
// TODO: There is no UTType object on iOS < 14.0, just UTType strings that
// can be found here:
// https://developer.apple.com/library/archive/documentation/Miscellaneous/Reference/UTIRef/Articles/System-DeclaredUniformTypeIdentifiers.html#//apple_ref/doc/uid/TP40009259-SW1
// though I have not found a function for converting MIME types into UTTypes
// on iOS < 14.0. If the only option is to implement this conversion ourselves,
// at least for now we can leave without iOS < 14.0 support (RN presumably
// supports iOS 13.4 and above, but according to Wiki iOS 13.x are considered
// obsolete by now, and presumably all devices running iOS 13.x originally
// have been upgraded to iOS 14+ by now).
[[RNFSException NOT_IMPLEMENTED]
reject:reject details:@"pickFile() is implemented for iOS 14+ only"];
return;
}

UIViewController *root = RCTPresentedViewController();
UIViewController *root = RCTPresentedViewController();

// Note: This is needed because the module overall runs on a dedicated queue
// (see its methodQueue() method below), while interaction with UI should be
// done on the main thread queue.
// Note: This is needed because the module overall runs on a dedicated queue
// (see its methodQueue() method below), while interaction with UI should be
// done on the main thread queue.

picker.delegate = self;
[pendingPickFilePromises setObject:@[resolve, reject]
forKey:[NSValue valueWithPointer:(void*)picker]];
[root presentViewController:picker animated:YES completion:nil];
picker.delegate = self;
[pendingPickFilePromises setObject:@[resolve, reject]
forKey:[NSValue valueWithPointer:(void*)picker]];
[root presentViewController:picker animated:YES completion:nil];
}
@catch (NSException *e) {
[[RNFSException from:e] reject:reject];
}
});
}

Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@dr.pogodin/react-native-fs",
"version": "2.22.0",
"version": "2.22.1",
"description": "Native filesystem access for react-native",
"main": "lib/commonjs/index",
"module": "lib/module/index",
Expand Down Expand Up @@ -57,7 +57,7 @@
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-prettier": "^5.1.3",
"jest": "^29.7.0",
"metro-config": "^0.80.4",
"metro-config": "^0.80.5",
"pod-install": "^0.2.0",
"prettier": "^3.2.4",
"react": "18.2.0",
Expand Down
Loading

0 comments on commit 4512e1e

Please sign in to comment.