diff --git a/README.md b/README.md index 2e4d5b03..8ebb9205 100644 --- a/README.md +++ b/README.md @@ -5,9 +5,17 @@ [![Package Quality](http://npm.packagequality.com/shield/react-native-firebase.svg?style=flat-square)](http://packagequality.com/#?package=react-native-firebase) [![Chat](https://img.shields.io/badge/chat-on%20discord-7289da.svg?style=flat-square)](https://discord.gg/t6bdqMs) [![Donate](https://img.shields.io/badge/Donate-Patreon-green.svg?style=flat-square)](https://www.patreon.com/invertase) +[![Twitter Follow](https://img.shields.io/twitter/follow/rnfirebase.svg?style=social&label=Follow)](https://twitter.com/rnfirebase) -**RNFirebase** makes using [Firebase](http://firebase.com) with React Native simple. +**RNFirebase** makes using [Firebase](http://firebase.com) with React Native simple. + +--- + +We also support **both** databases: Realtime Database and Cloud Firestore! + +--- + - - - - - diff --git a/docs/core/config-default-app.md b/docs/core/config-default-app.md deleted file mode 100644 index 91a51536..00000000 --- a/docs/core/config-default-app.md +++ /dev/null @@ -1,4 +0,0 @@ - - -### Enable Database Persistence - diff --git a/docs/core/config-rnfirebase.md b/docs/core/config-rnfirebase.md index b18a4228..3dd6e5cd 100644 --- a/docs/core/config-rnfirebase.md +++ b/docs/core/config-rnfirebase.md @@ -1,5 +1,8 @@ ### Log Options +TODO - PR's welcome + ### Debug Options +TODO - PR's welcome diff --git a/docs/core/default-app.md b/docs/core/default-app.md new file mode 100644 index 00000000..cfb2ba64 --- /dev/null +++ b/docs/core/default-app.md @@ -0,0 +1,27 @@ +### Default Firebase App + +After following the iOS & Android install guides and correctly setting up your google services plist/json files; the default app is automatically initialized and available for use in react-native-firebase. + +There's no need to call `initializeApp(opt)` in your JS code for the default app, import RNFirebase and use the default app straight away: + +```javascript +import firebase from 'react-native-firebase'; + +console.log(firebase.database().app.name); // '[DEFAULT]' +``` + +!> Calling `initializeApp()` for the default app will throw an 'app already initialized' error in a later release. + +### Enable Database Persistence + +Enabling database persistence (setPersistence) via JS for the default app is no longer supported. This breaking change was added in v3 to prevent several race condition issues around. + +You can still however easily enable this natively for the default app instance: + +#### Android + +Add `FirebaseDatabase.getInstance().setPersistenceEnabled(true);` inside your `MainActivity.java` files `onCreate()` method. + +#### iOS + +Add `[FIRDatabase database].persistenceEnabled = YES;` after the `[FIRApp configure];` line inside your `AppDelegate.m` files `didFinishLaunchingWithOptions` method. diff --git a/docs/core/firebase.md b/docs/core/firebase.md index c203c11f..74ddc24c 100644 --- a/docs/core/firebase.md +++ b/docs/core/firebase.md @@ -1,9 +1,10 @@ # Firebase - - - - - - - +TODO Reference Docs: + +- apps(): Array +- app(): FirebaseApp +- initializeApp(): FirebaseApp +- setLogLevel() +- SDK_VERSION: String +- googleApiAvailability: Object diff --git a/docs/core/initialize-apps.md b/docs/core/initialize-apps.md new file mode 100644 index 00000000..8bda76f1 --- /dev/null +++ b/docs/core/initialize-apps.md @@ -0,0 +1,93 @@ +## Initializing Apps + +!> The **default** firebase app instance can **not** be initialized via JS, please setup your google services plist/json files in your android studio / xcode projects. See [Default App](/core/default-app) for more information. + +App initialization in RNFirebase is for the most part the same as the web sdk, with only a few minor differences. + +### Supported Modules + +Only 4 modules on the official firebase native SDK's support multiple apps, they are as follows: + + - Authentication + - Database + - Firestore + - Storage + +### Initialize via JavaScript + +#### Cross Platform Example + +```javascript +import { Platform } from 'react-native'; +import firebase from 'react-native-firebase'; + +// pluck values from your `GoogleService-Info.plist` you created on the firebase console +const iosConfig = { + clientId: 'x', + appId: 'x', + apiKey: 'x', + databaseURL: 'x', + storageBucket: 'x', + messagingSenderId: 'x', + projectId: 'x', + + // enable persistence by adding the below flag + persistence: true, +}; + +// pluck values from your `google-services.json` file you created on the firebase console +const androidConfig = { + clientId: 'x', + appId: 'x', + apiKey: 'x', + databaseURL: 'x', + storageBucket: 'x', + messagingSenderId: 'x', + projectId: 'x', + + // enable persistence by adding the below flag + persistence: true, +}; + +const kittensApp = firebase.initializeApp( + // use platform specific firebase config + Platform.OS === 'ios' ? iosConfig : androidConfig, + // name of this app + 'kittens', +); + +// dynamically created apps aren't available immediately due to the +// asynchronous nature of react native bridging, therefore you must +// wait for an `onReady` state before calling any modules/methods +// otherwise you will most likely run into `app not initialized` exceptions +kittensApp.onReady().then((app) => { + // --- ready --- + // use `app` arg, kittensApp var or `app('kittens')` to access modules + // and their methods. e.g: + firebase.app('kittens').auth().signInAnonymously().then((user) => { + console.log('kittensApp user ->', user.toJSON()); + }); +}); +``` + +### Initialize via Android/iOS native code + +If you're familiar with native code you can create apps natively also (or if you are already initializing additional apps natively on app boot) - these apps automatically become available for use inside RNFirebase. + +For example, if you created an app natively called `dogs` then the following would work: + +```javascript +import firebase from 'react-native-firebase'; + +const dogsApp = firebase.app('dogs'); + +dogsApp.auth().signInAnonymously().then((user) => { + console.log('dogsApp user ->', user.toJSON()); +}); +``` + + +### Deleting an app instance + +Currently it's not possible to provide cross platform 'delete app' functionality as the Firebase Android SDK is missing the app delete method, this has been flagged with firebase ([firebase/firebase-ios-sdk#140 (comment)](https://github.com/firebase/firebase-ios-sdk/issues/140#issuecomment-315953708)). + diff --git a/docs/index.html b/docs/index.html index 6f68d6c6..01fcfb85 100644 --- a/docs/index.html +++ b/docs/index.html @@ -45,11 +45,11 @@ ], } - + + + + +