Skip to content

Commit

Permalink
Patch react-native-firebase v6 on iOS to fix exception with database …
Browse files Browse the repository at this point in the history
…module

This is similar to the patch done for react-native-firebase v5
See invertase/react-native-firebase#2734
  • Loading branch information
jeanregisser committed Apr 29, 2020
1 parent d0033ec commit 35aefe2
Showing 1 changed file with 104 additions and 0 deletions.
104 changes: 104 additions & 0 deletions patches/@react-native-firebase/database+6.7.1.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
patch-package
--- a/node_modules/@react-native-firebase/database/ios/RNFBDatabase/RNFBDatabaseCommon.h
+++ b/node_modules/@react-native-firebase/database/ios/RNFBDatabase/RNFBDatabaseCommon.h
@@ -21,6 +21,8 @@

@interface RNFBDatabaseCommon : NSObject

++ (dispatch_queue_t)sharedMethodQueue;
+
+ (FIRDatabase *)getDatabaseForApp
:(FIRApp *)firebaseApp
dbURL:(NSString *)dbURL;
--- a/node_modules/@react-native-firebase/database/ios/RNFBDatabase/RNFBDatabaseCommon.m
+++ b/node_modules/@react-native-firebase/database/ios/RNFBDatabase/RNFBDatabaseCommon.m
@@ -33,6 +33,16 @@ NSString *const DATABASE_PERSISTENCE_CACHE_SIZE = @"firebase_database_persistenc
configSettingsLock = [NSMutableDictionary dictionary];
}

++ (dispatch_queue_t)sharedMethodQueue
+{
+ static dispatch_queue_t sharedQueue;
+ static dispatch_once_t onceToken;
+ dispatch_once(&onceToken, ^{
+ sharedQueue = dispatch_queue_create("io.invertase.firebase.database", DISPATCH_QUEUE_SERIAL);
+ });
+ return sharedQueue;
+}
+
+ (FIRDatabase *)getDatabaseForApp:(FIRApp *)firebaseApp dbURL:(NSString *)dbURL {

FIRDatabase *firDatabase;
--- a/node_modules/@react-native-firebase/database/ios/RNFBDatabase/RNFBDatabaseModule.m
+++ b/node_modules/@react-native-firebase/database/ios/RNFBDatabase/RNFBDatabaseModule.m
@@ -29,7 +29,7 @@
RCT_EXPORT_MODULE();

- (dispatch_queue_t)methodQueue {
- return dispatch_queue_create("io.invertase.firebase.database", DISPATCH_QUEUE_SERIAL);
+ return RNFBDatabaseCommon.sharedMethodQueue;
}

#pragma mark -
--- a/node_modules/@react-native-firebase/database/ios/RNFBDatabase/RNFBDatabaseOnDisconnectModule.m
+++ b/node_modules/@react-native-firebase/database/ios/RNFBDatabase/RNFBDatabaseOnDisconnectModule.m
@@ -29,7 +29,7 @@
RCT_EXPORT_MODULE();

- (dispatch_queue_t)methodQueue {
- return dispatch_queue_create("io.invertase.firebase.database", DISPATCH_QUEUE_SERIAL);
+ return RNFBDatabaseCommon.sharedMethodQueue;
}

#pragma mark -
--- a/node_modules/@react-native-firebase/database/ios/RNFBDatabase/RNFBDatabaseQueryModule.m
+++ b/node_modules/@react-native-firebase/database/ios/RNFBDatabase/RNFBDatabaseQueryModule.m
@@ -32,7 +32,7 @@ static NSString *const RNFB_DATABASE_SYNC = @"database_sync_event";
RCT_EXPORT_MODULE();

- (dispatch_queue_t)methodQueue {
- return dispatch_queue_create("io.invertase.firebase.database", DISPATCH_QUEUE_SERIAL);
+ return RNFBDatabaseCommon.sharedMethodQueue;
}

- (id)init {
--- a/node_modules/@react-native-firebase/database/ios/RNFBDatabase/RNFBDatabaseReferenceModule.m
+++ b/node_modules/@react-native-firebase/database/ios/RNFBDatabase/RNFBDatabaseReferenceModule.m
@@ -29,7 +29,7 @@
RCT_EXPORT_MODULE();

- (dispatch_queue_t)methodQueue {
- return dispatch_queue_create("io.invertase.firebase.database", DISPATCH_QUEUE_SERIAL);
+ return RNFBDatabaseCommon.sharedMethodQueue;
}

#pragma mark -
--- a/node_modules/@react-native-firebase/database/ios/RNFBDatabase/RNFBDatabaseTransactionModule.m
+++ b/node_modules/@react-native-firebase/database/ios/RNFBDatabase/RNFBDatabaseTransactionModule.m
@@ -33,7 +33,7 @@ static NSString *const RNFB_DATABASE_TRANSACTION_EVENT = @"database_transaction_
RCT_EXPORT_MODULE();

- (dispatch_queue_t)methodQueue {
- return dispatch_queue_create("io.invertase.firebase.database", DISPATCH_QUEUE_SERIAL);
+ return RNFBDatabaseCommon.sharedMethodQueue;
}

- (id)init {
@@ -57,6 +57,8 @@ RCT_EXPORT_METHOD(transactionStart:
: (nonnull NSNumber *) transactionId
: (BOOL) applyLocally
) {
+ FIRDatabase *firDatabase = [RNFBDatabaseCommon getDatabaseForApp:firebaseApp dbURL:dbURL];
+ FIRDatabaseReference *firDatabaseReference = [RNFBDatabaseCommon getReferenceForDatabase:firDatabase path:path];
dispatch_async(_transactionQueue, ^{
NSMutableDictionary *transactionState = [NSMutableDictionary new];
dispatch_semaphore_t sema = dispatch_semaphore_create(0);
@@ -64,8 +66,6 @@ RCT_EXPORT_METHOD(transactionStart:
#pragma ide diagnostic ignored "err_typecheck_convert_incompatible"
transactionState[@"semaphore"] = sema;
#pragma clang diagnostic pop
- FIRDatabase *firDatabase = [RNFBDatabaseCommon getDatabaseForApp:firebaseApp dbURL:dbURL];
- FIRDatabaseReference *firDatabaseReference = [RNFBDatabaseCommon getReferenceForDatabase:firDatabase path:path];

id runTransactionBlock = ^FIRTransactionResult *(FIRMutableData *currentData) {
dispatch_barrier_async(_transactionQueue, ^{

0 comments on commit 35aefe2

Please sign in to comment.