[utils] run play services check automatically after any module usage - once
This commit is contained in:
parent
08fae27f70
commit
3d360348d5
@ -6,7 +6,7 @@ import { NativeModules, NativeEventEmitter } from 'react-native';
|
|||||||
|
|
||||||
import INTERNALS from './internals';
|
import INTERNALS from './internals';
|
||||||
import FirebaseApp from './firebase-app';
|
import FirebaseApp from './firebase-app';
|
||||||
import { isObject, isString } from './utils';
|
import { isObject, isString, isAndroid } from './utils';
|
||||||
|
|
||||||
// module imports
|
// module imports
|
||||||
import AdMob, { statics as AdMobStatics } from './modules/admob';
|
import AdMob, { statics as AdMobStatics } from './modules/admob';
|
||||||
@ -27,18 +27,13 @@ class FirebaseCore {
|
|||||||
constructor() {
|
constructor() {
|
||||||
this._nativeEmitters = {};
|
this._nativeEmitters = {};
|
||||||
this._nativeSubscriptions = {};
|
this._nativeSubscriptions = {};
|
||||||
|
this._checkedPlayServices = false;
|
||||||
|
|
||||||
if (!FirebaseCoreModule) {
|
if (!FirebaseCoreModule) {
|
||||||
throw (new Error(INTERNALS.STRINGS.ERROR_MISSING_CORE));
|
throw (new Error(INTERNALS.STRINGS.ERROR_MISSING_CORE));
|
||||||
}
|
}
|
||||||
|
|
||||||
for (let i = 0, len = FirebaseCoreModule.apps.length; i < len; i++) {
|
this._initializeNativeApps();
|
||||||
const app = FirebaseCoreModule.apps[i];
|
|
||||||
const options = Object.assign({}, app);
|
|
||||||
delete options.name;
|
|
||||||
INTERNALS.APPS[app.name] = new FirebaseApp(app.name, options);
|
|
||||||
INTERNALS.APPS[app.name]._initializeApp(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
// modules
|
// modules
|
||||||
this.admob = this._appNamespaceOrStatics(AdMobStatics, AdMob);
|
this.admob = this._appNamespaceOrStatics(AdMobStatics, AdMob);
|
||||||
@ -54,6 +49,20 @@ class FirebaseCore {
|
|||||||
this.utils = this._appNamespaceOrStatics(UtilsStatics, Utils);
|
this.utils = this._appNamespaceOrStatics(UtilsStatics, Utils);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Bootstraps all native app instances that were discovered on boot
|
||||||
|
* @private
|
||||||
|
*/
|
||||||
|
_initializeNativeApps() {
|
||||||
|
for (let i = 0, len = FirebaseCoreModule.apps.length; i < len; i++) {
|
||||||
|
const app = FirebaseCoreModule.apps[i];
|
||||||
|
const options = Object.assign({}, app);
|
||||||
|
delete options.name;
|
||||||
|
INTERNALS.APPS[app.name] = new FirebaseApp(app.name, options);
|
||||||
|
INTERNALS.APPS[app.name]._initializeApp(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Web SDK initializeApp
|
* Web SDK initializeApp
|
||||||
*
|
*
|
||||||
@ -171,7 +180,6 @@ class FirebaseCore {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @param namespace
|
|
||||||
* @param statics
|
* @param statics
|
||||||
* @param InstanceClass
|
* @param InstanceClass
|
||||||
* @return {function(FirebaseApp=)}
|
* @return {function(FirebaseApp=)}
|
||||||
@ -179,8 +187,18 @@ class FirebaseCore {
|
|||||||
*/
|
*/
|
||||||
_appNamespaceOrStatics(statics = {}, InstanceClass): Function {
|
_appNamespaceOrStatics(statics = {}, InstanceClass): Function {
|
||||||
const namespace = InstanceClass._NAMESPACE;
|
const namespace = InstanceClass._NAMESPACE;
|
||||||
|
|
||||||
|
// play services checks will run for the first time on any module
|
||||||
|
// usage - except for the utils module - to allow you to configure
|
||||||
|
// play services options
|
||||||
|
if (isAndroid && namespace !== Utils._NAMESPACE && !this._checkedPlayServices) {
|
||||||
|
this._checkedPlayServices = true;
|
||||||
|
this.utils().checkPlayServicesAvailability();
|
||||||
|
}
|
||||||
|
|
||||||
const getNamespace = (app?: FirebaseApp) => {
|
const getNamespace = (app?: FirebaseApp) => {
|
||||||
let _app = app;
|
let _app = app;
|
||||||
|
|
||||||
// throw an error if it's not a valid app instance
|
// throw an error if it's not a valid app instance
|
||||||
if (_app && !(_app instanceof FirebaseApp)) throw new Error(INTERNALS.STRINGS.ERROR_NOT_APP(namespace));
|
if (_app && !(_app instanceof FirebaseApp)) throw new Error(INTERNALS.STRINGS.ERROR_NOT_APP(namespace));
|
||||||
|
|
||||||
@ -193,6 +211,7 @@ class FirebaseCore {
|
|||||||
Object.assign(getNamespace, statics, {
|
Object.assign(getNamespace, statics, {
|
||||||
nativeModuleExists: !!NativeModules[InstanceClass._NATIVE_MODULE],
|
nativeModuleExists: !!NativeModules[InstanceClass._NATIVE_MODULE],
|
||||||
});
|
});
|
||||||
|
|
||||||
return getNamespace;
|
return getNamespace;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user