How to use @react-native-firebase/app - 10 common examples

To help you get started, we’ve selected a few @react-native-firebase/app examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github invertase / react-native-firebase / packages / database / lib / DatabaseSyncTree.js View on Github external
_handleErrorEvent(event) {
    // console.log('SyncTree.ERROR >>>', event);
    const { eventRegistrationKey, registrationCancellationKey } = event.registration;

    const registration = this.getRegistration(registrationCancellationKey);

    if (registration) {
      // build a new js error - we additionally attach
      // the ref as a property for easier debugging
      const error = NativeError.fromEvent(event.error, 'database');

      // forward on to users .on(successCallback, cancellationCallback <-- listener
      SharedEventEmitter.emit(registrationCancellationKey, error);

      // remove the paired event registration - if we received a cancellation
      // event then it's guaranteed that they'll be no further value events
      this.removeRegistration(eventRegistrationKey);
    }
  }
github invertase / react-native-firebase / packages / perf / lib / HttpMetric.js View on Github external
} else {
      // eslint-disable-next-line no-console
      console.warn(
        `Warning: A firebase.perf.HttpMetric (${this._httpMethod}: ${
          this._url
        }) failed to provide a httpResponseCode; this metric will not be visible on the Firebase console.`,
      );
    }

    if (!isNull(this._requestPayloadSize)) {
      metricData.requestPayloadSize = this._requestPayloadSize;
    }
    if (!isNull(this._responsePayloadSize)) {
      metricData.responsePayloadSize = this._responsePayloadSize;
    }
    if (!isNull(this._responseContentType)) {
      metricData.responseContentType = this._responseContentType;
    }

    return this.native.stopHttpMetric(this._id, metricData);
  }
}
github invertase / react-native-firebase / packages / ml-natural-language / lib / index.js View on Github external
// mlkit().X(...);
export default createModuleNamespace({
  statics,
  version,
  namespace,
  nativeModuleName,
  nativeEvents: false,
  hasMultiAppSupport: false,
  hasCustomUrlOrRegionSupport: false,
  ModuleClass: FirebaseMlkitModule,
});

// import mlkit, { firebase } from '@react-native-firebase/mlkit';
// mlkit().X(...);
// firebase.mlkit().X(...);
export const firebase = getFirebaseRoot();
github invertase / react-native-firebase / packages / ml-vision / lib / index.js View on Github external
// mlkit().X(...);
export default createModuleNamespace({
  statics,
  version,
  namespace,
  nativeModuleName,
  nativeEvents: false,
  hasMultiAppSupport: false,
  hasCustomUrlOrRegionSupport: false,
  ModuleClass: FirebaseMlkitModule,
});

// import mlkit, { firebase } from '@react-native-firebase/mlkit';
// mlkit().X(...);
// firebase.mlkit().X(...);
export const firebase = getFirebaseRoot();
github invertase / react-native-firebase / packages / database / lib / DatabaseQuery.js View on Github external
}

    if (!isUndefined(successCallBack) && !isFunction(successCallBack)) {
      throw new Error("firebase.database().ref().once(_, *) 'successCallBack' must be a function.");
    }

    if (
      !isUndefined(failureCallbackOrContext) &&
      (!isObject(failureCallbackOrContext) && !isFunction(failureCallbackOrContext))
    ) {
      throw new Error(
        "firebase.database().ref().once(_, _, *) 'failureCallbackOrContext' must be a function or context.",
      );
    }

    if (!isUndefined(context) && !isObject(context)) {
      throw new Error(
        "firebase.database().ref().once(_, _, _, *) 'context' must be a context object.",
      );
    }

    const modifiers = this._modifiers.toArray();

    return this._database.native
      .once(this.path, modifiers, eventType)
      .then(result => {
        let dataSnapshot;
        let previousChildName;

        // Child based events return a previousChildName
        if (eventType === 'value') {
          dataSnapshot = new DatabaseDataSnapshot(this.ref, result);
github invertase / react-native-firebase / packages / database / lib / DatabaseQuery.js View on Github external
return DatabaseSyncTree.removeListenersForRegistrations(
        DatabaseSyncTree.getRegistrationsByPath(this.path),
      );
    }

    if (!isUndefined(eventType) && !eventTypes.includes(eventType)) {
      throw new Error(
        `firebase.database().ref().off(*) 'eventType' must be one of ${eventTypes.join(', ')}.`,
      );
    }

    if (!isUndefined(callback) && !isFunction(callback)) {
      throw new Error("firebase.database().ref().off(_, *) 'callback' must be a function.");
    }

    if (!isUndefined(context) && !isObject(context)) {
      throw new Error("firebase.database().ref().off(_, _, *) 'context' must be an object.");
    }

    // Firebase Docs:
    //     Note that if on() was called
    //     multiple times with the same eventType and callback, the callback will be called
    //     multiple times for each event, and off() must be called multiple times to
    //     remove the callback.

    // Remove only a single registration
    if (eventType && callback) {
      const registration = DatabaseSyncTree.getOneByPathEventListener(
        this.path,
        eventType,
        callback,
      );
github invertase / react-native-firebase / packages / firestore / lib / utils / serialize.js View on Github external
if (isNumber(value)) {
    return getTypeMapInt('number', value);
  }

  if (isString(value)) {
    if (value === '') {
      return getTypeMapInt('stringEmpty');
    }
    return getTypeMapInt('string', value);
  }

  if (isArray(value)) {
    return getTypeMapInt('array', buildNativeArray(value));
  }

  if (isObject(value)) {
    if (value instanceof FirestoreDocumentReference) {
      return getTypeMapInt('reference', value.path);
    }

    if (value instanceof FirestoreGeoPoint) {
      return getTypeMapInt('geopoint', [value.latitude, value.longitude]);
    }

    // Handle Date objects are Timestamps as per web sdk
    if (isDate(value)) {
      const timestamp = FirestoreTimestamp.fromDate(value);
      return getTypeMapInt('timestamp', [timestamp.seconds, timestamp.nanoseconds]);
    }

    if (value instanceof FirestoreTimestamp) {
      return getTypeMapInt('timestamp', [value.seconds, value.nanoseconds]);
github invertase / react-native-firebase / packages / firestore / lib / FirestoreQuery.js View on Github external
_handleQueryCursor(cursor, docOrField, fields) {
    const modifiers = this._modifiers._copy();

    if (isUndefined(docOrField)) {
      throw new Error(
        `firebase.firestore().collection().${cursor}(*) Expected a DocumentSnapshot or list of field values but got undefined.`,
      );
    }

    // Handles cases where the first arg is a DocumentSnapshot
    if (docOrField instanceof FirestoreDocumentSnapshot) {
      if (fields.length > 0) {
        throw new Error(
          `firebase.firestore().collection().${cursor}(*) Too many arguments provided. Expected DocumentSnapshot or list of field values.`,
        );
      }

      const documentSnapshot = docOrField;

      if (!documentSnapshot.exists) {
github invertase / react-native-firebase / packages / messaging / lib / index.js View on Github external
onMessage(listener) {
    if (!isFunction(listener)) {
      throw new Error("firebase.messaging().onMessage(*) 'listener' expected a function.");
    }

    // TODO(salakar) rework internals as without this native module will never be ready (therefore never subscribes)
    this.native;

    const subscription = this.emitter.addListener('messaging_message_received', listener);
    return () => subscription.remove();
  }
github invertase / react-native-firebase / packages / storage / lib / StorageTask.js View on Github external
function wrapSnapshotEventListener(task, listenerFn, unsubscribe) {
  if (!isFunction(listenerFn)) {
    return null;
  }
  return event => {
    if (unsubscribe) {
      setTimeout(() => unsubscribe(), 0);
    } // 1 frame = 16ms, pushing to next frame
    if (isFunction(listenerFn)) {
      const snapshot = Object.assign({}, event);
      snapshot.task = task;
      snapshot.ref = task._ref;

      if (snapshot.metadata) {
        if (!snapshot.metadata.generation) {
          snapshot.metadata.generation = '';
        }
        if (!snapshot.metadata.bucket) {

@react-native-firebase/app

A well tested, feature rich Firebase implementation for React Native, supporting iOS & Android. Individual module support for Admob, Analytics, Auth, Crash Reporting, Cloud Firestore, Database, Dynamic Links, Functions, Messaging (FCM), Remote Config, Sto

Apache-2.0
Latest version published 3 days ago

Package Health Score

82 / 100
Full package analysis