diff --git a/lib/modules/analytics/index.js b/lib/modules/analytics/index.js index e19285ee..7f7261b9 100644 --- a/lib/modules/analytics/index.js +++ b/lib/modules/analytics/index.js @@ -1,6 +1,6 @@ // @flow import { NativeModules } from 'react-native'; -import { Base } from './../base'; +import { nativeSDKMissing } from './../../utils'; const FirebaseAnalytics = NativeModules.RNFirebaseAnalytics; const AlphaNumericUnderscore = /^[a-zA-Z0-9_]+$/; @@ -21,7 +21,13 @@ const ReservedEventNames = [ 'user_engagement', ]; -export default class Analytics extends Base { +export default class Analytics { + constructor() { + if (FirebaseAnalytics.nativeSDKMissing) { + return nativeSDKMissing('analytics'); + } + } + /** * Logs an app event. * @param {string} name diff --git a/lib/modules/auth/index.js b/lib/modules/auth/index.js index c6db2f6d..289e2d20 100644 --- a/lib/modules/auth/index.js +++ b/lib/modules/auth/index.js @@ -3,6 +3,7 @@ import { NativeModules, NativeEventEmitter } from 'react-native'; import User from './user'; import { Base } from './../base'; +import { nativeSDKMissing } from './../../utils'; // providers import EmailAuthProvider from './providers/Email'; @@ -15,12 +16,16 @@ const FirebaseAuth = NativeModules.RNFirebaseAuth; const FirebaseAuthEvt = new NativeEventEmitter(FirebaseAuth); export default class Auth extends Base { - _user: User|null; + _user: User | null; _authResult: AuthResultType | null; authenticated: boolean; constructor(firebase: Object, options: Object = {}) { super(firebase, options); + if (FirebaseAuth.nativeSDKMissing) { + return nativeSDKMissing('auth'); + } + this._user = null; this._authResult = null; this.authenticated = false; @@ -168,7 +173,7 @@ export default class Auth extends Base { * Get the currently signed in user * @return {Promise} */ - get currentUser(): User|null { + get currentUser(): User | null { return this._user; } diff --git a/lib/modules/config/index.js b/lib/modules/config/index.js index f2a8b36b..2007c78a 100644 --- a/lib/modules/config/index.js +++ b/lib/modules/config/index.js @@ -4,6 +4,7 @@ import { NativeModules } from 'react-native'; import { Base } from './../base'; +import { nativeSDKMissing } from './../../utils'; const FirebaseRemoteConfig = NativeModules.RNFirebaseRemoteConfig; @@ -15,6 +16,10 @@ type RemoteConfigOptions = {} export default class RemoteConfig extends Base { constructor(firebase: Object, options: RemoteConfigOptions = {}) { super(firebase, options); + if (FirebaseRemoteConfig.nativeSDKMissing) { + return nativeSDKMissing('remote config'); + } + this.namespace = 'firebase:config'; this.developerModeEnabled = false; } diff --git a/lib/modules/crash/index.js b/lib/modules/crash/index.js index cc6c2503..abbf6073 100644 --- a/lib/modules/crash/index.js +++ b/lib/modules/crash/index.js @@ -1,10 +1,16 @@ // @flow import { NativeModules } from 'react-native'; -import { Base } from './../base'; +import { nativeSDKMissing } from './../../utils'; const FirebaseCrash = NativeModules.RNFirebaseCrash; -export default class Crash extends Base { +export default class Crash { + constructor() { + if (FirebaseCrash.nativeSDKMissing) { + return nativeSDKMissing('crash'); + } + } + /** * Logs a message that will appear in a subsequent crash report. * @param {string} message diff --git a/lib/modules/database/index.js b/lib/modules/database/index.js index 775774ff..f804ecf1 100644 --- a/lib/modules/database/index.js +++ b/lib/modules/database/index.js @@ -8,7 +8,7 @@ import { Base } from './../base'; import Snapshot from './snapshot'; import Reference from './reference'; import TransactionHandler from './transaction'; -import { promisify } from './../../utils'; +import { promisify, nativeSDKMissing } from './../../utils'; const FirebaseDatabase = NativeModules.RNFirebaseDatabase; const FirebaseDatabaseEvt = new NativeEventEmitter(FirebaseDatabase); @@ -19,6 +19,10 @@ const FirebaseDatabaseEvt = new NativeEventEmitter(FirebaseDatabase); export default class Database extends Base { constructor(firebase: Object, options: Object = {}) { super(firebase, options); + if (FirebaseDatabase.nativeSDKMissing) { + return nativeSDKMissing('database'); + } + this.references = {}; this.serverTimeOffset = 0; this.persistenceEnabled = false; @@ -83,12 +87,10 @@ export default class Database extends Base { * @param origCB * @returns {*} */ - off( - refId: number, - // $FlowFixMe - listeners: Array, - remainingListenersCount: number - ) { + off(refId: number, + // $FlowFixMe + listeners: Array, + remainingListenersCount: number) { this.log.debug('off() : ', refId, listeners); // Delete the reference if there are no more listeners diff --git a/lib/modules/messaging/index.js b/lib/modules/messaging/index.js index 79a261c0..c3c11220 100644 --- a/lib/modules/messaging/index.js +++ b/lib/modules/messaging/index.js @@ -1,5 +1,6 @@ import { NativeModules, DeviceEventEmitter, Platform } from 'react-native'; import { Base } from './../base'; +import { nativeSDKMissing } from './../../utils'; import RemoteMessage from './RemoteMessage'; const FirebaseMessaging = NativeModules.RNFirebaseMessaging; @@ -75,6 +76,10 @@ function finish(data) { export default class Messaging extends Base { constructor(firebase, options = {}) { super(firebase, options); + if (FirebaseMessaging.nativeSDKMissing) { + return nativeSDKMissing('messaging'); + } + this.namespace = 'firebase:messaging'; } diff --git a/lib/modules/perf/index.js b/lib/modules/perf/index.js index 48f0ea31..6db70c63 100644 --- a/lib/modules/perf/index.js +++ b/lib/modules/perf/index.js @@ -1,11 +1,16 @@ // @flow import { NativeModules } from 'react-native'; -import { Base } from './../base'; +import { nativeSDKMissing } from './../../utils'; import Trace from './Trace'; const FirebasePerformance = NativeModules.RNFirebasePerformance; -export default class PerformanceMonitoring extends Base { +export default class PerformanceMonitoring { + constructor() { + if (FirebasePerformance.nativeSDKMissing) { + return nativeSDKMissing('perf'); + } + } /** * Globally enable or disable performance monitoring diff --git a/lib/modules/storage/index.js b/lib/modules/storage/index.js index 5a54dc36..87a931d4 100644 --- a/lib/modules/storage/index.js +++ b/lib/modules/storage/index.js @@ -2,6 +2,7 @@ import { NativeModules, NativeEventEmitter } from 'react-native'; import { Base } from './../base'; +import { nativeSDKMissing } from './../../utils'; import StorageRef from './reference'; const FirebaseStorage = NativeModules.RNFirebaseStorage; @@ -19,6 +20,10 @@ export default class Storage extends Base { */ constructor(firebase: Object, options: StorageOptionsType = {}) { super(firebase, options); + if (FirebaseStorage.nativeSDKMissing) { + return nativeSDKMissing('storage'); + } + this.subscriptions = {}; this.successListener = FirebaseStorageEvt.addListener( diff --git a/lib/utils/index.js b/lib/utils/index.js index bb957a69..dff4b02a 100644 --- a/lib/utils/index.js +++ b/lib/utils/index.js @@ -1,3 +1,5 @@ +import { Platform } from 'react-native'; + /** * @flow */ @@ -27,6 +29,15 @@ const _handler = (resolve, reject, errorPrefix, err, resp) => { }); }; + +export function nativeSDKMissing(sdkName) { + if (Platform.OS === 'ios') { + console.warn(`Firebase ${sdkName} native sdk has not been included in your podfile - ${sdkName} methods have been disabled.`); + } else { + console.warn(`Firebase ${sdkName} native sdk has not been included in your build.gradle file - ${sdkName} methods have been disabled.`); + } +} + export function toWebSDKErrorCode(code: any, prefix: string): string { if (!code || typeof code !== 'string') return ''; return code.toLowerCase().replace('error_', prefix).replace(/_/g, '-'); @@ -40,11 +51,9 @@ export function toWebSDKErrorCode(code: any, prefix: string): string { * @param joiner * @returns {*} */ -export function deepGet( - object: Object, - path: string, - joiner?: string = '/' -): any { +export function deepGet(object: Object, + path: string, + joiner?: string = '/'): any { const keys = path.split(joiner); let i = 0; @@ -68,11 +77,9 @@ export function deepGet( * @param joiner * @returns {*} */ -export function deepExists( - object: Object, - path: string, - joiner?: string = '/' -): boolean { +export function deepExists(object: Object, + path: string, + joiner?: string = '/'): boolean { const keys = path.split(joiner); let i = 0; @@ -161,11 +168,9 @@ export function noop(): void { * @param NativeModule * @param errorPrefix */ -export function promisify( - fn: Function | string, - NativeModule: Object, - errorPrefix?: string -): (args: any) => Promise<> { +export function promisify(fn: Function | string, + NativeModule: Object, + errorPrefix?: string): (args: any) => Promise<> { return (...args) => { return new Promise((resolve, reject) => { const _fn = typeof fn === 'function' ? fn : NativeModule[fn]; @@ -184,12 +189,10 @@ export function promisify( * @param callback * @private */ -function _delayChunk( - collection: Array<*>, - chunkSize: number, - operation: Function, - callback: Function -): void { +function _delayChunk(collection: Array<*>, + chunkSize: number, + operation: Function, + callback: Function): void { const length = collection.length; const iterations = Math.ceil(length / chunkSize); @@ -217,12 +220,10 @@ function _delayChunk( * @param iterator * @param cb */ -export function each( - array: Array<*>, - chunkSize: number | Function, - iterator: Function, - cb?: Function -): void { +export function each(array: Array<*>, + chunkSize: number | Function, + iterator: Function, + cb?: Function): void { if (typeof chunkSize === 'function') { cb = iterator; iterator = chunkSize; @@ -252,12 +253,10 @@ export function typeOf(value: any): string { * @param cb * @returns {*} */ -export function map( - array: Array<*>, - chunkSize: number | Function, - iterator: Function, - cb?: Function -): void { +export function map(array: Array<*>, + chunkSize: number | Function, + iterator: Function, + cb?: Function): void { if (typeof chunkSize === 'function') { cb = iterator; iterator = chunkSize;