Skip to content

Commit 47024cc

Browse files
author
Riccardo Cipolleschi
committed
feat: connect iOS to JS and test TM
1 parent bbcd0f1 commit 47024cc

File tree

4 files changed

+17
-13
lines changed

4 files changed

+17
-13
lines changed

index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
// Use of this source code is governed by a MIT-style license that can be
33
// found in the LICENSE file.
44

5-
import {AppState, DeviceEventEmitter, NativeModules, Platform,} from 'react-native';
5+
import {AppState, DeviceEventEmitter, Platform,} from 'react-native';
6+
import ReactNativeBlobUtil from './codegenSpecs/NativeBlobUtils';
67

78
//import StatefulPromise from './class/StatefulPromise.js'
89
import fs from './fs';
@@ -33,7 +34,6 @@ const {
3334

3435
const Blob = polyfill.Blob;
3536
const emitter = DeviceEventEmitter;
36-
const ReactNativeBlobUtil = NativeModules.ReactNativeBlobUtil;
3737
const wrap = URIUtil.wrap;
3838

3939
// when app resumes, check if there's any expired network task and trigger

ios/ReactNativeBlobUtil/ReactNativeBlobUtil.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
@property (nonatomic) NSString * filePathPrefix;
3939
@property (retain) UIDocumentInteractionController * documentController;
4040

41-
+ (RCTBridge *)getRCTBridge;
41+
+ (RCTEventDispatcher *)getRCTEventDispatcher;
4242

4343
@end
4444

ios/ReactNativeBlobUtil/ReactNativeBlobUtil.mm

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
#import "ReactNativeBlobUtilSpec.h"
1616
#endif
1717

18-
1918
__strong RCTEventDispatcher * eventDispatcherRef;
2019
dispatch_queue_t commonTaskQueue;
2120
dispatch_queue_t fsQueue;
@@ -67,11 +66,11 @@ - (id) init {
6766
if(![[NSFileManager defaultManager] fileExistsAtPath: [ReactNativeBlobUtilFS getTempPath] isDirectory:&isDir]) {
6867
[[NSFileManager defaultManager] createDirectoryAtPath:[ReactNativeBlobUtilFS getTempPath] withIntermediateDirectories:YES attributes:nil error:NULL];
6968
}
70-
eventDispatcherRef = nil;
7169
dispatch_async(dispatch_get_main_queue(), ^{
7270
eventDispatcherRef = [ReactNativeBlobUtil getRCTEventDispatcher];
7371
[ReactNativeBlobUtilNetwork emitExpiredTasks: eventDispatcherRef];
7472
});
73+
7574
return self;
7675
}
7776

@@ -412,7 +411,6 @@ - (void)writeFileArray:(NSString *)path
412411
RCT_EXPORT_METHOD(unlink:(NSString *)path callback:(RCTResponseSenderBlock) callback)
413412
{
414413
NSError * error = nil;
415-
NSString * tmpPath = nil;
416414
[[NSFileManager defaultManager] removeItemAtPath:path error:&error];
417415
if(error == nil || [[NSFileManager defaultManager] fileExistsAtPath:path] == NO)
418416
callback(@[[NSNull null]]);
@@ -424,7 +422,6 @@ - (void)writeFileArray:(NSString *)path
424422
RCT_EXPORT_METHOD(removeSession:(NSArray *)paths callback:(RCTResponseSenderBlock) callback)
425423
{
426424
NSError * error = nil;
427-
NSString * tmpPath = nil;
428425

429426
for(NSString * path in paths) {
430427
[[NSFileManager defaultManager] removeItemAtPath:path error:&error];
@@ -487,7 +484,7 @@ - (void)ls:(NSString *)path
487484
callback(@[[NSString stringWithFormat:@"failed to stat path `%@` because it does not exist or it is not a folder", path]]);
488485
return ;
489486
}
490-
result = [ReactNativeBlobUtilFS stat:path error:&error];
487+
result = [ReactNativeBlobUtilFS stat:path error:&error].mutableCopy;
491488

492489
if(error == nil)
493490
callback(@[[NSNull null], result]);
@@ -639,11 +636,13 @@ - (void)readFile:(NSString *)path
639636
reject(code, err, nil);
640637
return;
641638
}
642-
if(encoding == @"ascii") {
639+
if([encoding isEqualToString:@"ascii"]) {
643640
resolve((NSMutableArray *)content);
644641
}
645-
else {
646-
resolve((NSString *)content);
642+
if([encoding isEqualToString:@"base64"]) {
643+
resolve([content base64EncodedStringWithOptions:0]);
644+
} else {
645+
resolve([[NSString alloc] initWithData:content encoding:NSUTF8StringEncoding]);
647646
}
648647
}];
649648
}
@@ -869,6 +868,11 @@ - (UIViewController *) documentInteractionControllerViewControllerForPreview: (U
869868

870869

871870
#if RCT_NEW_ARCH_ENABLED
871+
- (std::shared_ptr<facebook::react::TurboModule>)getTurboModule:
872+
(const facebook::react::ObjCTurboModule::InitParams &)params
873+
{
874+
return std::make_shared<facebook::react::NativeBlobUtilsSpecJSI>(params);
875+
}
872876
#endif
873877

874878
@end

ios/ReactNativeBlobUtilFS.mm

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,11 @@ - (id)initWithEventDispatcherRef:(RCTEventDispatcher *)eventDispatcherRef {
6565
}
6666

6767
// static member getter
68-
+ (NSArray *) getFileStreams {
68+
+ (NSDictionary *) getFileStreams {
6969

7070
if(fileStreams == nil)
7171
fileStreams = [[NSMutableDictionary alloc] init];
72-
return fileStreams.allValues;
72+
return fileStreams;
7373
}
7474

7575
+(void) setFileStream:(ReactNativeBlobUtilFS *) instance withId:(NSString *) uuid {

0 commit comments

Comments
 (0)