This commit is contained in:
Elliot Hesp 2017-05-31 16:36:28 +01:00
commit 35aeef460f
27 changed files with 138 additions and 187 deletions

View File

@ -1,8 +1,6 @@
#ifndef RNFirebase_h
#define RNFirebase_h
#import <UIKit/UIKit.h>
#import <React/RCTEventDispatcher.h>
#import <React/RCTEventEmitter.h>
#import <React/RCTBridgeModule.h>

View File

@ -1,36 +1,18 @@
#import "RNFirebase.h"
#import "RNFirebaseEvents.h"
static dispatch_once_t onceToken;
@implementation RNFirebase
RCT_EXPORT_MODULE(RNFirebase);
- (void)dealloc {
NSLog(@"Dealloc called on RNFirebase: %@", self);
[[NSNotificationCenter defaultCenter] removeObserver:self];
}
- (id)init {
self = [super init];
if (self != nil) {
NSLog(@"Setting up RNFirebase instance");
[RNFirebase initializeRNFirebase];
}
return self;
}
+ (void)initializeRNFirebase {
#if __has_include(<FirebaseMessaging/FirebaseMessaging.h>)
dispatch_once(&onceToken, ^{
[[NSNotificationCenter defaultCenter] postNotificationName:kRNFirebaseInitialized object:nil];
});
#endif
}
- (NSArray<NSString *> *)supportedEvents {
return @[INITIALIZED_EVENT];
return @[];
}
@end

View File

@ -7,5 +7,4 @@ RCT_EXPORT_METHOD(log:(NSString *)message) {
}
RCT_EXPORT_METHOD(nativeSDKMissing) {}
@end

View File

@ -1,4 +1,3 @@
#import "RNFirebase.h"
#import "RNFirebaseAnalytics.h"
#if __has_include(<FirebaseAnalytics/FIRAnalytics.h>)
@ -35,7 +34,5 @@ RCT_EXPORT_METHOD(setSessionTimeoutDuration:(nonnull NSNumber *) milliseconds) {
#else
@implementation RNFirebaseAnalytics
RCT_EXPORT_MODULE();
RCT_EXPORT_METHOD(nativeSDKMissing) {}
@end
#endif

View File

@ -1,11 +1,11 @@
#ifndef RNFirebaseAuth_h
#define RNFirebaseAuth_h
#import <React/RCTEventEmitter.h>
#import <React/RCTBridgeModule.h>
#if __has_include(<FirebaseAuth/FIRAuth.h>)
#import "Firebase.h"
#import <React/RCTEventEmitter.h>
@interface RNFirebaseAuth : RCTEventEmitter <RCTBridgeModule> {
FIRAuthStateDidChangeListenerHandle authListenerHandle;
@ -15,7 +15,7 @@
@end
#else
@interface RNFirebaseAuth : RCTEventEmitter <RCTBridgeModule> {
@interface RNFirebaseAuth : NSObject <RCTBridgeModule> {
}
@end
#endif

View File

@ -729,7 +729,5 @@ RCT_EXPORT_METHOD(fetchProvidersForEmail:(NSString *)email resolver:(RCTPromiseR
#else
@implementation RNFirebaseAuth
RCT_EXPORT_MODULE();
RCT_EXPORT_METHOD(nativeSDKMissing) {}
@end
#endif

View File

@ -23,7 +23,5 @@ RCT_EXPORT_METHOD(report:(NSString *) message) {
#else
@implementation RNFirebaseCrash
RCT_EXPORT_MODULE();
RCT_EXPORT_METHOD(nativeSDKMissing) {}
@end
#endif

View File

@ -1,20 +1,19 @@
#ifndef RNFirebaseDatabase_h
#define RNFirebaseDatabase_h
#import <React/RCTEventEmitter.h>
#import <React/RCTBridgeModule.h>
#if __has_include(<FirebaseDatabase/FIRDatabase.h>)
#import "Firebase.h"
#import <React/RCTEventEmitter.h>
@interface RNFirebaseDatabase : RCTEventEmitter <RCTBridgeModule> {}
@interface RNFirebaseDatabase : RCTEventEmitter<RCTBridgeModule> {}
@property NSMutableDictionary *dbReferences;
@property NSMutableDictionary *transactions;
@property dispatch_queue_t transactionQueue;
@end
#else
@interface RNFirebaseDatabase : RCTEventEmitter <RCTBridgeModule> {}
@interface RNFirebaseDatabase : NSObject<RCTBridgeModule> {}
@end
#endif

View File

@ -1,7 +1,6 @@
#import "RNFirebase.h"
#import "RNFirebaseDatabase.h"
#import "RNFirebaseEvents.h"
#import "Firebase.h"
#if __has_include(<FirebaseDatabase/FIRDatabase.h>)
@ -512,7 +511,5 @@ RCT_EXPORT_METHOD(goOnline) {
#else
@implementation RNFirebaseDatabase
RCT_EXPORT_MODULE();
RCT_EXPORT_METHOD(nativeSDKMissing) {}
@end
#endif

View File

@ -3,20 +3,9 @@
#import <Foundation/Foundation.h>
#define SYSTEM_VERSION_EQUAL_TO(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedSame)
#define SYSTEM_VERSION_GREATER_THAN(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedDescending)
#define SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedAscending)
#define SYSTEM_VERSION_LESS_THAN(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedAscending)
#define SYSTEM_VERSION_LESS_THAN_OR_EQUAL_TO(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedDescending)
#define RNFIREBASE_QUEUE_NAME "com.invertase.firebase.WorkerQueue"
static NSString *const kRNFirebaseInitialized = @"RNFirebaseInitializedEvent";
static NSString *const INITIALIZED_EVENT = @"RNFirebaseInitialized";
static NSString *const AUTH_CHANGED_EVENT = @"onAuthStateChanged";
static NSString *const AUTH_ERROR_EVENT = @"authError";
static NSString *const AUTH_ANONYMOUS_ERROR_EVENT = @"authAnonymousError";
static NSString *const DEBUG_EVENT = @"debug";
// Database
static NSString *const DATABASE_DATA_EVENT = @"database_event";
@ -29,7 +18,6 @@ static NSString *const DATABASE_CHILD_MODIFIED_EVENT = @"child_changed";
static NSString *const DATABASE_CHILD_REMOVED_EVENT = @"child_removed";
static NSString *const DATABASE_CHILD_MOVED_EVENT = @"child_moved";
// Storage
static NSString *const STORAGE_EVENT = @"storage_event";
static NSString *const STORAGE_ERROR = @"storage_error";

View File

@ -1,15 +1,11 @@
#ifndef RNFirebaseMessaging_h
#define RNFirebaseMessaging_h
#import <React/RCTEventEmitter.h>
#import <React/RCTBridgeModule.h>
#if __has_include(<FirebaseMessaging/FirebaseMessaging.h>)
#import "Firebase.h"
#import <FirebaseMessaging/FirebaseMessaging.h>
#import <React/RCTUtils.h>
#import <UIKit/UIKit.h>
#import <React/RCTEventEmitter.h>
@import UserNotifications;
@ -30,7 +26,7 @@ typedef void (^RCTNotificationResponseCallback)();
@end
#else
@interface RNFirebaseMessaging : RCTEventEmitter<RCTBridgeModule>
@interface RNFirebaseMessaging : NSObject<RCTBridgeModule>
@end
#endif

View File

@ -1,14 +1,14 @@
#import "RNFirebaseMessaging.h"
@import UserNotifications;
#if __has_include(<FirebaseMessaging/FirebaseMessaging.h>)
#import "RNFirebaseEvents.h"
#import <FirebaseMessaging/FirebaseMessaging.h>
#import <React/RCTEventDispatcher.h>
#import <React/RCTConvert.h>
#import <React/RCTUtils.h>
@import UserNotifications;
#if __has_include(<FirebaseMessaging/FirebaseMessaging.h>)
#import <FirebaseMessaging/FirebaseMessaging.h>
@implementation RCTConvert (NSCalendarUnit)
RCT_ENUM_CONVERTER(NSCalendarUnit,
@ -420,7 +420,5 @@ RCT_EXPORT_METHOD(finishNotificationResponse: (NSString *)completionHandlerId) {
#else
@implementation RNFirebaseMessaging
RCT_EXPORT_MODULE();
RCT_EXPORT_METHOD(nativeSDKMissing) {}
@end
#endif

View File

@ -49,7 +49,5 @@ RCT_EXPORT_METHOD(incrementCounter:
#else
@implementation RNFirebasePerformance
RCT_EXPORT_MODULE();
RCT_EXPORT_METHOD(nativeSDKMissing) {}
@end
#endif

View File

@ -1,9 +1,8 @@
#import "RNFirebaseRemoteConfig.h"
#import <React/RCTConvert.h>
#if __has_include(<FirebaseRemoteConfig/FirebaseRemoteConfig.h>)
#import "FirebaseRemoteConfig/FirebaseRemoteConfig.h"
#import <React/RCTConvert.h>
NSString *convertFIRRemoteConfigFetchStatusToNSString(FIRRemoteConfigFetchStatus value)
{
@ -52,21 +51,13 @@ NSDictionary *convertFIRRemoteConfigValueToNSDictionary(FIRRemoteConfigValue *va
RCT_EXPORT_MODULE(RNFirebaseRemoteConfig);
- (id)init
{
if (self = [super init]) {
_remoteConfig = [FIRRemoteConfig remoteConfig];
}
return self;
}
RCT_EXPORT_METHOD(enableDeveloperMode) {
FIRRemoteConfigSettings *remoteConfigSettings = [[FIRRemoteConfigSettings alloc] initWithDeveloperModeEnabled:YES];
self.remoteConfig.configSettings = remoteConfigSettings;
[FIRRemoteConfig remoteConfig].configSettings = remoteConfigSettings;
}
RCT_EXPORT_METHOD(fetch:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) {
[self.remoteConfig fetchWithCompletionHandler:^(FIRRemoteConfigFetchStatus status, NSError *__nullable error) {
[[FIRRemoteConfig remoteConfig] fetchWithCompletionHandler:^(FIRRemoteConfigFetchStatus status, NSError *__nullable error) {
if (error) {
RCTLogError(@"\nError: %@", RCTJSErrorFromNSError(error));
reject(convertFIRRemoteConfigFetchStatusToNSString(status), error.localizedDescription, error);
@ -80,7 +71,7 @@ RCT_EXPORT_METHOD(fetchWithExpirationDuration:(nonnull NSNumber *)expirationDura
resolver:(RCTPromiseResolveBlock)resolve
rejecter:(RCTPromiseRejectBlock)reject)
{
[self.remoteConfig fetchWithExpirationDuration:expirationDuration.doubleValue completionHandler:^(FIRRemoteConfigFetchStatus status, NSError *__nullable error) {
[[FIRRemoteConfig remoteConfig] fetchWithExpirationDuration:expirationDuration.doubleValue completionHandler:^(FIRRemoteConfigFetchStatus status, NSError *__nullable error) {
if (error) {
RCTLogError(@"\nError: %@", RCTJSErrorFromNSError(error));
reject(convertFIRRemoteConfigFetchStatusToNSString(status), error.localizedDescription, error);
@ -93,7 +84,7 @@ RCT_EXPORT_METHOD(fetchWithExpirationDuration:(nonnull NSNumber *)expirationDura
RCT_EXPORT_METHOD(activateFetched:(RCTPromiseResolveBlock)resolve
rejecter:(RCTPromiseRejectBlock)reject)
{
BOOL status = [self.remoteConfig activateFetched];
BOOL status = [[FIRRemoteConfig remoteConfig] activateFetched];
resolve(@(status));
}
@ -101,7 +92,7 @@ RCT_EXPORT_METHOD(getValue:(NSString *)key
resolver:(RCTPromiseResolveBlock)resolve
rejecter:(RCTPromiseRejectBlock)reject)
{
FIRRemoteConfigValue *value = [self.remoteConfig configValueForKey:key];
FIRRemoteConfigValue *value = [[FIRRemoteConfig remoteConfig] configValueForKey:key];
resolve(convertFIRRemoteConfigValueToNSDictionary(value));
}
@ -111,7 +102,7 @@ RCT_EXPORT_METHOD(getValues:(NSArray *)keys
{
NSMutableArray *valuesArray = [[NSMutableArray alloc] init];
for (NSString *key in keys) {
FIRRemoteConfigValue *value = [self.remoteConfig configValueForKey:key];
FIRRemoteConfigValue *value = [[FIRRemoteConfig remoteConfig] configValueForKey:key];
[valuesArray addObject:convertFIRRemoteConfigValueToNSDictionary(value)];
}
resolve(valuesArray);
@ -121,7 +112,7 @@ RCT_EXPORT_METHOD(getKeysByPrefix:(NSString *)prefix
resolver:(RCTPromiseResolveBlock)resolve
rejecter:(RCTPromiseRejectBlock)reject)
{
NSSet *keys = [self.remoteConfig keysWithPrefix:prefix];
NSSet *keys = [[FIRRemoteConfig remoteConfig] keysWithPrefix:prefix];
NSMutableArray *keysArray = [[NSMutableArray alloc] init];
for (NSString *key in keys) {
[keysArray addObject:key];
@ -130,18 +121,16 @@ RCT_EXPORT_METHOD(getKeysByPrefix:(NSString *)prefix
}
RCT_EXPORT_METHOD(setDefaults:(NSDictionary *)defaults) {
[self.remoteConfig setDefaults:defaults];
[[FIRRemoteConfig remoteConfig] setDefaults:defaults];
}
RCT_EXPORT_METHOD(setDefaultsFromResource:(NSString *)fileName) {
[self.remoteConfig setDefaultsFromPlistFileName:fileName];
[[FIRRemoteConfig remoteConfig] setDefaultsFromPlistFileName:fileName];
}
@end
#else
@implementation RNFirebaseRemoteConfig
RCT_EXPORT_MODULE();
RCT_EXPORT_METHOD(nativeSDKMissing) {}
@end
#endif

View File

@ -1,13 +1,20 @@
#ifndef RNFirebaseStorage_h
#define RNFirebaseStorage_h
#import <React/RCTEventEmitter.h>
#import <React/RCTBridgeModule.h>
@interface RNFirebaseStorage : RCTEventEmitter <RCTBridgeModule> {
#if __has_include(<FirebaseStorage/FIRStorage.h>)
#import <React/RCTEventEmitter.h>
@interface RNFirebaseStorage : RCTEventEmitter<RCTBridgeModule> {
}
@end
#else
@interface RNFirebaseStorage : NSObject<RCTBridgeModule>
@end
#endif
#endif

View File

@ -450,7 +450,5 @@ RCT_EXPORT_METHOD(putFile:(NSString *) path localPath:(NSString *)localPath meta
#else
@implementation RNFirebaseStorage
RCT_EXPORT_MODULE();
RCT_EXPORT_METHOD(nativeSDKMissing) {}
@end
#endif

View File

@ -10,14 +10,13 @@ import NativeExpress from './NativeExpress';
import { Base } from './../base';
const FirebaseAdMob = NativeModules.RNFirebaseAdMob;
const FirebaseAdMobEvt = new NativeEventEmitter(FirebaseAdMob);
const FirebaseAdMobEvt = FirebaseAdMob && new NativeEventEmitter(FirebaseAdMob);
export default class Admob extends Base {
constructor() {
super();
console.log('>>', FirebaseAdMob)
if (FirebaseAdMob.nativeSDKMissing) {
if (!FirebaseAdMob) {
return nativeSDKMissing('admob');
}

View File

@ -23,7 +23,7 @@ const ReservedEventNames = [
export default class Analytics {
constructor() {
if (FirebaseAnalytics.nativeSDKMissing) {
if (!FirebaseAnalytics) {
return nativeSDKMissing('analytics');
}
}

View File

@ -13,7 +13,7 @@ import TwitterAuthProvider from './providers/Twitter';
import GithubAuthProvider from './providers/Github';
const FirebaseAuth = NativeModules.RNFirebaseAuth;
const FirebaseAuthEvt = new NativeEventEmitter(FirebaseAuth);
const FirebaseAuthEvt = FirebaseAuth && new NativeEventEmitter(FirebaseAuth);
export default class Auth extends Base {
_user: User | null;
@ -22,7 +22,7 @@ export default class Auth extends Base {
constructor(firebase: Object, options: Object = {}) {
super(firebase, options);
if (FirebaseAuth.nativeSDKMissing) {
if (!FirebaseAuth) {
return nativeSDKMissing('auth');
}

View File

@ -16,7 +16,7 @@ type RemoteConfigOptions = {}
export default class RemoteConfig extends Base {
constructor(firebase: Object, options: RemoteConfigOptions = {}) {
super(firebase, options);
if (FirebaseRemoteConfig.nativeSDKMissing) {
if (!FirebaseRemoteConfig) {
return nativeSDKMissing('remote config');
}

View File

@ -6,7 +6,7 @@ const FirebaseCrash = NativeModules.RNFirebaseCrash;
export default class Crash {
constructor() {
if (FirebaseCrash.nativeSDKMissing) {
if (!FirebaseCrash) {
return nativeSDKMissing('crash');
}
}

View File

@ -11,7 +11,7 @@ import TransactionHandler from './transaction';
import { promisify, nativeSDKMissing } from './../../utils';
const FirebaseDatabase = NativeModules.RNFirebaseDatabase;
const FirebaseDatabaseEvt = new NativeEventEmitter(FirebaseDatabase);
const FirebaseDatabaseEvt = FirebaseDatabase && new NativeEventEmitter(FirebaseDatabase);
/**
* @class Database
@ -19,7 +19,7 @@ const FirebaseDatabaseEvt = new NativeEventEmitter(FirebaseDatabase);
export default class Database extends Base {
constructor(firebase: Object, options: Object = {}) {
super(firebase, options);
if (FirebaseDatabase.nativeSDKMissing) {
if (!FirebaseDatabase) {
return nativeSDKMissing('database');
}
@ -211,7 +211,7 @@ export default class Database extends Base {
}
export const statics = {
ServerValue: {
ServerValue: FirebaseDatabase ? {
TIMESTAMP: FirebaseDatabase.serverValueTimestamp || { '.sv': 'timestamp' },
},
} : {},
};

View File

@ -4,7 +4,7 @@ import { nativeSDKMissing } from './../../utils';
import RemoteMessage from './RemoteMessage';
const FirebaseMessaging = NativeModules.RNFirebaseMessaging;
const FirebaseMessagingEvt = new NativeEventEmitter(FirebaseMessaging);
const FirebaseMessagingEvt = FirebaseMessaging && new NativeEventEmitter(FirebaseMessaging);
const EVENT_TYPE = {
RefreshToken: 'messaging_token_refreshed',
@ -77,7 +77,7 @@ function finish(data) {
export default class Messaging extends Base {
constructor(firebase, options = {}) {
super(firebase, options);
if (FirebaseMessaging.nativeSDKMissing) {
if (!FirebaseMessaging) {
return nativeSDKMissing('messaging');
}

View File

@ -7,7 +7,7 @@ const FirebasePerformance = NativeModules.RNFirebasePerformance;
export default class PerformanceMonitoring {
constructor() {
if (FirebasePerformance.nativeSDKMissing) {
if (!FirebasePerformance) {
return nativeSDKMissing('perf');
}
}

View File

@ -6,7 +6,7 @@ import { nativeSDKMissing } from './../../utils';
import StorageRef from './reference';
const FirebaseStorage = NativeModules.RNFirebaseStorage;
const FirebaseStorageEvt = new NativeEventEmitter(FirebaseStorage);
const FirebaseStorageEvt = FirebaseStorage && new NativeEventEmitter(FirebaseStorage);
type StorageOptionsType = {
storageBucket?: ?string,
@ -20,7 +20,7 @@ export default class Storage extends Base {
*/
constructor(firebase: Object, options: StorageOptionsType = {}) {
super(firebase, options);
if (FirebaseStorage.nativeSDKMissing) {
if (!FirebaseStorage) {
return nativeSDKMissing('storage');
}
@ -148,7 +148,7 @@ export const statics = {
CANCELLED: 'cancelled',
ERROR: 'error',
},
Native: {
Native: FirebaseStorage ? {
MAIN_BUNDLE_PATH: FirebaseStorage.MAIN_BUNDLE_PATH,
CACHES_DIRECTORY_PATH: FirebaseStorage.CACHES_DIRECTORY_PATH,
DOCUMENT_DIRECTORY_PATH: FirebaseStorage.DOCUMENT_DIRECTORY_PATH,
@ -158,6 +158,5 @@ export const statics = {
LIBRARY_DIRECTORY_PATH: FirebaseStorage.LIBRARY_DIRECTORY_PATH,
FILETYPE_REGULAR: FirebaseStorage.FILETYPE_REGULAR,
FILETYPE_DIRECTORY: FirebaseStorage.FILETYPE_DIRECTORY,
},
} : {},
};

View File

@ -1,7 +1,10 @@
import React, { Component } from 'react';
import { Provider } from 'react-redux';
import { Banner } from './../firebase/modules/admob';
import { View } from 'react-native';
import fb from './firebase';
const firebase = fb.native;
const Banner = firebase.admob.Banner;
const NativeExpress = firebase.admob.NativeExpress;
import CoreContainer from './containers/CoreContainer';
import setupStore from './store/setup';
@ -52,6 +55,14 @@ function bootstrap() {
return null;
}
return (
<View>
<NativeExpress size="320x250" onAdLoaded={(props) => {
console.log('ad', props)
}} />
</View>
);
// return <Banner style={{ width: 100, height: 100, backgroundColor: 'pink'}} />;
return (
<Provider store={this.state.store}>