From e74b760288f08ee65698e8f0a2de975fedd1417b Mon Sep 17 00:00:00 2001 From: Salakar Date: Sat, 7 Oct 2017 03:09:05 +0100 Subject: [PATCH] [utils] move play services check --- lib/firebase-app.js | 7 ++++++- lib/firebase.js | 9 --------- lib/modules/utils/index.js | 8 ++++++-- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/lib/firebase-app.js b/lib/firebase-app.js index 1a4742e9..d93985b9 100644 --- a/lib/firebase-app.js +++ b/lib/firebase-app.js @@ -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); } diff --git a/lib/firebase.js b/lib/firebase.js index 2ce9317c..b841a92b 100644 --- a/lib/firebase.js +++ b/lib/firebase.js @@ -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; diff --git a/lib/modules/utils/index.js b/lib/modules/utils/index.js index 333cabd1..57a9cce7 100644 --- a/lib/modules/utils/index.js +++ b/lib/modules/utils/index.js @@ -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); }