more work on multiple apps support
This commit is contained in:
parent
ec22e510bc
commit
f97db8eba1
@ -14,6 +14,7 @@ import com.facebook.react.bridge.WritableArray;
|
|||||||
import com.google.android.gms.tasks.OnCompleteListener;
|
import com.google.android.gms.tasks.OnCompleteListener;
|
||||||
import com.facebook.react.bridge.ReactApplicationContext;
|
import com.facebook.react.bridge.ReactApplicationContext;
|
||||||
import com.facebook.react.bridge.ReactContextBaseJavaModule;
|
import com.facebook.react.bridge.ReactContextBaseJavaModule;
|
||||||
|
import com.google.firebase.FirebaseApp;
|
||||||
import com.google.firebase.remoteconfig.FirebaseRemoteConfig;
|
import com.google.firebase.remoteconfig.FirebaseRemoteConfig;
|
||||||
import com.google.firebase.remoteconfig.FirebaseRemoteConfigValue;
|
import com.google.firebase.remoteconfig.FirebaseRemoteConfigValue;
|
||||||
import com.google.firebase.remoteconfig.FirebaseRemoteConfigSettings;
|
import com.google.firebase.remoteconfig.FirebaseRemoteConfigSettings;
|
||||||
@ -47,10 +48,12 @@ class RNFirebaseRemoteConfig extends ReactContextBaseJavaModule {
|
|||||||
return TAG;
|
return TAG;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ReactMethod
|
@ReactMethod public void enableDeveloperMode(String appName) {
|
||||||
public void enableDeveloperMode(String appName) {
|
FirebaseApp firebaseApp = FirebaseApp.getInstance(appName);
|
||||||
|
|
||||||
FirebaseRemoteConfigSettings.Builder settings = new FirebaseRemoteConfigSettings.Builder();
|
FirebaseRemoteConfigSettings.Builder settings = new FirebaseRemoteConfigSettings.Builder();
|
||||||
settings.setDeveloperModeEnabled(true);
|
settings.setDeveloperModeEnabled(true);
|
||||||
|
|
||||||
FirebaseRemoteConfig.getInstance().setConfigSettings(settings.build());
|
FirebaseRemoteConfig.getInstance().setConfigSettings(settings.build());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
|
|
||||||
#import <React/RCTBridgeModule.h>
|
#import <React/RCTBridgeModule.h>
|
||||||
|
|
||||||
@interface RNFirebaseRemoteConfig : NSObject <RCTBridgeModule>
|
@interface RNFirebaseConfig : NSObject <RCTBridgeModule>
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
@ -1,12 +1,12 @@
|
|||||||
#import "RNFirebaseRemoteConfig.h"
|
#import "RNFirebaseConfig.h"
|
||||||
|
|
||||||
#if __has_include(<FirebaseRemoteConfig/FirebaseRemoteConfig.h>)
|
#if __has_include(<FirebaseRemoteConfig/FirebaseRemoteConfig.h>)
|
||||||
|
|
||||||
#import "FirebaseRemoteConfig/FirebaseRemoteConfig.h"
|
#import "FirebaseRemoteConfig/FirebaseRemoteConfig.h"
|
||||||
#import <React/RCTConvert.h>
|
#import <React/RCTConvert.h>
|
||||||
|
|
||||||
NSString *convertFIRRemoteConfigFetchStatusToNSString(FIRRemoteConfigFetchStatus value)
|
NSString *convertFIRRemoteConfigFetchStatusToNSString(FIRRemoteConfigFetchStatus value) {
|
||||||
{
|
switch (value) {
|
||||||
switch(value){
|
|
||||||
case FIRRemoteConfigFetchStatusNoFetchYet:
|
case FIRRemoteConfigFetchStatusNoFetchYet:
|
||||||
return @"config/no_fetch_yet";
|
return @"config/no_fetch_yet";
|
||||||
case FIRRemoteConfigFetchStatusFailure:
|
case FIRRemoteConfigFetchStatusFailure:
|
||||||
@ -18,9 +18,8 @@ NSString *convertFIRRemoteConfigFetchStatusToNSString(FIRRemoteConfigFetchStatus
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
NSString *convertFIRRemoteConfigSourceToNSString(FIRRemoteConfigSource value)
|
NSString *convertFIRRemoteConfigSourceToNSString(FIRRemoteConfigSource value) {
|
||||||
{
|
switch (value) {
|
||||||
switch(value) {
|
|
||||||
case FIRRemoteConfigSourceDefault:
|
case FIRRemoteConfigSourceDefault:
|
||||||
return @"default";
|
return @"default";
|
||||||
case FIRRemoteConfigSourceRemote:
|
case FIRRemoteConfigSourceRemote:
|
||||||
@ -30,33 +29,29 @@ NSString *convertFIRRemoteConfigSourceToNSString(FIRRemoteConfigSource value)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
NSDictionary *convertFIRRemoteConfigValueToNSDictionary(FIRRemoteConfigValue *value)
|
NSDictionary *convertFIRRemoteConfigValueToNSDictionary(FIRRemoteConfigValue *value) {
|
||||||
{
|
return @{@"stringValue": value.stringValue ?: [NSNull null], @"numberValue": value.numberValue ?: [NSNull null], @"dataValue": value.dataValue ? [value.dataValue base64EncodedStringWithOptions:0] : [NSNull null], @"boolValue": @(value.boolValue), @"source": convertFIRRemoteConfigSourceToNSString(value.source)};
|
||||||
return @{
|
|
||||||
@"stringValue" : value.stringValue ?: [NSNull null],
|
|
||||||
@"numberValue" : value.numberValue ?: [NSNull null],
|
|
||||||
@"dataValue" : value.dataValue ? [value.dataValue base64EncodedStringWithOptions:0] : [NSNull null],
|
|
||||||
@"boolValue" : @(value.boolValue),
|
|
||||||
@"source" : convertFIRRemoteConfigSourceToNSString(value.source)
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@interface RNFirebaseRemoteConfig ()
|
@interface RNFirebaseConfig ()
|
||||||
|
|
||||||
@property (nonatomic, readwrite, weak) FIRRemoteConfig *remoteConfig;
|
@property(nonatomic, readwrite, weak) FIRRemoteConfig *remoteConfig;
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
@implementation RNFirebaseRemoteConfig
|
@implementation RNFirebaseConfig
|
||||||
|
|
||||||
RCT_EXPORT_MODULE(RNFirebaseRemoteConfig);
|
RCT_EXPORT_MODULE(RNFirebaseConfig);
|
||||||
|
|
||||||
RCT_EXPORT_METHOD(enableDeveloperMode) {
|
RCT_EXPORT_METHOD(enableDeveloperMode) {
|
||||||
FIRRemoteConfigSettings *remoteConfigSettings = [[FIRRemoteConfigSettings alloc] initWithDeveloperModeEnabled:YES];
|
FIRRemoteConfigSettings *remoteConfigSettings = [[FIRRemoteConfigSettings alloc] initWithDeveloperModeEnabled:YES];
|
||||||
[FIRRemoteConfig remoteConfig].configSettings = remoteConfigSettings;
|
[FIRRemoteConfig remoteConfig].configSettings = remoteConfigSettings;
|
||||||
}
|
}
|
||||||
|
|
||||||
RCT_EXPORT_METHOD(fetch:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) {
|
RCT_EXPORT_METHOD(fetch:
|
||||||
|
(RCTPromiseResolveBlock) resolve
|
||||||
|
rejecter:
|
||||||
|
(RCTPromiseRejectBlock) reject) {
|
||||||
[[FIRRemoteConfig remoteConfig] fetchWithCompletionHandler:^(FIRRemoteConfigFetchStatus status, NSError *__nullable error) {
|
[[FIRRemoteConfig remoteConfig] fetchWithCompletionHandler:^(FIRRemoteConfigFetchStatus status, NSError *__nullable error) {
|
||||||
if (error) {
|
if (error) {
|
||||||
RCTLogError(@"\nError: %@", RCTJSErrorFromNSError(error));
|
RCTLogError(@"\nError: %@", RCTJSErrorFromNSError(error));
|
||||||
@ -67,10 +62,11 @@ RCT_EXPORT_METHOD(fetch:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseReje
|
|||||||
}];
|
}];
|
||||||
}
|
}
|
||||||
|
|
||||||
RCT_EXPORT_METHOD(fetchWithExpirationDuration:(nonnull NSNumber *)expirationDuration
|
RCT_EXPORT_METHOD(fetchWithExpirationDuration:
|
||||||
resolver:(RCTPromiseResolveBlock)resolve
|
(nonnull
|
||||||
rejecter:(RCTPromiseRejectBlock)reject)
|
NSNumber *)expirationDuration
|
||||||
{
|
resolver:(RCTPromiseResolveBlock)resolve
|
||||||
|
rejecter:(RCTPromiseRejectBlock)reject) {
|
||||||
[[FIRRemoteConfig remoteConfig] fetchWithExpirationDuration:expirationDuration.doubleValue completionHandler:^(FIRRemoteConfigFetchStatus status, NSError *__nullable error) {
|
[[FIRRemoteConfig remoteConfig] fetchWithExpirationDuration:expirationDuration.doubleValue completionHandler:^(FIRRemoteConfigFetchStatus status, NSError *__nullable error) {
|
||||||
if (error) {
|
if (error) {
|
||||||
RCTLogError(@"\nError: %@", RCTJSErrorFromNSError(error));
|
RCTLogError(@"\nError: %@", RCTJSErrorFromNSError(error));
|
||||||
@ -81,37 +77,44 @@ RCT_EXPORT_METHOD(fetchWithExpirationDuration:(nonnull NSNumber *)expirationDura
|
|||||||
}];
|
}];
|
||||||
}
|
}
|
||||||
|
|
||||||
RCT_EXPORT_METHOD(activateFetched:(RCTPromiseResolveBlock)resolve
|
RCT_EXPORT_METHOD(activateFetched:
|
||||||
rejecter:(RCTPromiseRejectBlock)reject)
|
(RCTPromiseResolveBlock) resolve
|
||||||
{
|
rejecter:
|
||||||
|
(RCTPromiseRejectBlock) reject) {
|
||||||
BOOL status = [[FIRRemoteConfig remoteConfig] activateFetched];
|
BOOL status = [[FIRRemoteConfig remoteConfig] activateFetched];
|
||||||
resolve(@(status));
|
resolve(@(status));
|
||||||
}
|
}
|
||||||
|
|
||||||
RCT_EXPORT_METHOD(getValue:(NSString *)key
|
RCT_EXPORT_METHOD(getValue:
|
||||||
resolver:(RCTPromiseResolveBlock)resolve
|
(NSString *) key
|
||||||
rejecter:(RCTPromiseRejectBlock)reject)
|
resolver:
|
||||||
{
|
(RCTPromiseResolveBlock) resolve
|
||||||
|
rejecter:
|
||||||
|
(RCTPromiseRejectBlock) reject) {
|
||||||
FIRRemoteConfigValue *value = [[FIRRemoteConfig remoteConfig] configValueForKey:key];
|
FIRRemoteConfigValue *value = [[FIRRemoteConfig remoteConfig] configValueForKey:key];
|
||||||
resolve(convertFIRRemoteConfigValueToNSDictionary(value));
|
resolve(convertFIRRemoteConfigValueToNSDictionary(value));
|
||||||
}
|
}
|
||||||
|
|
||||||
RCT_EXPORT_METHOD(getValues:(NSArray *)keys
|
RCT_EXPORT_METHOD(getValues:
|
||||||
resolver:(RCTPromiseResolveBlock)resolve
|
(NSArray *) keys
|
||||||
rejecter:(RCTPromiseRejectBlock)reject)
|
resolver:
|
||||||
{
|
(RCTPromiseResolveBlock) resolve
|
||||||
|
rejecter:
|
||||||
|
(RCTPromiseRejectBlock) reject) {
|
||||||
NSMutableArray *valuesArray = [[NSMutableArray alloc] init];
|
NSMutableArray *valuesArray = [[NSMutableArray alloc] init];
|
||||||
for (NSString *key in keys) {
|
for (NSString *key in keys) {
|
||||||
FIRRemoteConfigValue *value = [[FIRRemoteConfig remoteConfig] configValueForKey:key];
|
FIRRemoteConfigValue *value = [[FIRRemoteConfig remoteConfig] configValueForKey:key];
|
||||||
[valuesArray addObject:convertFIRRemoteConfigValueToNSDictionary(value)];
|
[valuesArray addObject:convertFIRRemoteConfigValueToNSDictionary(value)];
|
||||||
}
|
}
|
||||||
resolve(valuesArray);
|
resolve(valuesArray);
|
||||||
}
|
}
|
||||||
|
|
||||||
RCT_EXPORT_METHOD(getKeysByPrefix:(NSString *)prefix
|
RCT_EXPORT_METHOD(getKeysByPrefix:
|
||||||
resolver:(RCTPromiseResolveBlock)resolve
|
(NSString *) prefix
|
||||||
rejecter:(RCTPromiseRejectBlock)reject)
|
resolver:
|
||||||
{
|
(RCTPromiseResolveBlock) resolve
|
||||||
|
rejecter:
|
||||||
|
(RCTPromiseRejectBlock) reject) {
|
||||||
NSSet *keys = [[FIRRemoteConfig remoteConfig] keysWithPrefix:prefix];
|
NSSet *keys = [[FIRRemoteConfig remoteConfig] keysWithPrefix:prefix];
|
||||||
NSMutableArray *keysArray = [[NSMutableArray alloc] init];
|
NSMutableArray *keysArray = [[NSMutableArray alloc] init];
|
||||||
for (NSString *key in keys) {
|
for (NSString *key in keys) {
|
||||||
@ -120,17 +123,19 @@ RCT_EXPORT_METHOD(getKeysByPrefix:(NSString *)prefix
|
|||||||
resolve(keysArray);
|
resolve(keysArray);
|
||||||
}
|
}
|
||||||
|
|
||||||
RCT_EXPORT_METHOD(setDefaults:(NSDictionary *)defaults) {
|
RCT_EXPORT_METHOD(setDefaults:
|
||||||
|
(NSDictionary *) defaults) {
|
||||||
[[FIRRemoteConfig remoteConfig] setDefaults:defaults];
|
[[FIRRemoteConfig remoteConfig] setDefaults:defaults];
|
||||||
}
|
}
|
||||||
|
|
||||||
RCT_EXPORT_METHOD(setDefaultsFromResource:(NSString *)fileName) {
|
RCT_EXPORT_METHOD(setDefaultsFromResource:
|
||||||
|
(NSString *) fileName) {
|
||||||
[[FIRRemoteConfig remoteConfig] setDefaultsFromPlistFileName:fileName];
|
[[FIRRemoteConfig remoteConfig] setDefaultsFromPlistFileName:fileName];
|
||||||
}
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
#else
|
#else
|
||||||
@implementation RNFirebaseRemoteConfig
|
@implementation RNFirebaseConfig
|
||||||
@end
|
@end
|
||||||
#endif
|
#endif
|
@ -3,12 +3,16 @@ import { NativeModules } from 'react-native';
|
|||||||
import INTERNALS from './internals';
|
import INTERNALS from './internals';
|
||||||
|
|
||||||
// modules
|
// modules
|
||||||
|
// todo
|
||||||
import Crash from './modules/crash';
|
import Crash from './modules/crash';
|
||||||
import Performance from './modules/perf';
|
import Performance from './modules/perf';
|
||||||
import RemoteConfig from './modules/config';
|
|
||||||
import Analytics from './modules/analytics';
|
import Analytics from './modules/analytics';
|
||||||
import Auth, { statics as AuthStatics } from './modules/auth';
|
|
||||||
import AdMob, { statics as AdMobStatics } from './modules/admob';
|
import AdMob, { statics as AdMobStatics } from './modules/admob';
|
||||||
|
// ----
|
||||||
|
|
||||||
|
|
||||||
|
import Auth, { statics as AuthStatics } from './modules/auth';
|
||||||
|
import RemoteConfig from './modules/config';
|
||||||
import Storage, { statics as StorageStatics } from './modules/storage';
|
import Storage, { statics as StorageStatics } from './modules/storage';
|
||||||
import Database, { statics as DatabaseStatics } from './modules/database';
|
import Database, { statics as DatabaseStatics } from './modules/database';
|
||||||
import Messaging, { statics as MessagingStatics } from './modules/messaging';
|
import Messaging, { statics as MessagingStatics } from './modules/messaging';
|
||||||
@ -56,6 +60,10 @@ export default class FirebaseApp {
|
|||||||
return this._staticsOrModuleInstance('auth', AuthStatics, Auth);
|
return this._staticsOrModuleInstance('auth', AuthStatics, Auth);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
get config() {
|
||||||
|
return this._staticsOrModuleInstance('config', {}, RemoteConfig);
|
||||||
|
}
|
||||||
|
|
||||||
get database() {
|
get database() {
|
||||||
return this._staticsOrModuleInstance('database', DatabaseStatics, Database);
|
return this._staticsOrModuleInstance('database', DatabaseStatics, Database);
|
||||||
}
|
}
|
||||||
|
@ -12,6 +12,7 @@ import FirebaseApp from './firebase-app';
|
|||||||
|
|
||||||
// module imports
|
// module imports
|
||||||
import Auth, { statics as AuthStatics } from './modules/auth';
|
import Auth, { statics as AuthStatics } from './modules/auth';
|
||||||
|
import RemoteConfig from './modules/config';
|
||||||
import Storage, { statics as StorageStatics } from './modules/storage';
|
import Storage, { statics as StorageStatics } from './modules/storage';
|
||||||
import Database, { statics as DatabaseStatics } from './modules/database';
|
import Database, { statics as DatabaseStatics } from './modules/database';
|
||||||
import Messaging, { statics as MessagingStatics } from './modules/messaging';
|
import Messaging, { statics as MessagingStatics } from './modules/messaging';
|
||||||
@ -110,6 +111,11 @@ class FirebaseCore {
|
|||||||
return this._appNamespaceOrStatics('auth', AuthStatics, Auth);
|
return this._appNamespaceOrStatics('auth', AuthStatics, Auth);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
get config() {
|
||||||
|
return this._appNamespaceOrStatics('config', {}, RemoteConfig);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
get database() {
|
get database() {
|
||||||
return this._appNamespaceOrStatics('database', DatabaseStatics, Database);
|
return this._appNamespaceOrStatics('database', DatabaseStatics, Database);
|
||||||
}
|
}
|
||||||
|
@ -8,6 +8,13 @@ import INTERNALS from './../internals';
|
|||||||
|
|
||||||
const logs = {};
|
const logs = {};
|
||||||
|
|
||||||
|
// Firebase Native SDKs that support multiple app instances
|
||||||
|
const MULTI_APP_MODULES = [
|
||||||
|
'auth',
|
||||||
|
'database',
|
||||||
|
'storage',
|
||||||
|
];
|
||||||
|
|
||||||
export default class ModuleBase {
|
export default class ModuleBase {
|
||||||
constructor(firebaseApp, options, moduleName, withEventEmitter = false) {
|
constructor(firebaseApp, options, moduleName, withEventEmitter = false) {
|
||||||
this._options = Object.assign({}, options);
|
this._options = Object.assign({}, options);
|
||||||
@ -24,7 +31,12 @@ export default class ModuleBase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// used by the modules that extend ModuleBase to access their native module counterpart
|
// used by the modules that extend ModuleBase to access their native module counterpart
|
||||||
this._native = nativeWithApp(this._appName, nativeModule);
|
if (!MULTI_APP_MODULES.includes(moduleName.toLowerCase())) {
|
||||||
|
this._native = nativeModule;
|
||||||
|
} else {
|
||||||
|
this._native = nativeWithApp(this._appName, nativeModule);
|
||||||
|
}
|
||||||
|
|
||||||
if (withEventEmitter) {
|
if (withEventEmitter) {
|
||||||
this._eventEmitter = new NativeEventEmitter(this._native);
|
this._eventEmitter = new NativeEventEmitter(this._native);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user