Skip to content

Commit ea3abba

Browse files
committed
Merge branch 'jnpdx-fix/xcode-warnings'
* jnpdx-fix/xcode-warnings: Change deployment target to 8.0 nil checks of event bridge Fix remaining Android and iOS errors Fix Java Warnings Fix remaining iOS emitter issues Move to modern event emitter Fix Xcode warnings
2 parents 0e9c152 + 370030c commit ea3abba

File tree

12 files changed

+66
-52
lines changed

12 files changed

+66
-52
lines changed

Downloader.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ typedef void (^DownloadCompleteCallback)(NSNumber*, NSNumber*);
44
typedef void (^ErrorCallback)(NSError*);
55
typedef void (^BeginCallback)(NSNumber*, NSNumber*, NSDictionary*);
66
typedef void (^ProgressCallback)(NSNumber*, NSNumber*);
7-
typedef void (^ResumableCallback)();
7+
typedef void (^ResumableCallback)(void);
88

99
@interface RNFSDownloadParams : NSObject
1010

Downloader.m

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ - (void)URLSession:(NSURLSession *)session downloadTask:(NSURLSessionDownloadTas
9999
NSNumber* progress = [NSNumber numberWithUnsignedInt: floor(doublePercents)];
100100
if ([progress unsignedIntValue] % [_params.progressDivider integerValue] == 0) {
101101
if (([progress unsignedIntValue] != [_lastProgressValue unsignedIntValue]) || ([_bytesWritten unsignedIntegerValue] == [_contentLength longValue])) {
102-
NSLog(@"---Progress callback EMIT--- %zu", [progress unsignedIntValue]);
102+
NSLog(@"---Progress callback EMIT--- %u", [progress unsignedIntValue]);
103103
_lastProgressValue = [NSNumber numberWithUnsignedInt:[progress unsignedIntValue]];
104104
return _params.progressCallback(_contentLength, _bytesWritten);
105105
}
@@ -149,15 +149,15 @@ - (void)stopDownload
149149
[_task cancelByProducingResumeData:^(NSData * _Nullable resumeData) {
150150
if (resumeData != nil) {
151151
self.resumeData = resumeData;
152-
_params.resumableCallback();
152+
self->_params.resumableCallback();
153153
} else {
154154
NSError *error = [NSError errorWithDomain:@"RNFS"
155-
code:@"Aborted"
155+
code:0 //used to pass an NSString @"Aborted" here, but it needs an NSInteger
156156
userInfo:@{
157157
NSLocalizedDescriptionKey: @"Download has been aborted"
158158
}];
159159

160-
_params.errorCallback(error);
160+
self->_params.errorCallback(error);
161161
}
162162
}];
163163

FS.common.js

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,10 @@
99

1010
var RNFSManager = require('react-native').NativeModules.RNFSManager;
1111

12-
var NativeAppEventEmitter = require('react-native').NativeAppEventEmitter; // iOS
13-
var DeviceEventEmitter = require('react-native').DeviceEventEmitter; // Android
12+
var NativeEventEmitter = require('react-native').NativeEventEmitter;
13+
14+
var RNFS_NativeEventEmitter = new NativeEventEmitter(RNFSManager);
15+
1416
var base64 = require('base-64');
1517
var utf8 = require('utf8');
1618
var isIOS = require('react-native').Platform.OS === 'ios';
@@ -498,15 +500,15 @@ var RNFS = {
498500
var subscriptions = [];
499501

500502
if (options.begin) {
501-
subscriptions.push(NativeAppEventEmitter.addListener('DownloadBegin-' + jobId, options.begin));
503+
subscriptions.push(RNFS_NativeEventEmitter.addListener('DownloadBegin', options.begin));
502504
}
503505

504506
if (options.progress) {
505-
subscriptions.push(NativeAppEventEmitter.addListener('DownloadProgress-' + jobId, options.progress));
507+
subscriptions.push(RNFS_NativeEventEmitter.addListener('DownloadProgress', options.progress));
506508
}
507509

508510
if (options.resumable) {
509-
subscriptions.push(NativeAppEventEmitter.addListener('DownloadResumable-' + jobId, options.resumable));
511+
subscriptions.push(RNFS_NativeEventEmitter.addListener('DownloadResumable', options.resumable));
510512
}
511513

512514
var bridgeOptions = {
@@ -553,19 +555,19 @@ var RNFS = {
553555
if (options.method && typeof options.method !== 'string') throw new Error('uploadFiles: Invalid value for property `method`');
554556

555557
if (options.begin) {
556-
subscriptions.push(NativeAppEventEmitter.addListener('UploadBegin-' + jobId, options.begin));
558+
subscriptions.push(RNFS_NativeEventEmitter.addListener('UploadBegin', options.begin));
557559
}
558560
if (options.beginCallback && options.beginCallback instanceof Function) {
559561
// Deprecated
560-
subscriptions.push(NativeAppEventEmitter.addListener('UploadBegin-' + jobId, options.beginCallback));
562+
subscriptions.push(RNFS_NativeEventEmitter.addListener('UploadBegin', options.beginCallback));
561563
}
562564

563565
if (options.progress) {
564-
subscriptions.push(NativeAppEventEmitter.addListener('UploadProgress-' + jobId, options.progress));
566+
subscriptions.push(RNFS_NativeEventEmitter.addListener('UploadProgress', options.progress));
565567
}
566568
if (options.progressCallback && options.progressCallback instanceof Function) {
567569
// Deprecated
568-
subscriptions.push(NativeAppEventEmitter.addListener('UploadProgress-' + jobId, options.progressCallback));
570+
subscriptions.push(RNFS_NativeEventEmitter.addListener('UploadProgress', options.progressCallback));
569571
}
570572

571573
var bridgeOptions = {

IntegrationTests/IntegrationTests.xcodeproj/project.pbxproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -553,7 +553,7 @@
553553
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include,
554554
"$(SRCROOT)/../React/**",
555555
);
556-
IPHONEOS_DEPLOYMENT_TARGET = 7.0;
556+
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
557557
MTL_ENABLE_DEBUG_INFO = YES;
558558
ONLY_ACTIVE_ARCH = YES;
559559
SDKROOT = iphoneos;
@@ -593,7 +593,7 @@
593593
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include,
594594
"$(SRCROOT)/../React/**",
595595
);
596-
IPHONEOS_DEPLOYMENT_TARGET = 7.0;
596+
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
597597
MTL_ENABLE_DEBUG_INFO = NO;
598598
SDKROOT = iphoneos;
599599
VALIDATE_PRODUCT = YES;

RNFS.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ Pod::Spec.new do |s|
1010
s.license = pjson["license"]
1111
s.author = { "Johannes Lumpe" => "johannes@lum.pe" }
1212

13-
s.ios.deployment_target = '7.0'
13+
s.ios.deployment_target = '8.0'
1414
s.tvos.deployment_target = '9.2'
1515

1616
s.source = { :git => "https://github.com/itinance/react-native-fs", :tag => "v#{s.version}" }

RNFS.xcodeproj/project.pbxproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@
261261
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
262262
GCC_WARN_UNUSED_FUNCTION = YES;
263263
GCC_WARN_UNUSED_VARIABLE = YES;
264-
IPHONEOS_DEPLOYMENT_TARGET = 7.0;
264+
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
265265
MTL_ENABLE_DEBUG_INFO = YES;
266266
ONLY_ACTIVE_ARCH = YES;
267267
SDKROOT = iphoneos;
@@ -297,7 +297,7 @@
297297
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
298298
GCC_WARN_UNUSED_FUNCTION = YES;
299299
GCC_WARN_UNUSED_VARIABLE = YES;
300-
IPHONEOS_DEPLOYMENT_TARGET = 7.0;
300+
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
301301
MTL_ENABLE_DEBUG_INFO = NO;
302302
SDKROOT = iphoneos;
303303
VALIDATE_PRODUCT = YES;

RNFSManager.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,12 @@
77
//
88

99
#import <React/RCTBridgeModule.h>
10+
#import <React/RCTEventEmitter.h>
1011
#import <React/RCTLog.h>
1112

12-
typedef void (^CompletionHandler)();
13+
typedef void (^CompletionHandler)(void);
1314

14-
@interface RNFSManager : NSObject <RCTBridgeModule>
15+
@interface RNFSManager : RCTEventEmitter <RCTBridgeModule>
1516

1617
+(void)setCompletionHandlerForIdentifier: (NSString *)identifier completionHandler: (CompletionHandler)completionHandler;
1718

RNFSManager.m

Lines changed: 29 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,6 @@ @implementation RNFSManager
3232

3333
static NSMutableDictionary *completionHandlers;
3434

35-
@synthesize bridge = _bridge;
36-
3735
RCT_EXPORT_MODULE();
3836

3937
- (dispatch_queue_t)methodQueue
@@ -157,8 +155,15 @@ + (BOOL)requiresMainQueueSetup
157155
[fH writeData:data];
158156

159157
return resolve(nil);
160-
} @catch (NSException *e) {
161-
return [self reject:reject withError:e];
158+
} @catch (NSException *exception) {
159+
NSMutableDictionary * info = [NSMutableDictionary dictionary];
160+
[info setValue:exception.name forKey:@"ExceptionName"];
161+
[info setValue:exception.reason forKey:@"ExceptionReason"];
162+
[info setValue:exception.callStackReturnAddresses forKey:@"ExceptionCallStackReturnAddresses"];
163+
[info setValue:exception.callStackSymbols forKey:@"ExceptionCallStackSymbols"];
164+
[info setValue:exception.userInfo forKey:@"ExceptionUserInfo"];
165+
NSError *err = [NSError errorWithDomain:@"RNFS" code:0 userInfo:info];
166+
return [self reject:reject withError:err];
162167
}
163168
}
164169

@@ -452,6 +457,11 @@ + (BOOL)requiresMainQueueSetup
452457
resolve(nil);
453458
}
454459

460+
- (NSArray<NSString *> *)supportedEvents
461+
{
462+
return @[@"UploadBegin",@"UploadProgress",@"DownloadBegin",@"DownloadProgress",@"DownloadResumable"];
463+
}
464+
455465
RCT_EXPORT_METHOD(downloadFile:(NSDictionary *)options
456466
resolver:(RCTPromiseResolveBlock)resolve
457467
rejecter:(RCTPromiseRejectBlock)reject)
@@ -505,22 +515,24 @@ + (BOOL)requiresMainQueueSetup
505515
};
506516

507517
params.beginCallback = ^(NSNumber* statusCode, NSNumber* contentLength, NSDictionary* headers) {
508-
[self.bridge.eventDispatcher sendAppEventWithName:[NSString stringWithFormat:@"DownloadBegin-%@", jobId]
509-
body:@{@"jobId": jobId,
510-
@"statusCode": statusCode,
511-
@"contentLength": contentLength,
512-
@"headers": headers ?: [NSNull null]}];
518+
if (self.bridge != nil)
519+
[self sendEventWithName:@"DownloadBegin" body:@{@"jobId": jobId,
520+
@"statusCode": statusCode,
521+
@"contentLength": contentLength,
522+
@"headers": headers ?: [NSNull null]}];
513523
};
514524

515525
params.progressCallback = ^(NSNumber* contentLength, NSNumber* bytesWritten) {
516-
[self.bridge.eventDispatcher sendAppEventWithName:[NSString stringWithFormat:@"DownloadProgress-%@", jobId]
526+
if (self.bridge != nil)
527+
[self sendEventWithName:@"DownloadProgress"
517528
body:@{@"jobId": jobId,
518529
@"contentLength": contentLength,
519530
@"bytesWritten": bytesWritten}];
520531
};
521532

522533
params.resumableCallback = ^() {
523-
[self.bridge.eventDispatcher sendAppEventWithName:[NSString stringWithFormat:@"DownloadResumable-%@", jobId] body:nil];
534+
if (self.bridge != nil)
535+
[self sendEventWithName:@"DownloadResumable" body:nil];
524536
};
525537

526538
if (!self.downloaders) self.downloaders = [[NSMutableDictionary alloc] init];
@@ -619,12 +631,14 @@ + (BOOL)requiresMainQueueSetup
619631
};
620632

621633
params.beginCallback = ^() {
622-
[self.bridge.eventDispatcher sendAppEventWithName:[NSString stringWithFormat:@"UploadBegin-%@", jobId]
634+
if (self.bridge != nil)
635+
[self sendEventWithName:@"UploadBegin"
623636
body:@{@"jobId": jobId}];
624637
};
625638

626639
params.progressCallback = ^(NSNumber* totalBytesExpectedToSend, NSNumber* totalBytesSent) {
627-
[self.bridge.eventDispatcher sendAppEventWithName:[NSString stringWithFormat:@"UploadProgress-%@", jobId]
640+
if (self.bridge != nil)
641+
[self sendEventWithName:@"UploadProgress"
628642
body:@{@"jobId": jobId,
629643
@"totalBytesExpectedToSend": totalBytesExpectedToSend,
630644
@"totalBytesSent": totalBytesSent}];
@@ -813,7 +827,8 @@ + (BOOL)requiresMainQueueSetup
813827
rejecter: (RCTPromiseRejectBlock) reject)
814828
{
815829
NSURL* url = [NSURL URLWithString:imageUri];
816-
__block NSURL* videoURL = [NSURL URLWithString:destination];
830+
//unused?
831+
//__block NSURL* videoURL = [NSURL URLWithString:destination];
817832
__block NSError *error = nil;
818833

819834
PHFetchResult *phAssetFetchResult = [PHAsset fetchAssetsWithALAssetURLs:@[url] options:nil];

Uploader.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ - (void)uploadFiles:(RNFSUploadParams*)params
106106
NSURLSession *session = [NSURLSession sessionWithConfiguration:sessionConfiguration delegate:(id)self delegateQueue:[NSOperationQueue mainQueue]];
107107
_task = [session dataTaskWithRequest:req completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
108108
NSString * str = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
109-
return _params.completeCallback(str, response);
109+
return self->_params.completeCallback(str, response);
110110
}];
111111
[_task resume];
112112
_params.beginCallback();

android/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ android {
1919
buildToolsVersion safeExtGet('buildToolsVersion', '26.0.3')
2020

2121
defaultConfig {
22-
minSdkVersion safeExtGet('minSdkVersion', 16)
22+
minSdkVersion safeExtGet('minSdkVersion', 19)
2323
targetSdkVersion safeExtGet('targetSdkVersion', 26)
2424
versionCode 1
2525
versionName "1.0"

android/src/main/java/com/rnfs/Downloader.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,10 @@
11
package com.rnfs;
22

3-
import java.io.File;
43
import java.io.FileOutputStream;
5-
import java.io.FileInputStream;
64
import java.io.BufferedInputStream;
75
import java.io.InputStream;
86
import java.io.OutputStream;
9-
import java.io.IOException;
107
import java.net.URL;
11-
import java.net.URLConnection;
128
import java.net.HttpURLConnection;
139
import java.util.*;
1410
import java.util.concurrent.atomic.AtomicBoolean;
@@ -90,7 +86,7 @@ private void download(DownloadParams param, DownloadResult res) throws Exception
9086
if(statusCode >= 200 && statusCode < 300) {
9187
Map<String, List<String>> headers = connection.getHeaderFields();
9288

93-
Map<String, String> headersFlat = new HashMap<String, String>();
89+
Map<String, String> headersFlat = new HashMap<>();
9490

9591
for (Map.Entry<String, List<String>> entry : headers.entrySet()) {
9692
String headerKey = entry.getKey();

android/src/main/java/com/rnfs/RNFSManager.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
import android.util.Base64;
1212
import android.util.SparseArray;
1313
import android.media.MediaScannerConnection;
14-
import android.net.Uri;
1514

1615
import com.facebook.react.bridge.Arguments;
1716
import com.facebook.react.bridge.Promise;
@@ -57,8 +56,8 @@ public class RNFSManager extends ReactContextBaseJavaModule {
5756
private static final String RNFSFileTypeRegular = "RNFSFileTypeRegular";
5857
private static final String RNFSFileTypeDirectory = "RNFSFileTypeDirectory";
5958

60-
private SparseArray<Downloader> downloaders = new SparseArray<Downloader>();
61-
private SparseArray<Uploader> uploaders = new SparseArray<Uploader>();
59+
private SparseArray<Downloader> downloaders = new SparseArray<>();
60+
private SparseArray<Uploader> uploaders = new SparseArray<>();
6261

6362
private ReactApplicationContext reactContext;
6463

@@ -69,7 +68,7 @@ public RNFSManager(ReactApplicationContext reactContext) {
6968

7069
@Override
7170
public String getName() {
72-
return this.MODULE_NAME;
71+
return MODULE_NAME;
7372
}
7473

7574
private Uri getFileUri(String filepath, boolean isDirectoryAllowed) throws IORejectionException {
@@ -94,6 +93,7 @@ private String getOriginalFilepath(String filepath, boolean isDirectoryAllowed)
9493
if (cursor.moveToFirst()) {
9594
originalFilepath = cursor.getString(cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA));
9695
}
96+
cursor.close();
9797
} catch (IllegalArgumentException ignored) {
9898
}
9999
}
@@ -288,7 +288,7 @@ public void readFileRes(String filename, Promise promise) {
288288
byte[] buffer = new byte[stream.available()];
289289
stream.read(buffer);
290290
String base64Content = Base64.encodeToString(buffer, Base64.NO_WRAP);
291-
promise.resolve(base64Content);;
291+
promise.resolve(base64Content);
292292
} catch (Exception ex) {
293293
ex.printStackTrace();
294294
reject(promise, filename, ex);
@@ -476,7 +476,7 @@ public void readDirAssets(String directory, Promise promise) {
476476
}
477477
} catch (IOException ex) {
478478
//.. ah.. is a directory or a compressed file?
479-
isDirectory = ex.getMessage().indexOf("compressed") == -1;
479+
isDirectory = !ex.getMessage().contains("compressed");
480480
}
481481
fileMap.putInt("size", length);
482482
fileMap.putInt("type", isDirectory ? 1 : 0); // if 0, probably a folder..
@@ -744,7 +744,7 @@ public void onDownloadBegin(int statusCode, long contentLength, Map<String, Stri
744744
data.putDouble("contentLength", (double)contentLength);
745745
data.putMap("headers", headersMap);
746746

747-
sendEvent(getReactApplicationContext(), "DownloadBegin-" + jobId, data);
747+
sendEvent(getReactApplicationContext(), "DownloadBegin", data);
748748
}
749749
};
750750

@@ -756,7 +756,7 @@ public void onDownloadProgress(long contentLength, long bytesWritten) {
756756
data.putDouble("contentLength", (double)contentLength);
757757
data.putDouble("bytesWritten", (double)bytesWritten);
758758

759-
sendEvent(getReactApplicationContext(), "DownloadProgress-" + jobId, data);
759+
sendEvent(getReactApplicationContext(), "DownloadProgress", data);
760760
}
761761
};
762762

@@ -823,7 +823,7 @@ public void onUploadBegin() {
823823

824824
data.putInt("jobId", jobId);
825825

826-
sendEvent(getReactApplicationContext(), "UploadBegin-" + jobId, data);
826+
sendEvent(getReactApplicationContext(), "UploadBegin", data);
827827
}
828828
};
829829

@@ -835,7 +835,7 @@ public void onUploadProgress(int totalBytesExpectedToSend,int totalBytesSent) {
835835
data.putInt("totalBytesExpectedToSend", totalBytesExpectedToSend);
836836
data.putInt("totalBytesSent", totalBytesSent);
837837

838-
sendEvent(getReactApplicationContext(), "UploadProgress-" + jobId, data);
838+
sendEvent(getReactApplicationContext(), "UploadProgress", data);
839839
}
840840
};
841841

0 commit comments

Comments
 (0)