[utils] move play services check

This commit is contained in:
Salakar 2017-10-07 03:09:05 +01:00
parent 0eb38c4593
commit e74b760288
3 changed files with 12 additions and 12 deletions

View File

@ -1,7 +1,7 @@
import { NativeModules } from 'react-native';
import INTERNALS from './internals';
import { isObject } from './utils';
import { isObject, isAndroid } from './utils';
import AdMob, { statics as AdMobStatics } from './modules/admob';
import Auth, { statics as AuthStatics } from './modules/auth';
@ -152,6 +152,11 @@ export default class FirebaseApp {
const getInstance = () => {
const _name = `_${InstanceClass._NAMESPACE}`;
if (isAndroid && InstanceClass._NAMESPACE !== Utils._NAMESPACE && !INTERNALS.FLAGS.checkedPlayServices) {
INTERNALS.FLAGS.checkedPlayServices = true;
this.utils().checkPlayServicesAvailability();
}
if (!this._namespaces[_name]) {
this._namespaces[_name] = new InstanceClass(this);
}

View File

@ -27,7 +27,6 @@ class FirebaseCore {
constructor() {
this._nativeEmitters = {};
this._nativeSubscriptions = {};
this._checkedPlayServices = false;
if (!FirebaseCoreModule) {
throw (new Error(INTERNALS.STRINGS.ERROR_MISSING_CORE));
@ -188,14 +187,6 @@ class FirebaseCore {
_appNamespaceOrStatics(statics = {}, InstanceClass): Function {
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) => {
let _app = app;

View File

@ -19,13 +19,17 @@ export default class RNFirebaseUtils {
*/
checkPlayServicesAvailability() {
if (isIOS) return null;
const code = this.playServicesAvailability.code;
if (!this.playServicesAvailability.isAvailable) {
if (INTERNALS.OPTIONS.promptOnMissingPlayServices && this.playServicesAvailability.isUserResolvableError) {
this.promptForPlayServices();
} else {
const error = INTERNALS.STRINGS.ERROR_PLAY_SERVICES(this.playServicesAvailability.code);
const error = INTERNALS.STRINGS.ERROR_PLAY_SERVICES(code);
if (INTERNALS.OPTIONS.errorOnMissingPlayServices) {
throw new Error(error);
if (code === 2) console.warn(error); // only warn if it exists but may need an update
else throw new Error(error);
} else {
console.warn(error);
}