From cf71a2427da219108a1568fd9d1b7d3b963a8427 Mon Sep 17 00:00:00 2001 From: Chris Bianca Date: Thu, 27 Apr 2017 11:08:08 +0100 Subject: [PATCH 01/39] Bump version for release --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index b5ad4acc..432653dc 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "react-native-firebase", - "version": "1.0.0-alpha12", + "version": "1.0.0-alpha13", "author": "Invertase (http://invertase.io)", "description": "A react native firebase library supporting both android and ios native firebase SDK's", "main": "index", From d55bba3653ab8f25d395f1869779a3749e62824e Mon Sep 17 00:00:00 2001 From: Chris Bianca Date: Thu, 27 Apr 2017 11:09:08 +0100 Subject: [PATCH 02/39] Revert version --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 432653dc..b5ad4acc 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "react-native-firebase", - "version": "1.0.0-alpha13", + "version": "1.0.0-alpha12", "author": "Invertase (http://invertase.io)", "description": "A react native firebase library supporting both android and ios native firebase SDK's", "main": "index", From 6c4d80d162fd1acc7d0d665c08e7031e27442ae3 Mon Sep 17 00:00:00 2001 From: Chris Bianca Date: Thu, 27 Apr 2017 11:10:08 +0100 Subject: [PATCH 03/39] 1.0.0-alpha13 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index b5ad4acc..432653dc 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "react-native-firebase", - "version": "1.0.0-alpha12", + "version": "1.0.0-alpha13", "author": "Invertase (http://invertase.io)", "description": "A react native firebase library supporting both android and ios native firebase SDK's", "main": "index", From 361535e96e6a78c0e5d68f85faac3a6cf60580d3 Mon Sep 17 00:00:00 2001 From: Elliot Hesp Date: Thu, 27 Apr 2017 12:18:12 +0100 Subject: [PATCH 04/39] Move docs to docsify --- docs/.nojekyll | 0 docs/README.md | 20 ++++++++ docs/_sidebar.md | 25 ++++++++++ docs/api/remote-config.md | 1 - docs/contributing/guidelines.md | 5 ++ docs/contributing/testing.md | 3 ++ docs/faqs.md | 12 ++--- docs/firebase-setup.md | 44 ++---------------- docs/index.html | 46 +++++++++++++++++++ ...ion.android.md => installation-android.md} | 6 +-- ...nstallation.ios.md => installation-ios.md} | 19 ++++---- docs/{api => modules}/analytics.md | 0 docs/{api => modules}/authentication.md | 0 docs/{api => modules}/cloud-messaging.md | 4 +- docs/{api => modules}/crash.md | 2 +- docs/{api => modules}/database.md | 0 docs/{api => modules}/storage.md | 2 - docs/{api => modules}/transactions.md | 4 +- docs/usage.md | 36 +++++++++++++++ 19 files changed, 164 insertions(+), 65 deletions(-) create mode 100644 docs/.nojekyll create mode 100644 docs/README.md create mode 100644 docs/_sidebar.md delete mode 100644 docs/api/remote-config.md create mode 100644 docs/contributing/guidelines.md create mode 100644 docs/contributing/testing.md create mode 100644 docs/index.html rename docs/{installation.android.md => installation-android.md} (97%) rename docs/{installation.ios.md => installation-ios.md} (89%) rename docs/{api => modules}/analytics.md (100%) rename docs/{api => modules}/authentication.md (100%) rename docs/{api => modules}/cloud-messaging.md (96%) rename docs/{api => modules}/crash.md (95%) rename docs/{api => modules}/database.md (100%) rename docs/{api => modules}/storage.md (97%) rename docs/{api => modules}/transactions.md (62%) create mode 100644 docs/usage.md diff --git a/docs/.nojekyll b/docs/.nojekyll new file mode 100644 index 00000000..e69de29b diff --git a/docs/README.md b/docs/README.md new file mode 100644 index 00000000..f45bd754 --- /dev/null +++ b/docs/README.md @@ -0,0 +1,20 @@ + +

+
+ + React Native Firebase +

+ +
+A well tested Firebase implementation for React Native, supporting both iOS & Android apps. +
+ +--- + +RNFirebase is a _light-weight_ layer sitting on-top of the native Firebase libraries for both iOS and Android which mirrors the Firebase Web SDK as closely as possible. + +Although the [Firebase Web SDK](https://www.npmjs.com/package/firebase) library will work with React Native, it is mainly built for the web. + +RNFirebase provides a JavaScript bridge to the native Firebase SDKs for both iOS and Android. Firebase will run on the native thread, allowing the rest of your app to run on the [JS thread](https://facebook.github.io/react-native/docs/performance.html#javascript-frame-rate). The Firebase Web SDK also runs on the JS thread, therefore potentially affecting the frame rate causing jank with animations, touch events etc. All in all, RNFirebase provides much faster performance (~2x) over the web SDK. + +The native SDKs also allow us to hook into device sdk's which are not possible with the web SDK, for example crash reporting, offline realtime database support, analyics and more! diff --git a/docs/_sidebar.md b/docs/_sidebar.md new file mode 100644 index 00000000..1a3742eb --- /dev/null +++ b/docs/_sidebar.md @@ -0,0 +1,25 @@ +- Getting started + - [Installation - iOS](/installation-ios) + - [Installation - Android](/installation-android) + - [Firebase Setup](/firebase-setup.md) + - [Usage](/usage) + +- Contributing + - [Guidelines](/contributing/guidelines) + - [Testing](/contributing/testing) + +- Modules + - [Authentication](/modules/authentication) + - [Realtime Database](/modules/database) + - [Analytics](/modules/analytics) + - [Storage](/modules/storage) + - [Cloud Messaging](/modules/cloud-messaging) + - [Crash Reporting](/modules/crash) + - [Transactions](/modules/transactions) + +- Other + - [Project Board](https://github.com/invertase/react-native-firebase/projects) + - [FAQs / Troubleshooting](/faqs) + - [Examples](https://github.com/invertase/react-native-firebase-examples) + - [Chat](https://discord.gg/t6bdqMs) + - [Gitter](https://gitter.im/invertase/react-native-firebase) diff --git a/docs/api/remote-config.md b/docs/api/remote-config.md deleted file mode 100644 index 413c634a..00000000 --- a/docs/api/remote-config.md +++ /dev/null @@ -1 +0,0 @@ -# Remote Config diff --git a/docs/contributing/guidelines.md b/docs/contributing/guidelines.md new file mode 100644 index 00000000..c7b8ad3c --- /dev/null +++ b/docs/contributing/guidelines.md @@ -0,0 +1,5 @@ +# Guidelines + +We welcome any contribution to the repository. Please ensure your changes to the JavaScript code follow the styling guides controlled by ESlint. Changes to native code should be kept clean and follow the standard of existing code. + +Changes to existing code should ensure all relevant tests on the test app pass. Any new features should have new tests created and ensure all existing tests pass. diff --git a/docs/contributing/testing.md b/docs/contributing/testing.md new file mode 100644 index 00000000..3b446c28 --- /dev/null +++ b/docs/contributing/testing.md @@ -0,0 +1,3 @@ +# Testing + +TODO diff --git a/docs/faqs.md b/docs/faqs.md index 288fcd03..14f77151 100644 --- a/docs/faqs.md +++ b/docs/faqs.md @@ -1,6 +1,6 @@ # FAQs / Troubleshooting -### Comparison to Firestack +## Comparison to Firestack Firestack was a great start to integrating Firebase and React Native, however has underlying issues which needed to be fixed. A V3 fork of Firestack was created to help address issues such as lack of standardisation with the Firebase Web SDK, @@ -10,7 +10,7 @@ too large to manage on the existing repository, whilst trying to maintain backwa RNFirebase was re-written from the ground up, addressing these issues with core focus being around matching the Web SDK as closely as possible and fixing the major bugs/issues along the way. -### How do I integrate Redux with RNFirebase +## How do I integrate Redux with RNFirebase As every project has different requirements & structure, RNFirebase *currently* has no built in methods for Redux integration. As RNFirebase can be used outside of a Components context, you do have free reign to integrate it as you see fit. For example, @@ -42,7 +42,7 @@ export function onAuthStateChanged() { } ``` -### [Android] Google Play Services related issues +## [Android] Google Play Services related issues The firebase SDK requires a certain version of Google Play Services installed on Android in order to function properly. @@ -68,7 +68,7 @@ party emulator such as GenyMotion. Using this kind of workaround with Google Play Services can be problematic, so we recommend using the native Android Studio emulators to reduce the chance of these complications. -### [Android] Turning off Google Play Services availability errors +## [Android] Turning off Google Play Services availability errors G.P.S errors can be turned off using a config option like so: @@ -79,7 +79,7 @@ const firebase = RNFirebase.initializeApp({ ``` This will stop your app from immediately red-boxing or crashing, but won't solve the underlying issue of G.P.S not being available or of the correct version. This will mean certain functionalities won't work properly and your app may even crash. -### [Android] Checking for Google Play Services availability with React Native Firebase +## [Android] Checking for Google Play Services availability with React Native Firebase React Native Firebase actually has a useful helper object for checking G.P.S availability: @@ -109,7 +109,7 @@ This error will match the messages and error codes mentioned above, and can be f https://developers.google.com/android/reference/com/google/android/gms/common/ConnectionResult#SERVICE_VERSION_UPDATE_REQUIRED -### [Android] Duplicate Dex Files error (build time error) +## [Android] Duplicate Dex Files error (build time error) A common build time error when using libraries that require google play services is of the form: 'Failed on android with com.android.dex.DexException: Multiple dex files... ' diff --git a/docs/firebase-setup.md b/docs/firebase-setup.md index 3407d0ba..6a054fea 100644 --- a/docs/firebase-setup.md +++ b/docs/firebase-setup.md @@ -10,45 +10,11 @@ Each platform uses a different setup method after creating the project. ## iOS -See the [ios setup guide](./installation.ios.md). +For iOS, ensure you've followed the instructions provided by Firebase; adding your [GoogleService-Info.plist](https://github.com/invertase/react-native-firebase/blob/master/tests/ios/GoogleService-Info.plist) +file to the project, and [configuring your AppDelegate](https://github.com/invertase/react-native-firebase/blob/master/tests/ios/ReactNativeFirebaseDemo/AppDelegate.m#L20). ## Android -See the [android setup guide](./installation.android.md). - -## Usage - -After creating a Firebase project and installing the library, we can use it in our project by importing the library in our JavaScript: - -```javascript -import RNFirebase from 'react-native-firebase' -``` - -We need to tell the Firebase library we want to _configure_ the project. RNFirebase provides a way to configure both the native and the JavaScript side of the project at the same time with a single command: - -```javascript -const firebase = RNFirebase.initializeApp({ - // config options -}); -``` - -### Configuration Options - -| option | type | Default Value | Description | -|----------------|----------|-------------------------|----------------------------------------| -| debug | bool | false | When set to true, RNFirebase will log messages to the console and fire `debug` events we can listen to in `js` | -| persistence | bool | false | When set to true, database persistence will be enabled. | - -For instance: - -```javascript -import RNFirebase from 'react-native-firebase'; - -const configurationOptions = { - debug: true -}; - -const firebase = RNFirebase.initializeApp(configurationOptions); - -export default firebase; -``` +For Android, ensure you've followed the instructions provided by Firebase; adding your [google-services.json](https://github.com/invertase/react-native-firebase/blob/master/tests/android/app/google-services.json) +file to the project, installing the [google-services](https://github.com/invertase/react-native-firebase/blob/master/tests/android/build.gradle#L9) + plugin and applying **at the end** of your [`build.gradle`](https://github.com/invertase/react-native-firebase/blob/master/tests/android/app/build.gradle#L144). diff --git a/docs/index.html b/docs/index.html new file mode 100644 index 00000000..52157045 --- /dev/null +++ b/docs/index.html @@ -0,0 +1,46 @@ + + + + + react-native-firebase - A react native firebase library supporting both android and ios native firebase SDK's + + + + + +
+ + + + + + + + + + diff --git a/docs/installation.android.md b/docs/installation-android.md similarity index 97% rename from docs/installation.android.md rename to docs/installation-android.md index 509bc91e..f1555ec1 100644 --- a/docs/installation.android.md +++ b/docs/installation-android.md @@ -1,6 +1,6 @@ # Android Installation -### 1 - Setup google-services.json +## 1) Setup google-services.json Download the `google-services.json` file provided by Firebase in the _Add Firebase to Android_ platform menu in your Firebase configuration console. This file should be downloaded to `YOUR_PROJECT/android/app/google-services.json`. Next you'll have to add the google-services gradle plugin in order to parse it. @@ -23,7 +23,7 @@ In your app build.gradle file, add the gradle plugin at the VERY BOTTOM of the f apply plugin: 'com.google.gms.google-services' ``` -### 2 - Link RNFirebase +## 2) Link RNFirebase To install `react-native-firebase` in your project, you'll need to import the package from `io.invertase.firebase` in your project's `android/app/src/main/java/com/[app name]/MainApplication.java` and list it as a package for ReactNative in the `getPackages()` function: @@ -61,7 +61,7 @@ include ':react-native-firebase' project(':react-native-firebase').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-firebase/android') ``` -### 3 - Cloud Messaging (optional) +## 3) Cloud Messaging (optional) If you plan on using [Firebase Cloud Messaging](https://firebase.google.com/docs/cloud-messaging/), add the following to `android/app/src/main/AndroidManifest.xml`. diff --git a/docs/installation.ios.md b/docs/installation-ios.md similarity index 89% rename from docs/installation.ios.md rename to docs/installation-ios.md index 2ac49b9d..d0bdcb07 100644 --- a/docs/installation.ios.md +++ b/docs/installation-ios.md @@ -1,9 +1,9 @@ -## iOS Installation +# iOS Installation -### 1 - Setup google-services.plist and dependencies +## 1) Setup google-services.plist and dependencies Setup the `google-services.plist` file and Firebase ios frameworks first; check out the relevant Firebase docs [here](https://firebase.google.com/docs/ios/setup#frameworks). -#### 1.1 - Initialisation +### 1.1) Initialisation Make sure you've added the following to the top of your `ios/[YOUR APP NAME]]/AppDelegate.m` file: `#import ` @@ -12,10 +12,10 @@ and this to the `didFinishLaunchingWithOptions:(NSDictionary *)launchOptions` me `[FIRApp configure];` -### 2 - Link RNFirebase +## 2) Link RNFirebase There are multiple ways to install RNFirebase depending on how your project is currently setup: -#### 2.1 - Existing Cocoapods setup, including React Native as a pod +### 2.1) Existing Cocoapods setup, including React Native as a pod Simply add the following to your `Podfile`: ```ruby @@ -33,7 +33,7 @@ pod 'Firebase/Storage' pod 'RNFirebase', :path => '../node_modules/react-native-firebase' ``` -#### 2.2 - Via react-native-cli link +### 2.2) Via react-native-cli link React native ships with a `link` command that can be used to link the projects together, which can help automate the process of linking our package environments. ```bash @@ -46,12 +46,13 @@ Update the newly installed pods once the linking is done: cd ios && pod update --verbose ``` -##### cocoapods +### cocoapods + We've automated the process of setting up with cocoapods. This will happen automatically upon linking the package with `react-native-cli`. -**Remember to use the `ios/[YOUR APP NAME].xcworkspace` instead of the `ios/[YOUR APP NAME].xcproj` file from now on**. +> Remember to use the `ios/[YOUR APP NAME].xcworkspace` instead of the `ios/[YOUR APP NAME].xcproj` file from now on. -#### 2.3 - Manually +### 2.3) Manually If you prefer not to use `react-native link`, we can manually link the package together with the following steps, after `npm install`: diff --git a/docs/api/analytics.md b/docs/modules/analytics.md similarity index 100% rename from docs/api/analytics.md rename to docs/modules/analytics.md diff --git a/docs/api/authentication.md b/docs/modules/authentication.md similarity index 100% rename from docs/api/authentication.md rename to docs/modules/authentication.md diff --git a/docs/api/cloud-messaging.md b/docs/modules/cloud-messaging.md similarity index 96% rename from docs/api/cloud-messaging.md rename to docs/modules/cloud-messaging.md index c467a43b..5b37ce41 100644 --- a/docs/api/cloud-messaging.md +++ b/docs/modules/cloud-messaging.md @@ -1,6 +1,6 @@ # Cloud Messaging -Firebase Cloud Messaging ([FCM](https://firebase.google.com/docs/cloud-messaging/)) allows you to send push messages at no +Firebase Cloud Messaging ([FCM](https://firebase.google.com/docs/cloud-messaging/)) allows you to send push messages at no cost to both Android & iOS platforms. Assuming the installation instructions have been followed, FCM is ready to go. As the Firebase Web SDK has limited messaging functionality, the following methods within `react-native-firebase` have been @@ -26,7 +26,7 @@ firebase.messaging().unsubscribeFromTopic('foobar'); ### getInitialNotification(): `Promise` -When the application has been opened from a notification `getInitialNotification` is called and the notification payload +When the application has been opened from a notification `getInitialNotification` is called and the notification payload is returned. Use `onMessage` for notifications when the app is running. ```javascript diff --git a/docs/api/crash.md b/docs/modules/crash.md similarity index 95% rename from docs/api/crash.md rename to docs/modules/crash.md index 2e1295b0..2e986a62 100644 --- a/docs/api/crash.md +++ b/docs/modules/crash.md @@ -4,7 +4,7 @@ RNFirebase provides crash reporting for your app out of the box. Please note cra ## Manual Crash Reporting -If you want to manually report a crash, such as a pre-caught exception this is possible by using the `report` method. +If you want to manually report a crash, such as a pre-caught exception this is possible by using the `report` method. ```javascript try { diff --git a/docs/api/database.md b/docs/modules/database.md similarity index 100% rename from docs/api/database.md rename to docs/modules/database.md diff --git a/docs/api/storage.md b/docs/modules/storage.md similarity index 97% rename from docs/api/storage.md rename to docs/modules/storage.md index e2d0ae64..6ea5922c 100644 --- a/docs/api/storage.md +++ b/docs/modules/storage.md @@ -3,8 +3,6 @@ RNFirebase mimics the [Web Firebase SDK Storage](https://firebase.google.com/docs/storage/web/start), whilst providing some iOS and Android specific functionality. -All Storage operations are accessed via `storage()`. - ## Uploading files ### Simple diff --git a/docs/api/transactions.md b/docs/modules/transactions.md similarity index 62% rename from docs/api/transactions.md rename to docs/modules/transactions.md index 64ab1f3f..4df2f508 100644 --- a/docs/api/transactions.md +++ b/docs/modules/transactions.md @@ -1,6 +1,6 @@ # Transactions -Transactions are currently an experimental feature as they can not be integrated as easily as the other Firebase features. Please see the [Firebase documentation](https://firebase.google.com/docs/reference/js/firebase.database.Reference#transaction) for full implemtation details. +> Transactions are currently an experimental feature as they can not be integrated as easily as the other Firebase features. Please see the [Firebase documentation](https://firebase.google.com/docs/reference/js/firebase.database.Reference#transaction) for full implemtation details. ## Example @@ -17,7 +17,7 @@ ref.transaction((posts) => { } else { console.log('User posts incremented by 1'); } - + console.log('User posts is now: ', snapshot.val()); }); ``` diff --git a/docs/usage.md b/docs/usage.md new file mode 100644 index 00000000..117ad9d7 --- /dev/null +++ b/docs/usage.md @@ -0,0 +1,36 @@ +# Usage + +After creating a Firebase project and installing the library, we can use it in our project by importing the library in our JavaScript: + +```javascript +import RNFirebase from 'react-native-firebase' +``` + +We need to tell the Firebase library we want to _configure_ the project. RNFirebase provides a way to configure both the native and the JavaScript side of the project at the same time with a single command: + +```javascript +const firebase = RNFirebase.initializeApp({ + // config options +}); +``` + +## Configuration Options + +| option | type | Default Value | Description | +|----------------|----------|-------------------------|----------------------------------------| +| debug | bool | false | When set to true, RNFirebase will log messages to the console and fire `debug` events we can listen to in `js` | +| persistence | bool | false | When set to true, database persistence will be enabled. | + +For instance: + +```javascript +import RNFirebase from 'react-native-firebase'; + +const configurationOptions = { + debug: true +}; + +const firebase = RNFirebase.initializeApp(configurationOptions); + +export default firebase; +``` From af7502e19954eaaf33302fb8c871adbe8209d4f3 Mon Sep 17 00:00:00 2001 From: Elliot Hesp Date: Thu, 27 Apr 2017 12:25:29 +0100 Subject: [PATCH 05/39] Cleanup main README --- README.md | 47 ++++------------------------------------------- docs/README.md | 5 +++++ 2 files changed, 9 insertions(+), 43 deletions(-) diff --git a/README.md b/README.md index e04793aa..61aec0d2 100644 --- a/README.md +++ b/README.md @@ -8,13 +8,15 @@ **RNFirebase** makes using [Firebase](http://firebase.com) with React Native simple.
+> [Documentation](https://invertase.io/react-native-firebase) + ### Install -``` +```bash npm i react-native-firebase --save ``` #### Platform specific setup guides: -[![ios](https://a.fsdn.com/sd/topics/ios_64.png)](docs/installation.ios.md) [![android](https://a.fsdn.com/sd/topics/android_64.png)](docs/installation.android.md) +[![ios](https://a.fsdn.com/sd/topics/ios_64.png)](http://invertase.io/react-native-firebase/#/installation-ios) [![android](https://a.fsdn.com/sd/topics/android_64.png)](http://invertase.io/react-native-firebase/#/installation-android)
@@ -30,47 +32,6 @@ The native SDKs also allow us to hook into device sdk's which are not possible w
-### Test app - -To help ensure changes and features work across both iOS & Android, we've developed an app specifically to test `react-native-firebase` against the [`firebase` web SDK](https://www.npmjs.com/package/firebase). Please see the [`tests`](tests/README.md) directory for more information. - -
- -### Examples app - -There's currently a work in progress [examples app](https://github.com/invertase/react-native-firebase-examples) which aims to demonstrate various real world use-case scenarios with React Native & Firebase. We welcome any new examples or updates to existing ones. - -
- -### Documentation - -RNFirebase aims to replicate the Firebase Web SDK as closely as possible. Because of this, the documentation focuses around the installation, differences & best practices of this library. Please see the [Firebase Web SDK](https://firebase.google.com/docs/reference/js/) documentation for Firebase functionality. - -> If you find any discrepancies between the two libraries, please raise an issue or PR. - -* [Firebase Setup](docs/firebase-setup.md) -* API - * [Authentication](docs/api/authentication.md) - * [Realtime Database](docs/api/database.md) - * [Analytics](docs/api/analytics.md) - * [Storage](docs/api/storage.md) - * [Messaging](docs/api/cloud-messaging.md) - * [Crash](docs/api/crash.md) - * [Transactions](docs/api/transactions.md) -* [FAQs / Troubleshooting](docs/faqs.md) - -
- -### Contributing - -We welcome any contribution to the repository. Please ensure your changes to the JavaScript code follow the styling guides controlled by ESlint. Changes to native code should be kept clean and follow the standard of existing code. - -Changes to existing code should ensure all relevant tests on the test app pass. Any new features should have new tests created and ensure all existing tests pass. - -**Project board:** https://github.com/invertase/react-native-firebase/projects - -
- ### License - MIT diff --git a/docs/README.md b/docs/README.md index f45bd754..a2c60da3 100644 --- a/docs/README.md +++ b/docs/README.md @@ -6,6 +6,11 @@
+[![Chat](https://img.shields.io/badge/chat-on%20discord-7289da.svg)](https://discord.gg/t6bdqMs) +[![Gitter](https://badges.gitter.im/invertase/react-native-firebase.svg)](https://gitter.im/invertase/react-native-firebase?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge) +[![npm version](https://img.shields.io/npm/v/react-native-firebase.svg)](https://www.npmjs.com/package/react-native-firebase) +[![License](https://img.shields.io/npm/l/react-native-firebase.svg)](/LICENSE) +
A well tested Firebase implementation for React Native, supporting both iOS & Android apps.
From ea4b4150b8ba2c53cb61ad1a9153318daad6d784 Mon Sep 17 00:00:00 2001 From: Elliot Hesp Date: Thu, 27 Apr 2017 12:27:34 +0100 Subject: [PATCH 06/39] Add Favicon --- docs/index.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/index.html b/docs/index.html index 52157045..ace4a547 100644 --- a/docs/index.html +++ b/docs/index.html @@ -5,7 +5,7 @@ react-native-firebase - A react native firebase library supporting both android and ios native firebase SDK's - +
From 40dd20d26f78e8dc6b89cd16e455103544a81e07 Mon Sep 17 00:00:00 2001 From: Elliot Hesp Date: Thu, 27 Apr 2017 12:36:42 +0100 Subject: [PATCH 07/39] Link image/title to docks --- docs/README.md | 6 ++++-- docs/contributing/testing.md | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/docs/README.md b/docs/README.md index a2c60da3..bf7dc742 100644 --- a/docs/README.md +++ b/docs/README.md @@ -1,8 +1,10 @@

-
+ +
+
- React Native Firebase + React Native Firebase

diff --git a/docs/contributing/testing.md b/docs/contributing/testing.md index 3b446c28..383062db 100644 --- a/docs/contributing/testing.md +++ b/docs/contributing/testing.md @@ -1,3 +1,3 @@ # Testing -TODO + From 4fa51d26273ffceb7a33107406b3393b5bf03a9a Mon Sep 17 00:00:00 2001 From: Elliot Hesp Date: Thu, 27 Apr 2017 12:39:37 +0100 Subject: [PATCH 08/39] Update README.md --- README.md | 6 ++++-- docs/README.md | 6 ++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 61aec0d2..5cbd3754 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# React Native Firebase +# React Native Firebase [![Chat](https://img.shields.io/badge/chat-on%20discord-7289da.svg)](https://discord.gg/t6bdqMs) [![Gitter](https://badges.gitter.im/invertase/react-native-firebase.svg)](https://gitter.im/invertase/react-native-firebase?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge) @@ -6,10 +6,12 @@ [![License](https://img.shields.io/npm/l/react-native-firebase.svg)](/LICENSE) **RNFirebase** makes using [Firebase](http://firebase.com) with React Native simple. -
> [Documentation](https://invertase.io/react-native-firebase) + +
+ ### Install ```bash npm i react-native-firebase --save diff --git a/docs/README.md b/docs/README.md index bf7dc742..a2c60da3 100644 --- a/docs/README.md +++ b/docs/README.md @@ -1,10 +1,8 @@

- -
-
+
- React Native Firebase + React Native Firebase

From 6cee2609b10d34d4771ee95792eef1d120704716 Mon Sep 17 00:00:00 2001 From: Ben Styles Date: Fri, 28 Apr 2017 10:27:29 +0100 Subject: [PATCH 09/39] fixed some flow and eslint errors --- lib/modules/database/reference.js | 12 ++++++----- lib/modules/storage/reference.js | 2 +- lib/modules/storage/task.js | 30 ++++++++++++++++++--------- tests/src/containers/CoreContainer.js | 3 ++- 4 files changed, 30 insertions(+), 17 deletions(-) diff --git a/lib/modules/database/reference.js b/lib/modules/database/reference.js index b8025c38..67f88c2d 100644 --- a/lib/modules/database/reference.js +++ b/lib/modules/database/reference.js @@ -151,23 +151,25 @@ export default class Reference extends ReferenceBase { */ off(eventName?: string = '', origCB?: () => any) { this.log.debug('ref.off(): ', this.refId, eventName); + // $FlowFixMe + const listeners: Array = Object.values(this.listeners); let listenersToRemove; if (eventName && origCB) { - listenersToRemove = Object.values(this.listeners).filter((listener) => { + listenersToRemove = listeners.filter((listener) => { return listener.eventName === eventName && listener.successCallback === origCB; }); // Only remove a single listener as per the web spec if (listenersToRemove.length > 1) listenersToRemove = [listenersToRemove[0]]; } else if (eventName) { - listenersToRemove = Object.values(this.listeners).filter((listener) => { + listenersToRemove = listeners.filter((listener) => { return listener.eventName === eventName; }); } else if (origCB) { - listenersToRemove = Object.values(this.listeners).filter((listener) => { + listenersToRemove = listeners.filter((listener) => { return listener.successCallback === origCB; }); } else { - listenersToRemove = Object.values(this.listeners); + listenersToRemove = listeners; } // Remove the listeners from the reference to prevent memory leaks listenersToRemove.forEach((listener) => { @@ -183,7 +185,7 @@ export default class Reference extends ReferenceBase { * @param onComplete * @param applyLocally */ - transaction(transactionUpdate: Function, onComplete, applyLocally: boolean = false) { + transaction(transactionUpdate: Function, onComplete: (?Error, boolean, ?Snapshot) => *, applyLocally: boolean = false) { if (!isFunction(transactionUpdate)) return Promise.reject(new Error('Missing transactionUpdate function argument.')); return new Promise((resolve, reject) => { diff --git a/lib/modules/storage/reference.js b/lib/modules/storage/reference.js index b8cd4a34..04478d4f 100644 --- a/lib/modules/storage/reference.js +++ b/lib/modules/storage/reference.js @@ -80,7 +80,7 @@ export default class StorageReference extends ReferenceBase { * Alias to putFile * @returns {StorageReference.putFile} */ - get put() { + get put(): Function { return this.putFile; } diff --git a/lib/modules/storage/task.js b/lib/modules/storage/task.js index 4c8cb638..d365fceb 100644 --- a/lib/modules/storage/task.js +++ b/lib/modules/storage/task.js @@ -11,11 +11,13 @@ declare type UploadTaskSnapshotType = { downloadURL: string|null, metadata: Object, // TODO flow type def for https://firebase.google.com/docs/reference/js/firebase.storage.FullMetadata.html ref: StorageReference, - state: StorageStatics.TaskState.RUNNING - |StorageStatics.TaskState.PAUSED - |StorageStatics.TaskState.SUCCESS - |StorageStatics.TaskState.CANCELLED - |StorageStatics.TaskState.ERROR, + state: ( + typeof StorageStatics.TaskState.RUNNING + | typeof StorageStatics.TaskState.PAUSED + | typeof StorageStatics.TaskState.SUCCESS + | typeof StorageStatics.TaskState.CANCELLED + | typeof StorageStatics.TaskState.ERROR + ), task: StorageTask, totalBytes: number, }; @@ -32,7 +34,14 @@ declare type NextOrObserverType = null * @url https://firebase.google.com/docs/reference/js/firebase.storage.UploadTask */ export default class StorageTask { - constructor(type: UPLOAD_TASK|DOWNLOAD_TASK, promise: Promise, storageRef: StorageReference) { + type: typeof UPLOAD_TASK | typeof DOWNLOAD_TASK + ref: StorageReference + storage: StorageReference.storage + path: StorageReference.path + then: Promise<*> + catch: () => Promise<*> + + constructor(type: typeof UPLOAD_TASK | typeof DOWNLOAD_TASK, promise: Promise<*>, storageRef: StorageReference) { this.type = type; this.ref = storageRef; this.storage = storageRef.storage; @@ -49,13 +58,13 @@ export default class StorageTask { * @returns {Promise.} * @private */ - _interceptSnapshotEvent(f: Function|null|undefined): null|() => any { + _interceptSnapshotEvent(f: ?Function): null | () => * { if (!isFunction(f)) return null; return (snapshot) => { const _snapshot = Object.assign({}, snapshot); _snapshot.task = this; _snapshot.ref = this.ref; - return f(_snapshot); + return f && f(_snapshot); }; } @@ -65,12 +74,13 @@ export default class StorageTask { * @returns {*} * @private */ - _interceptErrorEvent(f: Function|null|undefined): null|() => any { + _interceptErrorEvent(f: ?Function): null | (Error) => * { if (!isFunction(f)) return null; return (error) => { const _error = new Error(error.message); + // $FlowFixMe _error.code = error.code; - return f(_error); + return f && f(_error); }; } diff --git a/tests/src/containers/CoreContainer.js b/tests/src/containers/CoreContainer.js index 2111b9dc..82e4452a 100644 --- a/tests/src/containers/CoreContainer.js +++ b/tests/src/containers/CoreContainer.js @@ -25,7 +25,7 @@ class CoreContainer extends React.Component { StatusBar.setBackgroundColor('#0279ba'); } if (Platform.OS === 'ios') { - StatusBar.setBarStyle('light-content') + StatusBar.setBarStyle('light-content'); } AppState.addEventListener('change', this.handleAppStateChange); NetInfo.isConnected.fetch().then((isConnected) => { @@ -44,6 +44,7 @@ class CoreContainer extends React.Component { } props: Props; + _isConnected: boolean; /** * Handle app state changes From 80b519158fa0132d9126366fe1b07d8da8ed83b5 Mon Sep 17 00:00:00 2001 From: Ben Styles Date: Fri, 28 Apr 2017 11:03:12 +0100 Subject: [PATCH 10/39] fixed some flow and eslint errors --- lib/modules/database/index.js | 7 ++++- lib/modules/storage/task.js | 50 ++++++++++++++++++++++++++++------- 2 files changed, 46 insertions(+), 11 deletions(-) diff --git a/lib/modules/database/index.js b/lib/modules/database/index.js index 5fc61033..775774ff 100644 --- a/lib/modules/database/index.js +++ b/lib/modules/database/index.js @@ -83,7 +83,12 @@ export default class Database extends Base { * @param origCB * @returns {*} */ - off(refId: number, 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/storage/task.js b/lib/modules/storage/task.js index d365fceb..3b2ced7d 100644 --- a/lib/modules/storage/task.js +++ b/lib/modules/storage/task.js @@ -26,9 +26,13 @@ declare type FuncSnapshotType = null|(snapshot: UploadTaskSnapshotType) => any; declare type FuncErrorType = null|(error: Error) => any; -declare type NextOrObserverType = null - |{ next?: FuncSnapshotType, error?: FuncErrorType, complete?:FuncSnapshotType } - |FuncSnapshotType; +declare type NextOrObserverType = null | + { + next?: FuncSnapshotType, + error?: FuncErrorType, + complete?:FuncSnapshotType + } | + FuncSnapshotType; /** * @url https://firebase.google.com/docs/reference/js/firebase.storage.UploadTask @@ -93,15 +97,41 @@ export default class StorageTask { * @private */ _subscribe(nextOrObserver: NextOrObserverType, error: FuncErrorType, complete: FuncSnapshotType): Function { - const observer = isObject(nextOrObserver); + let _error; + let _next; + let _complete; - const _error = this._interceptErrorEvent(observer ? nextOrObserver.error : error); - const _next = this._interceptSnapshotEvent(observer ? nextOrObserver.next : nextOrObserver); - const _complete = this._interceptSnapshotEvent(observer ? nextOrObserver.complete : complete); + if (typeof nextOrObserver === 'function') { + _error = this._interceptErrorEvent(error); + _next = this._interceptSnapshotEvent(nextOrObserver); + _complete = this._interceptSnapshotEvent(complete); + } else if (nextOrObserver) { + _error = this._interceptErrorEvent(nextOrObserver.error); + _next = this._interceptSnapshotEvent(nextOrObserver.next); + _complete = this._interceptSnapshotEvent(nextOrObserver.complete); + } - if (_next) this.storage._addListener(this.path, StorageStatics.TaskEvent.STATE_CHANGED, _next); - if (_error) this.storage._addListener(this.path, `${this.type}_failure`, _error); - if (_complete) this.storage._addListener(this.path, `${this.type}_success`, _complete); + if (_next) { + this.storage._addListener( + this.path, + StorageStatics.TaskEvent.STATE_CHANGED, + _next + ); + } + if (_error) { + this.storage._addListener( + this.path, + `${this.type}_failure`, + _error + ); + } + if (_complete) { + this.storage._addListener( + this.path, + `${this.type}_success`, + _complete + ); + } return () => { if (_next) this.storage._removeListener(this.path, StorageStatics.TaskEvent.STATE_CHANGED, _next); From 019269a66ca9343c4b5f8dd74fec173736b65148 Mon Sep 17 00:00:00 2001 From: Elliot Hesp Date: Fri, 28 Apr 2017 16:59:34 +0100 Subject: [PATCH 11/39] Update index.html --- docs/index.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/index.html b/docs/index.html index ace4a547..be66ecd5 100644 --- a/docs/index.html +++ b/docs/index.html @@ -19,7 +19,7 @@ themeColor: '#f5820b', subMaxLevel: 2, maxLevel: 4, - ga: 'UA-XXXXX-Y', + ga: 'UA-98196653-1', plugins: [ function (hook) { var footer = [ From 755bdda4a7d5e189ca3221ba10f1db2aa6cb1593 Mon Sep 17 00:00:00 2001 From: Carl Lippert Date: Sun, 30 Apr 2017 00:05:12 -0500 Subject: [PATCH 12/39] Update database.md Looks like some copied docs from firestack snuck through? --- docs/modules/database.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/modules/database.md b/docs/modules/database.md index 465526b1..407fee65 100644 --- a/docs/modules/database.md +++ b/docs/modules/database.md @@ -72,7 +72,7 @@ class MyComponent extends Component { ### Reading data -Firstack allows the database instance to [persist on disk](https://firebase.google.com/docs/database/android/offline-capabilities) if enabled. +Firebase allows the database instance to [persist on disk](https://firebase.google.com/docs/database/android/offline-capabilities) if enabled. To enable database persistence, pass the configuration option `persistence` before calls are made: ```javascript From ce7d9e64035b2439fe0d8b00dd4fed13cee1e205 Mon Sep 17 00:00:00 2001 From: Carl Lippert Date: Sun, 30 Apr 2017 00:07:30 -0500 Subject: [PATCH 13/39] Update database.md Typo --- docs/modules/database.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/modules/database.md b/docs/modules/database.md index 465526b1..63a2c8ee 100644 --- a/docs/modules/database.md +++ b/docs/modules/database.md @@ -181,7 +181,7 @@ class ToDos extends Component { #### Differences between `.on` & `.once` With persistence enabled, any calls to a ref with `.once` will always read the data from disk and not contact the server. -On behavious differently, by first checking for a connection and if none exists returns the persisted data. If it successfully connects +On behaves differently, by first checking for a connection and if none exists returns the persisted data. If it successfully connects to the server, the new data will be returned and the disk data will be updated. The database refs has a `keepSynced()` function to tell the RNFirebase library to keep the data at the `ref` in sync. From 11734e51bdb5e4f937ae8f68c60f6491807269ff Mon Sep 17 00:00:00 2001 From: Salakar Date: Mon, 1 May 2017 16:01:00 +0100 Subject: [PATCH 14/39] [tests] import RNFirebase for parent directory rather than from npm file:.. syntax --- package.json | 3 ++- tests/.gitignore | 1 - tests/android/settings.gradle | 2 +- tests/ios/Podfile | 40 +++++++++++++++++++++++++++++++++++ tests/src/firebase.js | 2 +- 5 files changed, 44 insertions(+), 4 deletions(-) create mode 100644 tests/ios/Podfile diff --git a/package.json b/package.json index b5ad4acc..da70fca0 100644 --- a/package.json +++ b/package.json @@ -9,7 +9,8 @@ "dev": "npm run compile -- --watch", "lint": "eslint ./src", "publish_pages": "gh-pages -d public/", - "watchcpx": "echo 'See https://github.com/wix/wml for watching changes. \r\n'", + "tests-packager": "cd tests && npm run start", + "tests-pod-install": "cd tests && npm run ios:pod:install", "flow": "flow" }, "repository": { diff --git a/tests/.gitignore b/tests/.gitignore index 6e4a1e09..8f21ab5f 100644 --- a/tests/.gitignore +++ b/tests/.gitignore @@ -55,7 +55,6 @@ buck-out/ fastlane/report.xml fastlane/Preview.html fastlane/screenshots -ios/Podfile ios/Podfile.lock ios/Pods/ ios/ReactNativeFirebaseDemo.xcworkspace/ diff --git a/tests/android/settings.gradle b/tests/android/settings.gradle index 444f86ec..4ead5270 100644 --- a/tests/android/settings.gradle +++ b/tests/android/settings.gradle @@ -1,6 +1,6 @@ rootProject.name = 'ReactNativeFirebaseDemo' include ':react-native-firebase' -project(':react-native-firebase').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-firebase/android') +project(':react-native-firebase').projectDir = new File(rootProject.projectDir, './../../android') include ':react-native-vector-icons' project(':react-native-vector-icons').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-vector-icons/android') diff --git a/tests/ios/Podfile b/tests/ios/Podfile new file mode 100644 index 00000000..f35d97f5 --- /dev/null +++ b/tests/ios/Podfile @@ -0,0 +1,40 @@ +install! 'cocoapods', :deterministic_uuids => false +# Uncomment this line to define a global platform for your project +# platform :ios, '9.0' + +target 'ReactNativeFirebaseDemo' do + platform :ios, '8.0' + # Uncomment this line if you're using Swift or would like to use dynamic frameworks + # use_frameworks! + + # Pods for ReactNativeFirebaseDemo + pod 'React', :path => '../node_modules/react-native', :subspecs => [ + 'Core', + 'RCTActionSheet', + 'RCTAnimation', + 'RCTCameraRoll', + 'RCTGeolocation', + 'RCTImage', + 'RCTLinkingIOS', + 'RCTNetwork', + 'RCTPushNotification', + 'RCTSettings', + 'RCTText', + 'RCTVibration', + 'RCTWebSocket' + # Add any other subspecs you want to use in your project + ] + + pod 'Firebase/Auth' + pod 'Firebase/Analytics' + pod 'Firebase/AppIndexing' + pod 'Firebase/Core' + pod 'Firebase/Crash' + pod 'Firebase/Database' + pod 'Firebase/DynamicLinks' + pod 'Firebase/Messaging' + pod 'Firebase/RemoteConfig' + pod 'Firebase/Storage' + + pod 'RNFirebase', :path => './../../' +end diff --git a/tests/src/firebase.js b/tests/src/firebase.js index e51a2b06..3f378671 100644 --- a/tests/src/firebase.js +++ b/tests/src/firebase.js @@ -1,5 +1,5 @@ import firebase from 'firebase'; -import RNfirebase from 'react-native-firebase'; +import RNfirebase from './../../'; import DatabaseContents from './tests/support/DatabaseContents'; From bc653beb2683794f128a5b8d165d9ce68d8b387e Mon Sep 17 00:00:00 2001 From: Salakar Date: Mon, 1 May 2017 17:06:40 +0100 Subject: [PATCH 15/39] [tests] import RNFirebase for parent directory rather than from npm file:.. syntax --- .gitignore | 2 ++ .npmignore | 2 ++ package.json | 8 +++++++- tests/firebase/.gitkeep | 0 4 files changed, 11 insertions(+), 1 deletion(-) create mode 100644 tests/firebase/.gitkeep diff --git a/.gitignore b/.gitignore index 3bcdc962..5798db37 100644 --- a/.gitignore +++ b/.gitignore @@ -24,6 +24,7 @@ android/local.properties # Gradle generated files android/.gradle/ +firebase # Signing files android/.signing/ @@ -56,6 +57,7 @@ android/gradlew android/build android/gradlew.bat android/gradle/ +lib/.watchmanconfig .idea .idea coverage diff --git a/.npmignore b/.npmignore index dc0208e2..4d657ee4 100644 --- a/.npmignore +++ b/.npmignore @@ -61,3 +61,5 @@ docs coverage yarn.lock tests +lib/.watchmanconfig + diff --git a/package.json b/package.json index da70fca0..903b3669 100644 --- a/package.json +++ b/package.json @@ -9,7 +9,12 @@ "dev": "npm run compile -- --watch", "lint": "eslint ./src", "publish_pages": "gh-pages -d public/", + "tests-npm-install": "cd tests && npm install", "tests-packager": "cd tests && npm run start", + "watch:add": "wml add $(node --eval \"console.log(require('path').resolve('./lib'));\") $(node --eval \"console.log(require('path').resolve('./tests/firebase'));\")", + "watch:list": "wml list", + "watch:start": "watchman watch $(node --eval \"console.log(require('path').resolve('./lib'));\") && wml start", + "watch:stop": "watchman watch-del $(node --eval \"console.log(require('path').resolve('./lib'));\") && wml stop", "tests-pod-install": "cd tests && npm run ios:pod:install", "flow": "flow" }, @@ -73,7 +78,8 @@ "flow-bin": "^0.40.0", "react": "^15.3.0", "react-dom": "^15.3.0", - "react-native": "^0.42.0" + "react-native": "^0.42.0", + "wml": "0.0.82" }, "dependencies": { "bows": "^1.6.0", diff --git a/tests/firebase/.gitkeep b/tests/firebase/.gitkeep new file mode 100644 index 00000000..e69de29b From c76796934fda747b0b0ffd54a580ce81405934b1 Mon Sep 17 00:00:00 2001 From: Salakar Date: Mon, 1 May 2017 17:13:54 +0100 Subject: [PATCH 16/39] [tests] misc firebase imports / git ignore --- .gitignore | 35 +++++++++++------------------------ tests/src/firebase.js | 2 +- 2 files changed, 12 insertions(+), 25 deletions(-) diff --git a/.gitignore b/.gitignore index 5798db37..87d61d94 100644 --- a/.gitignore +++ b/.gitignore @@ -19,30 +19,8 @@ android/*/build/ # Crashlytics configuations android/com_crashlytics_export_strings.xml -# Local configuration file (sdk path, etc) -android/local.properties - -# Gradle generated files -android/.gradle/ -firebase - # Signing files android/.signing/ - -# User-specific configurations -android/.idea/gradle.xml -android/.idea/libraries/ -android/.idea/workspace.xml -android/.idea/tasks.xml -android/.idea/.name -android/.idea/compiler.xml -android/.idea/copyright/profiles_settings.xml -android/.idea/encodings.xml -android/.idea/misc.xml -android/.idea/modules.xml -android/.idea/scopes/scope_settings.xml -android/.idea/vcs.xml -android/*.iml ios/RnFirebase.xcodeproj/xcuserdata # OS-specific files @@ -55,10 +33,19 @@ ehthumbs.db Thumbs.dbandroid/gradle android/gradlew android/build +android/.gradle android/gradlew.bat -android/gradle/ +android/gradle lib/.watchmanconfig .idea -.idea coverage yarn.lock +tests/build +tests/android/gradle +tests/ios/Podfile.lock +tests/android/app/build +tests/ios/Pods +tests/firebase +.gradle +local.properties +*.iml diff --git a/tests/src/firebase.js b/tests/src/firebase.js index 3f378671..b966843f 100644 --- a/tests/src/firebase.js +++ b/tests/src/firebase.js @@ -1,5 +1,5 @@ import firebase from 'firebase'; -import RNfirebase from './../../'; +import RNfirebase from './../firebase/firebase'; import DatabaseContents from './tests/support/DatabaseContents'; From 7fc273da418ccb79a2ac24613b357eb0b1cb7b36 Mon Sep 17 00:00:00 2001 From: Salakar Date: Mon, 1 May 2017 17:33:35 +0100 Subject: [PATCH 17/39] [tests] package scripts --- package.json | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index b67124b6..1a0da641 100644 --- a/package.json +++ b/package.json @@ -11,10 +11,9 @@ "publish_pages": "gh-pages -d public/", "tests-npm-install": "cd tests && npm install", "tests-packager": "cd tests && npm run start", - "watch:add": "wml add $(node --eval \"console.log(require('path').resolve('./lib'));\") $(node --eval \"console.log(require('path').resolve('./tests/firebase'));\")", - "watch:list": "wml list", - "watch:start": "watchman watch $(node --eval \"console.log(require('path').resolve('./lib'));\") && wml start", - "watch:stop": "watchman watch-del $(node --eval \"console.log(require('path').resolve('./lib'));\") && wml stop", + "tests-watch-init": "wml add $(node --eval \"console.log(require('path').resolve('./lib'));\") $(node --eval \"console.log(require('path').resolve('./tests/firebase'));\")", + "tests-watch-start": "watchman watch $(node --eval \"console.log(require('path').resolve('./lib'));\") && wml start", + "tests-watch-stop": "watchman watch-del $(node --eval \"console.log(require('path').resolve('./lib'));\") && wml stop", "tests-pod-install": "cd tests && npm run ios:pod:install", "flow": "flow" }, From 87f4cd6809900cf0185a3a740dc586ca2b5bbfea Mon Sep 17 00:00:00 2001 From: chrisbianca Date: Tue, 2 May 2017 09:36:17 +0100 Subject: [PATCH 18/39] Update installation-ios.md with FCM setup --- docs/installation-ios.md | 64 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) diff --git a/docs/installation-ios.md b/docs/installation-ios.md index d0bdcb07..c0512439 100644 --- a/docs/installation-ios.md +++ b/docs/installation-ios.md @@ -92,3 +92,67 @@ pod 'Firebase/Storage' ``` Then you can run `(cd ios && pod install)` to get the pods opened. If you do use this route, remember to use the `.xcworkspace` file. + +## 3) Cloud Messaging (optional) + +If you plan on using [Firebase Cloud Messaging](https://firebase.google.com/docs/cloud-messaging/) then, you need to: + +**NOTE: FCM does not work on the iOS simulator, you must test is using a real device. This is a restriction enforced by Apple for some unknown reason.** + +### 3.1) Set up certificates + +Follow the instructions at https://firebase.google.com/docs/cloud-messaging/ios/certs + +### 3.2) Enable capabilities + +In Xcode, enable the following capabilities: + +1) Push Notifications +2) Background modes > Remove notifications + +### 3.3) Update `AppDelegate.h` + +Add the following import: + +`@import UserNotifications;` + +Change the interface descriptor to: + +`@interface AppDelegate : UIResponder ` + +### 3.4) Update `AppDelegate.m` + +Add the following import: + +`#import "RNFirebaseMessaging.h"` + +Add the following to the `didFinishLaunchingWithOptions:(NSDictionary *)launchOptions` method after `[FIRApp Configure]`: + +`[[UNUserNotificationCenter currentNotificationCenter] setDelegate:self];` + +Add the following methods: + +``` +- (void)userNotificationCenter:(UNUserNotificationCenter *)center + willPresentNotification:(UNNotification *)notification + withCompletionHandler:(void (^)(UNNotificationPresentationOptions))completionHandler +{ + [RNFirebaseMessaging willPresentNotification:notification withCompletionHandler:completionHandler]; +} + +- (void)userNotificationCenter:(UNUserNotificationCenter *)center +didReceiveNotificationResponse:(UNNotificationResponse *)response + withCompletionHandler:(void (^)())completionHandler +{ + [RNFirebaseMessaging didReceiveNotificationResponse:response withCompletionHandler:completionHandler]; +} + +-(void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification { + [RNFirebaseMessaging didReceiveLocalNotification:notification]; +} + +- (void)application:(UIApplication *)application didReceiveRemoteNotification:(nonnull NSDictionary *)userInfo + fetchCompletionHandler:(nonnull void (^)(UIBackgroundFetchResult))completionHandler{ + [RNFirebaseMessaging didReceiveRemoteNotification:userInfo fetchCompletionHandler:completionHandler]; +} +``` From e9cf8a763c38f034d0f332f966301d5a5f520488 Mon Sep 17 00:00:00 2001 From: Elliot Hesp Date: Tue, 2 May 2017 09:54:10 +0100 Subject: [PATCH 19/39] Create sw.js --- docs/sw.js | 75 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 docs/sw.js diff --git a/docs/sw.js b/docs/sw.js new file mode 100644 index 00000000..ab031ac1 --- /dev/null +++ b/docs/sw.js @@ -0,0 +1,75 @@ +const RUNTIME = 'docsify' +const HOSTNAME_WHITELIST = [ + self.location.hostname, + 'fonts.gstatic.com', + 'fonts.googleapis.com', + 'unpkg.com' +] + +// The Util Function to hack URLs of intercepted requests +const getFixedUrl = (req) => { + var now = Date.now() + var url = new URL(req.url) + + // 1. fixed http URL + // Just keep syncing with location.protocol + // fetch(httpURL) belongs to active mixed content. + // And fetch(httpRequest) is not supported yet. + url.protocol = self.location.protocol + + // 2. add query for caching-busting. + // Github Pages served with Cache-Control: max-age=600 + // max-age on mutable content is error-prone, with SW life of bugs can even extend. + // Until cache mode of Fetch API landed, we have to workaround cache-busting with query string. + // Cache-Control-Bug: https://bugs.chromium.org/p/chromium/issues/detail?id=453190 + if (url.hostname === self.location.hostname) { + url.search += (url.search ? '&' : '?') + 'cache-bust=' + now + } + return url.href +} + +/** + * @Lifecycle Activate + * New one activated when old isnt being used. + * + * waitUntil(): activating ====> activated + */ +self.addEventListener('activate', event => { + event.waitUntil(self.clients.claim()) +}) + +/** + * @Functional Fetch + * All network requests are being intercepted here. + * + * void respondWith(Promise r) + */ +self.addEventListener('fetch', event => { + // Skip some of cross-origin requests, like those for Google Analytics. + if (HOSTNAME_WHITELIST.indexOf(new URL(event.request.url).hostname) > -1) { + // Stale-while-revalidate + // similar to HTTP's stale-while-revalidate: https://www.mnot.net/blog/2007/12/12/stale + // Upgrade from Jake's to Surma's: https://gist.github.com/surma/eb441223daaedf880801ad80006389f1 + const cached = caches.match(event.request) + const fixedUrl = getFixedUrl(event.request) + const fetched = fetch(fixedUrl, { cache: 'no-store' }) + const fetchedCopy = fetched.then(resp => resp.clone()) + + // Call respondWith() with whatever we get first. + // If the fetch fails (e.g disconnected), wait for the cache. + // If there’s nothing in cache, wait for the fetch. + // If neither yields a response, return offline pages. + event.respondWith( + Promise.race([fetched.catch(_ => cached), cached]) + .then(resp => resp || fetched) + .catch(_ => { /* eat any errors */ }) + ) + + // Update the cache with the version we fetched (only for ok status) + event.waitUntil( + Promise.all([fetchedCopy, caches.open(RUNTIME)]) + .then(([response, cache]) => response.ok && cache.put(event.request, response)) + .catch(_ => { /* eat any errors */ }) + ) + } +}) From d11f19feeadb867a3de68b5099fdfc7b3ad08a06 Mon Sep 17 00:00:00 2001 From: Elliot Hesp Date: Tue, 2 May 2017 09:56:54 +0100 Subject: [PATCH 20/39] Add more docs syntax highlighting --- docs/index.html | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/docs/index.html b/docs/index.html index be66ecd5..8cbe0a0a 100644 --- a/docs/index.html +++ b/docs/index.html @@ -36,6 +36,11 @@ ] } + @@ -43,4 +48,7 @@ + + + From ef783f0d9f0788bc8ae1e7f3774f00522459c951 Mon Sep 17 00:00:00 2001 From: Salakar Date: Tue, 2 May 2017 10:39:23 +0100 Subject: [PATCH 21/39] [js] crash and auth now use internal staticsOrInstance helper. --- lib/firebase.js | 18 ++++----------- tests/ios/Podfile.lock | 50 +++++++++++++++++++++--------------------- 2 files changed, 29 insertions(+), 39 deletions(-) diff --git a/lib/firebase.js b/lib/firebase.js index b1863487..4abfc79d 100644 --- a/lib/firebase.js +++ b/lib/firebase.js @@ -35,8 +35,10 @@ export default class Firebase { _crash: ?Object; auth: Function; + crash: Function; storage: Function; database: Function; + analytics: Function; messaging: Function; eventHandlers: Object; @@ -79,6 +81,8 @@ export default class Firebase { this.storage = this._staticsOrInstance('storage', StorageStatics, Storage); this.database = this._staticsOrInstance('database', DatabaseStatics, Database); this.messaging = this._staticsOrInstance('messaging', MessagingStatics, Messaging); + this.analytics = this._staticsOrInstance('analytics', {}, Analytics); + this.crash = this._staticsOrInstance('crash', {}, Crash); // init auth to start listeners this.auth(); @@ -107,20 +111,6 @@ export default class Firebase { return instances[name]; } - analytics() { - if (!this._analytics) { - this._analytics = new Analytics(this); - } - return this._analytics; - } - - crash() { - if (!this._crash) { - this._crash = new Crash(this); - } - return this._crash; - } - get apps(): Array { return Object.keys(instances); } diff --git a/tests/ios/Podfile.lock b/tests/ios/Podfile.lock index 28cc8d2e..bad383fd 100644 --- a/tests/ios/Podfile.lock +++ b/tests/ios/Podfile.lock @@ -1,31 +1,31 @@ PODS: - - Firebase/Analytics (3.15.0): + - Firebase/Analytics (3.14.0): - Firebase/Core - - Firebase/AppIndexing (3.15.0): + - Firebase/AppIndexing (3.14.0): - Firebase/Core - FirebaseAppIndexing (= 1.2.0) - - Firebase/Auth (3.15.0): + - Firebase/Auth (3.14.0): - Firebase/Core - FirebaseAuth (= 3.1.1) - - Firebase/Core (3.15.0): + - Firebase/Core (3.14.0): - FirebaseAnalytics (= 3.7.0) - - FirebaseCore (= 3.5.2) - - Firebase/Crash (3.15.0): + - FirebaseCore (= 3.5.1) + - Firebase/Crash (3.14.0): - Firebase/Core - FirebaseCrash (= 1.1.6) - - Firebase/Database (3.15.0): + - Firebase/Database (3.14.0): - Firebase/Core - FirebaseDatabase (= 3.1.2) - - Firebase/DynamicLinks (3.15.0): + - Firebase/DynamicLinks (3.14.0): - Firebase/Core - - FirebaseDynamicLinks (= 1.3.4) - - Firebase/Messaging (3.15.0): + - FirebaseDynamicLinks (= 1.3.3) + - Firebase/Messaging (3.14.0): - Firebase/Core - FirebaseMessaging (= 1.2.2) - - Firebase/RemoteConfig (3.15.0): + - Firebase/RemoteConfig (3.14.0): - Firebase/Core - FirebaseRemoteConfig (= 1.3.4) - - Firebase/Storage (3.15.0): + - Firebase/Storage (3.14.0): - Firebase/Core - FirebaseStorage (= 1.1.0) - FirebaseAnalytics (3.7.0): @@ -37,7 +37,7 @@ PODS: - FirebaseAnalytics (~> 3.7) - GoogleToolboxForMac/NSDictionary+URLArguments (~> 2.1) - GTMSessionFetcher/Core (~> 1.1) - - FirebaseCore (3.5.2): + - FirebaseCore (3.5.1): - GoogleToolboxForMac/NSData+zlib (~> 2.1) - FirebaseCrash (1.1.6): - FirebaseAnalytics (~> 3.7) @@ -47,7 +47,7 @@ PODS: - Protobuf (~> 3.1) - FirebaseDatabase (3.1.2): - FirebaseAnalytics (~> 3.7) - - FirebaseDynamicLinks (1.3.4): + - FirebaseDynamicLinks (1.3.3): - FirebaseAnalytics (~> 3.7) - FirebaseInstanceID (1.0.9) - FirebaseMessaging (1.2.2): @@ -75,7 +75,7 @@ PODS: - GoogleToolboxForMac/Defines (= 2.1.1) - GoogleToolboxForMac/NSString+URLArguments (= 2.1.1) - GoogleToolboxForMac/NSString+URLArguments (2.1.1) - - GTMSessionFetcher/Core (1.1.9) + - GTMSessionFetcher/Core (1.1.8) - Protobuf (3.2.0) - React (0.40.0): - React/Core (= 0.40.0) @@ -112,7 +112,7 @@ PODS: - React/RCTWebSocket (0.40.0): - React/Core - React/yoga (0.40.0) - - RNFirebase (1.0.0-alpha12): + - RNFirebase (1.0.0-alpha13): - Firebase/Auth - Firebase/Core - Firebase/Database @@ -145,33 +145,33 @@ DEPENDENCIES: - React/RCTText (from `../node_modules/react-native`) - React/RCTVibration (from `../node_modules/react-native`) - React/RCTWebSocket (from `../node_modules/react-native`) - - RNFirebase (from `../node_modules/react-native-firebase`) + - RNFirebase (from `./../../`) EXTERNAL SOURCES: React: - :path: "../node_modules/react-native" + :path: ../node_modules/react-native RNFirebase: - :path: "../node_modules/react-native-firebase" + :path: ./../../ SPEC CHECKSUMS: - Firebase: 2b1cdfba1cda8589f32904a697cc753322bff9d8 + Firebase: 85a581fb04e44f63ae9f4fbc8d6dabf4a4c18653 FirebaseAnalytics: 0d1b7d81d5021155be37702a94ba1ec16d45365d FirebaseAppIndexing: d0fa52ce0ad13f4b5b2f09e4b47fb0dc2213f4e9 FirebaseAuth: cc8a1824170adbd351edb7f994490a3fb5c18be6 - FirebaseCore: a024587e43778508700af8c6b1209f7c4516ba02 + FirebaseCore: 225d40532489835a034b8f4e2c9c87fbf4f615a2 FirebaseCrash: db4c05d9c75baa050744d31b36357c8f1efba481 FirebaseDatabase: 05c96d7b43a7368dc91c07791adb49683e1738d1 - FirebaseDynamicLinks: 30fb0856dd9ae6d8ba4da00972141a5c293a27b2 + FirebaseDynamicLinks: f0d025dd29a1d70418c003344813b67ab748ffb9 FirebaseInstanceID: 2d0518b1378fe9d685ef40cbdd63d2fdc1125339 FirebaseMessaging: df8267f378580a24174ce7861233aa11d5c90109 FirebaseRemoteConfig: af3003f4e8daa2bd1d5cf90d3cccc1fe224f8ed9 FirebaseStorage: a5c55b23741a49a72af8f30f95b3bb5ddbeda12d GoogleToolboxForMac: 8e329f1b599f2512c6b10676d45736bcc2cbbeb0 - GTMSessionFetcher: 5c046c76a1f859bc9c187e918f18e4fc7bb57b5e + GTMSessionFetcher: 6f8d8b28b7e345549ac471071608170b31cb4977 Protobuf: 745f59e122e5de98d4d7ef291e264a0eef80f58e React: 6dfb2f72edb1d74a800127ae157af038646673ce - RNFirebase: 228c16667a3ed1ba3b9ff0702449dca3be1c3618 + RNFirebase: 2e27a1e4530653630913ebdfb49de5ef8858e3b4 -PODFILE CHECKSUM: 23445e2727726988c7338fa2f396980d6fd3906f +PODFILE CHECKSUM: f8bc5de55afd159ec2faf523f1b8e0d861d0832b COCOAPODS: 1.2.0 From 8fe6ffee8ce5fd92574672692f0f1a976fc9cf9a Mon Sep 17 00:00:00 2001 From: Salakar Date: Tue, 2 May 2017 10:42:24 +0100 Subject: [PATCH 22/39] [ios] added RNFirebase to podfile template --- ios/Podfile.template | 1 + 1 file changed, 1 insertion(+) diff --git a/ios/Podfile.template b/ios/Podfile.template index 9e4bbc45..1dd4a8ee 100644 --- a/ios/Podfile.template +++ b/ios/Podfile.template @@ -8,3 +8,4 @@ pod 'Firebase/DynamicLinks' pod 'Firebase/Messaging' pod 'Firebase/RemoteConfig' pod 'Firebase/Storage' +pod 'RNFirebase', :path => '../node_modules/react-native-firebase' From 618b34cd4f6ab8ce101fbc5630310a12c5f7ebda Mon Sep 17 00:00:00 2001 From: Salakar Date: Tue, 2 May 2017 10:54:18 +0100 Subject: [PATCH 23/39] [ios] update pod spec & template --- RNFirebase.podspec | 9 +----- ios/Podfile | 71 ------------------------------------------ tests/ios/Podfile.lock | 13 ++------ 3 files changed, 3 insertions(+), 90 deletions(-) delete mode 100644 ios/Podfile diff --git a/RNFirebase.podspec b/RNFirebase.podspec index 331fb005..b509a3f4 100644 --- a/RNFirebase.podspec +++ b/RNFirebase.podspec @@ -6,7 +6,7 @@ Pod::Spec.new do |s| s.version = package["version"] s.summary = package["description"] s.description = <<-DESC - Wanna integrate firebase into your app using React Native? + Integrate firebase into your app using the React Native SDKs. DESC s.homepage = "http://invertase.io" s.license = package['license'] @@ -16,11 +16,4 @@ Pod::Spec.new do |s| s.platform = :ios, "8.0" s.preserve_paths = 'README.md', 'package.json', '*.js' s.source_files = 'ios/RNFirebase/*.{h,m}' - s.dependency 'React' - s.dependency 'Firebase/Auth' - s.dependency 'Firebase/Core' - s.dependency 'Firebase/Database' - s.dependency 'Firebase/Messaging' - s.dependency 'Firebase/RemoteConfig' - s.dependency 'Firebase/Storage' end diff --git a/ios/Podfile b/ios/Podfile deleted file mode 100644 index 990b86df..00000000 --- a/ios/Podfile +++ /dev/null @@ -1,71 +0,0 @@ -source 'https://github.com/CocoaPods/Specs.git' -use_frameworks! -platform :ios, '8.0' - -def common_pods - # pod 'RNFirebase', :path => '../' - # pod 'React', :path => '../node_modules/react-native' - [ - 'Firebase', - 'Firebase/Core', - 'Firebase/Auth', - 'Firebase/Storage', - 'Firebase/Database', - 'Firebase/RemoteConfig', - 'Firebase/Messaging' - ].each do |lib| - pod lib - end -end - -def test_pods - pod 'Quick', '~> 0.8.0' - pod 'Nimble', '~> 3.0.0' -end - -def setup - post_install do |installer| - installer.pods_project.targets.each do |target| - target.build_configurations.each do |configuration| - # configuration.build_settings['EXPANDED_CODE_SIGN_IDENTITY'] = "" - # configuration.build_settings['CODE_SIGNING_REQUIRED'] = "YES" - # configuration.build_settings['CODE_SIGNING_ALLOWED'] = "YES" - - target.build_settings(configuration.name)['OTHER_LDFLAGS'] = '$(inherited)' - target.build_settings(configuration.name)['USER_HEADER_SEARCH_PATHS'] = "$(BUILT_PRODUCTS_DIR)" - target.build_settings(configuration.name)['LD_DYLIB_INSTALL_NAME'] = '@rpath/${EXECUTABLE_NAME}' - target.build_settings(configuration.name)['LD_RUNPATH_SEARCH_PATHS'] = '$(inherited) @rpath @loader_path/../Frameworks @executable_path/Frameworks' - - target.build_settings(configuration.name)['ONLY_ACTIVE_ARCH'] = 'NO' - target.build_settings(configuration.name)['HEADER_SEARCH_PATHS'] = [ - "$(inherited)", - "${PODS_ROOT}/Headers/**", - "$(SRCROOT)/../../React/**", - "$(SRCROOT)/../../react-native/React/**", - '$(RN_ROOT)/React/**', - '$(PODS_ROOT)/Headers' - ].join(' ') - target.build_settings(configuration.name)['FRAMEWORK_SEARCH_PATHS'] = [ - "$(inherited)", - '$(PODS_ROOT)/**', - '$(PODS_CONFIGURATION_BUILD_DIR)/**' - ].join(' ') - target.build_settings(configuration.name)['OTHER_LDFLAGS'] = "$(inherited)" - end - end - end -end - -# target 'RNFirebase' do -# common_pods -# project "RNFirebase.xcodeproj" -# setup -# end - -target 'RNFirebaseTests' do - use_frameworks! - common_pods - test_pods - pod 'React', :path => '../node_modules/react-native' - setup -end diff --git a/tests/ios/Podfile.lock b/tests/ios/Podfile.lock index bad383fd..c3bb0e75 100644 --- a/tests/ios/Podfile.lock +++ b/tests/ios/Podfile.lock @@ -77,8 +77,6 @@ PODS: - GoogleToolboxForMac/NSString+URLArguments (2.1.1) - GTMSessionFetcher/Core (1.1.8) - Protobuf (3.2.0) - - React (0.40.0): - - React/Core (= 0.40.0) - React/Core (0.40.0): - React/cxxreact - React/yoga @@ -112,14 +110,7 @@ PODS: - React/RCTWebSocket (0.40.0): - React/Core - React/yoga (0.40.0) - - RNFirebase (1.0.0-alpha13): - - Firebase/Auth - - Firebase/Core - - Firebase/Database - - Firebase/Messaging - - Firebase/RemoteConfig - - Firebase/Storage - - React + - RNFirebase (1.0.0-alpha13) DEPENDENCIES: - Firebase/Analytics @@ -170,7 +161,7 @@ SPEC CHECKSUMS: GTMSessionFetcher: 6f8d8b28b7e345549ac471071608170b31cb4977 Protobuf: 745f59e122e5de98d4d7ef291e264a0eef80f58e React: 6dfb2f72edb1d74a800127ae157af038646673ce - RNFirebase: 2e27a1e4530653630913ebdfb49de5ef8858e3b4 + RNFirebase: 46bfe1099349ac6fac8c5e57cf4f0b0f4b7938ac PODFILE CHECKSUM: f8bc5de55afd159ec2faf523f1b8e0d861d0832b From 9adeffef1844bd85cccf35e38f0fec9bd6956163 Mon Sep 17 00:00:00 2001 From: Michael Diarmid Date: Tue, 2 May 2017 10:56:33 +0100 Subject: [PATCH 24/39] Update installation-ios.md --- docs/installation-ios.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/installation-ios.md b/docs/installation-ios.md index c0512439..7159086e 100644 --- a/docs/installation-ios.md +++ b/docs/installation-ios.md @@ -132,7 +132,7 @@ Add the following to the `didFinishLaunchingWithOptions:(NSDictionary *)launchOp Add the following methods: -``` +```objectivec - (void)userNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(UNNotificationPresentationOptions))completionHandler From 7c9b094f549c2591ed75931b751b0a20e0558876 Mon Sep 17 00:00:00 2001 From: Chris Bianca Date: Tue, 2 May 2017 13:56:50 +0100 Subject: [PATCH 25/39] [android][database] Fix startAt and endAt --- .../database/RNFirebaseDatabaseReference.java | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/android/src/main/java/io/invertase/firebase/database/RNFirebaseDatabaseReference.java b/android/src/main/java/io/invertase/firebase/database/RNFirebaseDatabaseReference.java index 4eaa48a0..39cd3a22 100644 --- a/android/src/main/java/io/invertase/firebase/database/RNFirebaseDatabaseReference.java +++ b/android/src/main/java/io/invertase/firebase/database/RNFirebaseDatabaseReference.java @@ -249,46 +249,46 @@ public class RNFirebaseDatabaseReference { if ("number".equals(valueType)) { double value = (Double) modifier.get("value"); if (key == null) { - query = query.equalTo(value); + query = query.endAt(value); } else { - query = query.equalTo(value, key); + query = query.endAt(value, key); } } else if ("boolean".equals(valueType)) { boolean value = (Boolean) modifier.get("value"); if (key == null) { - query = query.equalTo(value); + query = query.endAt(value); } else { - query = query.equalTo(value, key); + query = query.endAt(value, key); } } else if ("string".equals(valueType)) { String value = (String) modifier.get("value"); if (key == null) { - query = query.equalTo(value); + query = query.endAt(value); } else { - query = query.equalTo(value, key); + query = query.endAt(value, key); } } } else if ("startAt".equals(name)) { if ("number".equals(valueType)) { double value = (Double) modifier.get("value"); if (key == null) { - query = query.equalTo(value); + query = query.startAt(value); } else { - query = query.equalTo(value, key); + query = query.startAt(value, key); } } else if ("boolean".equals(valueType)) { boolean value = (Boolean) modifier.get("value"); if (key == null) { - query = query.equalTo(value); + query = query.startAt(value); } else { - query = query.equalTo(value, key); + query = query.startAt(value, key); } } else if ("string".equals(valueType)) { String value = (String) modifier.get("value"); if (key == null) { - query = query.equalTo(value); + query = query.startAt(value); } else { - query = query.equalTo(value, key); + query = query.startAt(value, key); } } } From e3e2c9e09061300d0ddb4ec016c5568ccc7120f2 Mon Sep 17 00:00:00 2001 From: Chris Bianca Date: Tue, 2 May 2017 14:37:48 +0100 Subject: [PATCH 26/39] 1.0.0-alpha14 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 1a0da641..3fe0a8b9 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "react-native-firebase", - "version": "1.0.0-alpha13", + "version": "1.0.0-alpha14", "author": "Invertase (http://invertase.io)", "description": "A react native firebase library supporting both android and ios native firebase SDK's", "main": "index", From f6c8e9cf563558f7218a80f332ca34b6087a1f2e Mon Sep 17 00:00:00 2001 From: Salakar Date: Tue, 2 May 2017 16:19:41 +0100 Subject: [PATCH 27/39] 1.0.1 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 3fe0a8b9..439ff35a 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "react-native-firebase", - "version": "1.0.0-alpha14", + "version": "1.0.1", "author": "Invertase (http://invertase.io)", "description": "A react native firebase library supporting both android and ios native firebase SDK's", "main": "index", From 70dfbc9222867d2c37532f3d4a5e2991d8db2581 Mon Sep 17 00:00:00 2001 From: chrisbianca Date: Wed, 3 May 2017 08:40:15 +0100 Subject: [PATCH 28/39] Update iOS install docs to make options clearer --- docs/installation-ios.md | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/docs/installation-ios.md b/docs/installation-ios.md index 7159086e..f9c17de5 100644 --- a/docs/installation-ios.md +++ b/docs/installation-ios.md @@ -13,9 +13,10 @@ and this to the `didFinishLaunchingWithOptions:(NSDictionary *)launchOptions` me `[FIRApp configure];` ## 2) Link RNFirebase + There are multiple ways to install RNFirebase depending on how your project is currently setup: -### 2.1) Existing Cocoapods setup, including React Native as a pod +### 2.1) You already use Cocoapods and have React Native installed as a pod Simply add the following to your `Podfile`: ```ruby @@ -33,26 +34,27 @@ pod 'Firebase/Storage' pod 'RNFirebase', :path => '../node_modules/react-native-firebase' ``` -### 2.2) Via react-native-cli link +### 2.2) You're not using Cocoapods or don't have React Native installed as a pod (Automatic install) + React native ships with a `link` command that can be used to link the projects together, which can help automate the process of linking our package environments. ```bash react-native link react-native-firebase ``` +#### cocoapods + +We've automated the process of setting up with cocoapods. This will happen automatically upon linking the package with `react-native-cli`. + Update the newly installed pods once the linking is done: ```bash cd ios && pod update --verbose ``` -### cocoapods +**NOTE: You need to use the `ios/[YOUR APP NAME].xcworkspace` instead of the `ios/[YOUR APP NAME].xcproj` file from now on.** -We've automated the process of setting up with cocoapods. This will happen automatically upon linking the package with `react-native-cli`. - -> Remember to use the `ios/[YOUR APP NAME].xcworkspace` instead of the `ios/[YOUR APP NAME].xcproj` file from now on. - -### 2.3) Manually +### 2.3) You're not using Cocoapods or don't have React Native installed as a pod (Manual install) If you prefer not to use `react-native link`, we can manually link the package together with the following steps, after `npm install`: @@ -91,7 +93,9 @@ pod 'Firebase/RemoteConfig' pod 'Firebase/Storage' ``` -Then you can run `(cd ios && pod install)` to get the pods opened. If you do use this route, remember to use the `.xcworkspace` file. +Then you can run `(cd ios && pod install)` to get the pods opened. + +**NOTE: You need to use the `ios/[YOUR APP NAME].xcworkspace` instead of the `ios/[YOUR APP NAME].xcproj` file from now on.** ## 3) Cloud Messaging (optional) From b4622006bfe99f69125540b73ae81ae0e570956e Mon Sep 17 00:00:00 2001 From: Elliot Hesp Date: Wed, 3 May 2017 09:25:29 +0100 Subject: [PATCH 29/39] [android] Fix database limit type conversion --- .../firebase/database/RNFirebaseDatabaseReference.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/android/src/main/java/io/invertase/firebase/database/RNFirebaseDatabaseReference.java b/android/src/main/java/io/invertase/firebase/database/RNFirebaseDatabaseReference.java index 39cd3a22..45ce7504 100644 --- a/android/src/main/java/io/invertase/firebase/database/RNFirebaseDatabaseReference.java +++ b/android/src/main/java/io/invertase/firebase/database/RNFirebaseDatabaseReference.java @@ -213,7 +213,7 @@ public class RNFirebaseDatabaseReference { query = query.orderByChild(key); } } else if ("limit".equals(type)) { - int limit = (Integer) modifier.get("limit"); + int limit = ((Double)modifier.get("limit")).intValue(); if ("limitToLast".equals(name)) { query = query.limitToLast(limit); } else if ("limitToFirst".equals(name)) { From eb4410c90a04861b26535c6fa22f43bad5c5a3c0 Mon Sep 17 00:00:00 2001 From: Michael Diarmid Date: Wed, 3 May 2017 15:34:50 +0100 Subject: [PATCH 30/39] Update firebase-setup.md --- docs/firebase-setup.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/firebase-setup.md b/docs/firebase-setup.md index 6a054fea..d28b493b 100644 --- a/docs/firebase-setup.md +++ b/docs/firebase-setup.md @@ -4,7 +4,7 @@ The RNFirebase library is intended on making it easy to work with [Firebase](htt To add Firebase to your project, make sure to create a project in the [Firebase console](https://firebase.google.com/console) -![Create a new project](http://d.pr/i/17cJ2.png) +![Create a new project](https://i.imgur.com/KbbamwD.png) Each platform uses a different setup method after creating the project. From 670dfa2807ca271eb35566ec6c816073bf7be630 Mon Sep 17 00:00:00 2001 From: Michael Diarmid Date: Wed, 3 May 2017 16:02:21 +0100 Subject: [PATCH 31/39] Update transactions.md --- docs/modules/transactions.md | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/docs/modules/transactions.md b/docs/modules/transactions.md index 4df2f508..ee273c2d 100644 --- a/docs/modules/transactions.md +++ b/docs/modules/transactions.md @@ -1,6 +1,21 @@ # Transactions -> Transactions are currently an experimental feature as they can not be integrated as easily as the other Firebase features. Please see the [Firebase documentation](https://firebase.google.com/docs/reference/js/firebase.database.Reference#transaction) for full implemtation details. +!> Transactions is currently an experimental feature in RNFirebase. Whilst it does work there may still be some issues with it, especially around offline connectivity handling. Please report any issues in the usual manner. + + +?> For help on how to use firebase transactions please see the [Firebase Transaction Documentation](https://firebase.google.com/docs/reference/js/firebase.database.Reference#transaction). + +### Android Implementation + +The [android implementation](https://github.com/invertase/react-native-firebase/blob/master/android/src/main/java/io/invertase/firebase/database/RNFirebaseTransactionHandler.java) makes use of [Condition](https://docs.oracle.com/javase/7/docs/api/java/util/concurrent/locks/Condition.html) and [ReentrantLock](https://docs.oracle.com/javase/7/docs/api/java/util/concurrent/locks/ReentrantLock.html) locks to handle transactions across the React Native Bridge. + + +### iOS Implementation + +The [iOS implementation](https://github.com/invertase/react-native-firebase/blob/master/ios/RNFirebase/RNFirebaseDatabase.m#L279) makes use of GCD (Grand Central Dispatch) to handle transactions across the React Native Bridge without blocking the application thread. Check out [this](https://mikeash.com/pyblog/friday-qa-2011-10-14-whats-new-in-gcd.html) post for some 'light' reading about it. + +!> Transactions that receive no response from react native's JS thread within 30 seconds are automatically aborted - this value is currently not configurable - PR welcome. + ## Example From 1666bc1496718cffddf1914c562e7f58f75b3720 Mon Sep 17 00:00:00 2001 From: Aleck Greenham Date: Thu, 4 May 2017 18:49:47 +0100 Subject: [PATCH 32/39] [TestSuite] Upgrade test app navigation Fix invertase/react-native-firebase#83 --- tests/package.json | 2 +- tests/src/screens/Overview.js | 16 +++++----------- tests/src/screens/Suite.js | 32 +++++++++++++------------------- tests/src/screens/Test.js | 24 +++++++++--------------- 4 files changed, 28 insertions(+), 46 deletions(-) diff --git a/tests/package.json b/tests/package.json index 9c38a381..8cbba693 100644 --- a/tests/package.json +++ b/tests/package.json @@ -37,7 +37,7 @@ "react-native-firebase": "file:..", "react-native-simple-toast": "0.0.5", "react-native-vector-icons": "^4.0.0", - "react-navigation": "^1.0.0-beta.7", + "react-navigation": "^1.0.0-beta.9", "react-redux": "^5.0.3", "redux": "^3.6.0", "redux-logger": "^2.8.2", diff --git a/tests/src/screens/Overview.js b/tests/src/screens/Overview.js index e52b2a94..4ce6a944 100644 --- a/tests/src/screens/Overview.js +++ b/tests/src/screens/Overview.js @@ -13,17 +13,11 @@ class Overview extends React.Component { // noinspection JSUnusedGlobalSymbols static navigationOptions = { title: 'Test Suites', - header: () => { - return { - style: { backgroundColor: '#0288d1' }, - tintColor: '#ffffff', - right: ( - - - - ), - }; - }, + headerTintColor: '#ffffff', + headerStyle: { backgroundColor: '#0288d1' }, + headerRight: + + }; /** diff --git a/tests/src/screens/Suite.js b/tests/src/screens/Suite.js index 884727df..1758a1eb 100644 --- a/tests/src/screens/Suite.js +++ b/tests/src/screens/Suite.js @@ -11,25 +11,19 @@ import TestSuiteControlButton from '../components/TestSuiteControlButton'; class Suite extends React.Component { - static navigationOptions = { - title: ({ state: { params: { title } } }) => { - return title; - }, - header: ({ state: { params: { testSuiteId, onlyShowFailingTests } }, setParams }) => { - return { - style: { backgroundColor: '#0288d1' }, - tintColor: '#ffffff', - right: ( - - - - ), - }; - }, + static navigationOptions = ({ navigation: { state: { params: { title, testSuiteId, onlyShowFailingTests } }, setParams } }) => { + return { + title, + headerTintColor: '#ffffff', + headerStyle: { backgroundColor: '#0288d1' }, + headerRight: + + , + }; }; /** diff --git a/tests/src/screens/Test.js b/tests/src/screens/Test.js index a8e0e233..e716ece1 100644 --- a/tests/src/screens/Test.js +++ b/tests/src/screens/Test.js @@ -9,21 +9,15 @@ import TestControlButton from '../components/TestControlButton'; class Test extends React.Component { - static navigationOptions = { - title: ({ state: { params: { title } } }) => { - return title; - }, - header: ({ state: { params: { testId } } }) => { - return { - style: { backgroundColor: '#0288d1' }, - tintColor: '#ffffff', - right: ( - - - - ), - }; - }, + static navigationOptions = ({ navigation: { state: { params: { title, testId } } } }) => { + return { + title, + headerTintColor: '#ffffff', + headerStyle: { backgroundColor: '#0288d1' }, + headerRight: + + , + }; }; static renderBanner({ status, time }) { From 67bc409e9b518cbfd834e52a84d4785b204de6f8 Mon Sep 17 00:00:00 2001 From: Aleck Greenham Date: Thu, 4 May 2017 18:53:54 +0100 Subject: [PATCH 33/39] [TestSuite] Upgrade gradle version and increase daemon memory allocation --- tests/android/build.gradle | 2 +- tests/android/gradle.properties | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/android/build.gradle b/tests/android/build.gradle index 41f6c1d8..48e679ff 100644 --- a/tests/android/build.gradle +++ b/tests/android/build.gradle @@ -5,7 +5,7 @@ buildscript { jcenter() } dependencies { - classpath 'com.android.tools.build:gradle:2.3.0' + classpath 'com.android.tools.build:gradle:2.3.1' classpath 'com.google.gms:google-services:3.0.0' // NOTE: Do not place your application dependencies here; they belong diff --git a/tests/android/gradle.properties b/tests/android/gradle.properties index 1fd964e9..16374225 100644 --- a/tests/android/gradle.properties +++ b/tests/android/gradle.properties @@ -18,3 +18,4 @@ # org.gradle.parallel=true android.useDeprecatedNdk=true +org.gradle.jvmargs=-Xmx1536M From da556ae8c9376545161695c4d67e3c34a4edbfaf Mon Sep 17 00:00:00 2001 From: Salakar Date: Fri, 5 May 2017 09:46:22 +0100 Subject: [PATCH 34/39] [ios] add backwards compatibility to RN imports - fixed #80 --- ios/RNFirebase/RNFirebase.h | 14 +++++++++- ios/RNFirebase/RNFirebaseAnalytics.h | 4 +++ ios/RNFirebase/RNFirebaseAuth.h | 8 ++++++ ios/RNFirebase/RNFirebaseCrash.h | 4 +++ ios/RNFirebase/RNFirebaseDatabase.h | 8 ++++++ ios/RNFirebase/RNFirebaseErrors.h | 4 +++ ios/RNFirebase/RNFirebaseMessaging.h | 13 +++++++++ ios/RNFirebase/RNFirebaseMessaging.m | 42 ++++++++++++++++++---------- ios/RNFirebase/RNFirebaseStorage.h | 10 ++++++- 9 files changed, 90 insertions(+), 17 deletions(-) diff --git a/ios/RNFirebase/RNFirebase.h b/ios/RNFirebase/RNFirebase.h index 68550631..1e6ae035 100644 --- a/ios/RNFirebase/RNFirebase.h +++ b/ios/RNFirebase/RNFirebase.h @@ -2,9 +2,21 @@ #define RNFirebase_h #import -#import "RCTBridgeModule.h" +#if __has_include() +#import +#else // Compatibility for RN version < 0.40 #import "RCTEventDispatcher.h" +#endif +#if __has_include() +#import +#else // Compatibility for RN version < 0.40 #import "RCTEventEmitter.h" +#endif +#if __has_include() +#import +#else // Compatibility for RN version < 0.40 +#import "RCTBridgeModule.h" +#endif @interface RNFirebase : RCTEventEmitter { } diff --git a/ios/RNFirebase/RNFirebaseAnalytics.h b/ios/RNFirebase/RNFirebaseAnalytics.h index b0a5bcb6..603dbafa 100644 --- a/ios/RNFirebase/RNFirebaseAnalytics.h +++ b/ios/RNFirebase/RNFirebaseAnalytics.h @@ -1,7 +1,11 @@ #ifndef RNFirebaseAnalytics_h #define RNFirebaseAnalytics_h +#if __has_include() +#import +#else // Compatibility for RN version < 0.40 #import "RCTBridgeModule.h" +#endif @interface RNFirebaseAnalytics : NSObject { diff --git a/ios/RNFirebase/RNFirebaseAuth.h b/ios/RNFirebase/RNFirebaseAuth.h index b79ec552..5ea32dba 100644 --- a/ios/RNFirebase/RNFirebaseAuth.h +++ b/ios/RNFirebase/RNFirebaseAuth.h @@ -2,8 +2,16 @@ #define RNFirebaseAuth_h #import "Firebase.h" +#if __has_include() +#import +#else // Compatibility for RN version < 0.40 #import "RCTEventEmitter.h" +#endif +#if __has_include() +#import +#else // Compatibility for RN version < 0.40 #import "RCTBridgeModule.h" +#endif @interface RNFirebaseAuth : RCTEventEmitter { FIRAuthStateDidChangeListenerHandle authListenerHandle; diff --git a/ios/RNFirebase/RNFirebaseCrash.h b/ios/RNFirebase/RNFirebaseCrash.h index ed987c1c..a92e5501 100644 --- a/ios/RNFirebase/RNFirebaseCrash.h +++ b/ios/RNFirebase/RNFirebaseCrash.h @@ -1,7 +1,11 @@ #ifndef RNFirebaseCrash_h #define RNFirebaseCrash_h +#if __has_include() +#import +#else // Compatibility for RN version < 0.40 #import "RCTBridgeModule.h" +#endif @interface RNFirebaseCrash : NSObject { diff --git a/ios/RNFirebase/RNFirebaseDatabase.h b/ios/RNFirebase/RNFirebaseDatabase.h index a2d81525..d0f66302 100644 --- a/ios/RNFirebase/RNFirebaseDatabase.h +++ b/ios/RNFirebase/RNFirebaseDatabase.h @@ -2,8 +2,16 @@ #define RNFirebaseDatabase_h #import "Firebase.h" +#if __has_include() +#import +#else // Compatibility for RN version < 0.40 #import "RCTEventEmitter.h" +#endif +#if __has_include() +#import +#else // Compatibility for RN version < 0.40 #import "RCTBridgeModule.h" +#endif @interface RNFirebaseDatabase : RCTEventEmitter { diff --git a/ios/RNFirebase/RNFirebaseErrors.h b/ios/RNFirebase/RNFirebaseErrors.h index 0bed4c2f..bf61e8ea 100644 --- a/ios/RNFirebase/RNFirebaseErrors.h +++ b/ios/RNFirebase/RNFirebaseErrors.h @@ -1,7 +1,11 @@ #ifndef RNFirebaseErrors_h #define RNFirebaseErrors_h +#if __has_include() +#import +#else // Compatibility for RN version < 0.40 #import "RCTBridgeModule.h" +#endif #import "Firebase.h" @interface RNFirebaseErrors : NSObject { diff --git a/ios/RNFirebase/RNFirebaseMessaging.h b/ios/RNFirebase/RNFirebaseMessaging.h index 0e1bec73..96672cc4 100644 --- a/ios/RNFirebase/RNFirebaseMessaging.h +++ b/ios/RNFirebase/RNFirebaseMessaging.h @@ -5,9 +5,22 @@ #import #import "Firebase.h" + +#if __has_include() +#import +#else // Compatibility for RN version < 0.40 #import "RCTEventEmitter.h" +#endif +#if __has_include() +#import +#else // Compatibility for RN version < 0.40 #import "RCTBridgeModule.h" +#endif +#if __has_include() +#import +#else // Compatibility for RN version < 0.40 #import "RCTUtils.h" +#endif @import UserNotifications; diff --git a/ios/RNFirebase/RNFirebaseMessaging.m b/ios/RNFirebase/RNFirebaseMessaging.m index c86855ee..f027cfb0 100644 --- a/ios/RNFirebase/RNFirebaseMessaging.m +++ b/ios/RNFirebase/RNFirebaseMessaging.m @@ -1,8 +1,20 @@ #import "RNFirebaseMessaging.h" -#import +#if __has_include() #import +#else // Compatibility for RN version < 0.40 +#import "RCTEventDispatcher.h" +#endif +#if __has_include() +#import +#else // Compatibility for RN version < 0.40 +#import "RCTConvert.h" +#endif +#if __has_include() #import +#else // Compatibility for RN version < 0.40 +#import "RCTUtils.h" +#endif @import UserNotifications; #import @@ -53,13 +65,13 @@ RCT_ENUM_CONVERTER(NSCalendarUnit, content.categoryIdentifier = [RCTConvert NSString:details[@"click_action"]]; content.userInfo = details; content.badge = [RCTConvert NSNumber:details[@"badge"]]; - + NSDate *fireDate = [RCTConvert NSDate:details[@"fire_date"]]; - + if(fireDate == nil){ return [UNNotificationRequest requestWithIdentifier:[RCTConvert NSString:details[@"id"]] content:content trigger:nil]; } - + NSCalendarUnit interval = [RCTConvert NSCalendarUnit:details[@"repeat_interval"]]; NSCalendarUnit unitFlags; switch (interval) { @@ -177,12 +189,12 @@ RCT_EXPORT_MODULE() - (void)setBridge:(RCTBridge *)bridge { _bridge = bridge; - + [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleNotificationReceived:) name:FCMNotificationReceived object:nil]; - + [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(disconnectFCM) name:UIApplicationDidEnterBackgroundNotification @@ -191,19 +203,19 @@ RCT_EXPORT_MODULE() selector:@selector(connectToFCM) name:UIApplicationDidBecomeActiveNotification object:nil]; - + [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onTokenRefresh) name:kFIRInstanceIDTokenRefreshNotification object:nil]; - + [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(sendDataMessageFailure:) name:FIRMessagingSendErrorNotification object:nil]; - + [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(sendDataMessageSuccess:) name:FIRMessagingSendSuccessNotification object:nil]; - + // For iOS 10 data message (sent via FCM) dispatch_async(dispatch_get_main_queue(), ^{ [[FIRMessaging messaging] setRemoteMessageDelegate:self]; @@ -283,7 +295,7 @@ RCT_EXPORT_METHOD(requestPermissions:(RCTPromiseResolveBlock)resolve rejecter:(R ]; #endif } - + [[UIApplication sharedApplication] registerForRemoteNotifications]; } @@ -459,22 +471,22 @@ RCT_EXPORT_METHOD(finishNotificationResponse: (NSString *)completionHandlerId){ self.notificationCallbacks[completionHandlerId] = completionHandler; data[@"_completionHandlerId"] = completionHandlerId; } - + [_bridge.eventDispatcher sendDeviceEventWithName:FCMNotificationReceived body:data]; - + } - (void)sendDataMessageFailure:(NSNotification *)notification { NSString *messageID = (NSString *)notification.userInfo[@"messageID"]; - + NSLog(@"sendDataMessageFailure: %@", messageID); } - (void)sendDataMessageSuccess:(NSNotification *)notification { NSString *messageID = (NSString *)notification.userInfo[@"messageID"]; - + NSLog(@"sendDataMessageSuccess: %@", messageID); } diff --git a/ios/RNFirebase/RNFirebaseStorage.h b/ios/RNFirebase/RNFirebaseStorage.h index bce4417c..9f388129 100644 --- a/ios/RNFirebase/RNFirebaseStorage.h +++ b/ios/RNFirebase/RNFirebaseStorage.h @@ -2,8 +2,16 @@ #define RNFirebaseStorage_h #import "Firebase.h" -#import "RCTBridgeModule.h" +#if __has_include() +#import +#else // Compatibility for RN version < 0.40 #import "RCTEventEmitter.h" +#endif +#if __has_include() +#import +#else // Compatibility for RN version < 0.40 +#import "RCTBridgeModule.h" +#endif @interface RNFirebaseStorage : RCTEventEmitter { From a8380843e242a8ec841edc8326ce583fa6e0edc6 Mon Sep 17 00:00:00 2001 From: Salakar Date: Fri, 5 May 2017 10:12:15 +0100 Subject: [PATCH 35/39] 1.0.2 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 439ff35a..f1d8b410 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "react-native-firebase", - "version": "1.0.1", + "version": "1.0.2", "author": "Invertase (http://invertase.io)", "description": "A react native firebase library supporting both android and ios native firebase SDK's", "main": "index", From 619661e8f7cc583d82551d936d66cf3397f07293 Mon Sep 17 00:00:00 2001 From: Aleck Greenham Date: Sat, 6 May 2017 09:57:18 +0100 Subject: [PATCH 36/39] =?UTF-8?q?[Test=20Suite]=20Don=E2=80=99t=20run=20fo?= =?UTF-8?q?cused=20pending=20tests?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/.gitignore | 1 + tests/__tests__/src/tests/pendingTestTests.js | 78 +++++++++++++++++++ tests/lib/TestSuite.js | 20 ++--- 3 files changed, 89 insertions(+), 10 deletions(-) create mode 100644 tests/.gitignore diff --git a/tests/.gitignore b/tests/.gitignore new file mode 100644 index 00000000..5afd82db --- /dev/null +++ b/tests/.gitignore @@ -0,0 +1 @@ +__tests__/build/ diff --git a/tests/__tests__/src/tests/pendingTestTests.js b/tests/__tests__/src/tests/pendingTestTests.js index e7c128a9..1dafed1c 100644 --- a/tests/__tests__/src/tests/pendingTestTests.js +++ b/tests/__tests__/src/tests/pendingTestTests.js @@ -103,6 +103,84 @@ function pendingTestTests({ it: _it, describe: _describe }) { otherTest.should.be.called(); }); }); + + _describe('when an outer context is focused', () => { + _it('a pending test will still not run', async () => { + const pendingTest = sinon.spy(); + const otherTest = sinon.spy(); + const unfocusedTest = sinon.spy(); + + const testSuite = new TestSuite('', '', {}); + + testSuite.addTests(({ fdescribe, it, xit }) => { + fdescribe('', () => { + xit('', pendingTest); + + it('', otherTest); + }); + + it('', unfocusedTest); + }); + + testSuite.setStore({ + getState: () => { return {}; }, + }); + + const testIdsToRun = Object.keys(testSuite.testDefinitions.focusedTestIds).reduce((memo, testId) => { + if (!testSuite.testDefinitions.pendingTestIds[testId]) { + memo.push(testId); + } + + return memo; + }, []); + + await testSuite.run(testIdsToRun); + + pendingTest.should.not.be.called(); + otherTest.should.be.called(); + unfocusedTest.should.not.be.called(); + }); + }); + + _describe('when an outer context is focused', () => { + _it('a pending context will still not run', async () => { + const pendingTest = sinon.spy(); + const otherTest = sinon.spy(); + const unfocusedTest = sinon.spy(); + + const testSuite = new TestSuite('', '', {}); + + testSuite.addTests(({ fdescribe, it, xdescribe }) => { + fdescribe('', () => { + xdescribe('', () => { + it('', pendingTest); + }); + + it('', otherTest); + }); + + it('', unfocusedTest); + }); + + testSuite.setStore({ + getState: () => { return {}; }, + }); + + const testIdsToRun = Object.keys(testSuite.testDefinitions.focusedTestIds).reduce((memo, testId) => { + if (!testSuite.testDefinitions.pendingTestIds[testId]) { + memo.push(testId); + } + + return memo; + }, []); + + await testSuite.run(testIdsToRun); + + pendingTest.should.not.be.called(); + otherTest.should.be.called(); + unfocusedTest.should.not.be.called(); + }); + }); } export default pendingTestTests; diff --git a/tests/lib/TestSuite.js b/tests/lib/TestSuite.js index 3924bb8b..aaa6735c 100644 --- a/tests/lib/TestSuite.js +++ b/tests/lib/TestSuite.js @@ -111,19 +111,19 @@ class TestSuite { */ async run(testIds = undefined) { const testsToRun = (() => { - if (testIds) { - return testIds.map((id) => { - const test = this.testDefinitions.tests[id]; + return (testIds || Object.keys(this.testDefinitions.tests)).reduce((memo, id) => { + const test = this.testDefinitions.tests[id]; - if (!test) { - throw new RangeError(`ReactNativeFirebaseTests.TestRunError: Test with id ${id} not found in test suite ${this.name}`); - } + if (!test) { + throw new RangeError(`ReactNativeFirebaseTests.TestRunError: Test with id ${id} not found in test suite ${this.name}`); + } - return test; - }); - } + if (!this.testDefinitions.pendingTestIds[id]) { + memo.push(test); + } - return Object.values(this.testDefinitions.tests); + return memo; + }, []); })(); const testRun = new TestRun(this, testsToRun.reverse(), this.testDefinitions); From 591cf735d645556ce3fbffac1ab50b82a72a5fff Mon Sep 17 00:00:00 2001 From: Aleck Greenham Date: Sat, 6 May 2017 11:49:44 +0100 Subject: [PATCH 37/39] [TestSuite] Show full test description on Test screen --- tests/src/screens/Test.js | 69 +++++++++++++++++++++------------------ 1 file changed, 38 insertions(+), 31 deletions(-) diff --git a/tests/src/screens/Test.js b/tests/src/screens/Test.js index e716ece1..5ba50f27 100644 --- a/tests/src/screens/Test.js +++ b/tests/src/screens/Test.js @@ -51,33 +51,25 @@ class Test extends React.Component { setParams({ test }); } - renderError() { - const { test: { message } } = this.props; - - if (message) { - return ( - - Test Error - - {message} - - - ); - } - - return null; - } - - render() { - const { test: { func, status, time } } = this.props; + const { test: { message, description, func, status, time }, testContextName } = this.props; return ( {Test.renderBanner({ status, time })} - - {this.renderError()} - Test Code Preview + + + {testContextName}:{description} + + + Test Error + + {message || 'None'} + + + + Test Code Preview + {beautify(removeLastLine(removeFirstLine(func.toString())), { indent_size: 4, break_chained_methods: true })} @@ -95,8 +87,11 @@ Test.propTypes = { time: PropTypes.number, message: PropTypes.string, func: PropTypes.function, + description: PropTypes.string, }).isRequired, + testContextName: PropTypes.string, + navigation: PropTypes.shape({ setParams: PropTypes.func.isRequired, }).isRequired, @@ -107,27 +102,39 @@ const styles = StyleSheet.create({ flex: 1, backgroundColor: '#ffffff', }, - content: {}, - code: { - backgroundColor: '#3F373A', - color: '#c3c3c3', - padding: 5, - fontSize: 12, - }, - codeHeader: { + header: { fontWeight: '600', fontSize: 18, backgroundColor: '#000', color: '#fff', padding: 5, }, + code: { + backgroundColor: '#3F373A', + color: '#c3c3c3', + padding: 5, + fontSize: 12, + }, + description: { + padding: 5, + fontSize: 14, + }, + testLabel: { + fontWeight: '600', + fontSize: 16 + } }); -function select({ tests }, { navigation: { state: { params: { testId } } } }) { +function select({ tests, testContexts }, { navigation: { state: { params: { testId } } } }) { const test = tests[testId]; + let testContext = testContexts[test.testContextId]; + while(testContext.parentContextId && testContexts[testContext.parentContextId].parentContextId) { + testContext = testContexts[testContext.parentContextId]; + } return { test, + testContextName: testContext.name, }; } From 6874c83efd1987035241b01a9de43cc8014b96a6 Mon Sep 17 00:00:00 2001 From: Aleck Greenham Date: Sat, 6 May 2017 12:47:31 +0100 Subject: [PATCH 38/39] [TestSuite] Clean up TestSuite code further --- tests/lib/TestRun.js | 38 ++++++++++++++++++++++++-------------- tests/src/screens/Test.js | 28 +++++++++------------------- 2 files changed, 33 insertions(+), 33 deletions(-) diff --git a/tests/lib/TestRun.js b/tests/lib/TestRun.js index c927949d..593d6d3d 100644 --- a/tests/lib/TestRun.js +++ b/tests/lib/TestRun.js @@ -306,7 +306,7 @@ class TestRun { } async _safelyRunFunction(func, timeOutDuration, description) { - const syncResultOrPromise = tryCatcher(func); + const syncResultOrPromise = captureThrownErrors(func); if (syncResultOrPromise.error) { // Synchronous Error @@ -314,49 +314,59 @@ class TestRun { } // Asynchronous Error - return promiseToCallBack(syncResultOrPromise.value, timeOutDuration, description); + return capturePromiseErrors(syncResultOrPromise.result, timeOutDuration, description); } } /** - * Try catch to object - * @returns {{}} + * Call a function and capture any errors that are immediately thrown. + * @returns {Object} Object containing result of executing the function, or the error + * message that was captured * @private */ -function tryCatcher(func) { +function captureThrownErrors(func) { const result = {}; try { - result.value = func(); - } catch (e) { - result.error = e; + result.result = func(); + } catch (error) { + result.error = error; } return result; } /** - * Make a promise callback-able to trap errors - * @param promise + * Wraps a promise so that if it's rejected or an error is thrown while it's being + * evaluated, it's captured and thrown no further + * @param {*} target - Target to wrap. If a thenable object, it's wrapped so if it's + * rejected or an error is thrown, it will be captured. If a non-thenable object, + * wrapped in resolved promise and returned. + * @param {Number} timeoutDuration - Number of milliseconds the promise is allowed + * to pend before it's considered timed out + * @param {String} description - Description of the context the promises is defined + * in, used for reporting where a timeout occurred in the resulting error message. * @private */ -function promiseToCallBack(promise, timeoutDuration, description) { +function capturePromiseErrors(target, timeoutDuration, description) { let returnValue = null; try { - returnValue = Promise.resolve(promise) + returnValue = Promise.resolve(target) .then(() => { return null; }, (error) => { return Promise.resolve(error); }) - .timeout(timeoutDuration, `${description} took longer than ${timeoutDuration}ms. This can be extended with the timeout option.`) .catch((error) => { return Promise.resolve(error); - }); + }) + .timeout(timeoutDuration, + `${description} took longer than ${timeoutDuration}ms. This can be extended with the timeout option.` + ); } catch (error) { returnValue = Promise.resolve(error); } diff --git a/tests/src/screens/Test.js b/tests/src/screens/Test.js index 5ba50f27..b4499656 100644 --- a/tests/src/screens/Test.js +++ b/tests/src/screens/Test.js @@ -62,16 +62,16 @@ class Test extends React.Component { {testContextName}:{description} - Test Error - + Test Error + {message || 'None'} - + Test Code Preview - + {beautify(removeLastLine(removeFirstLine(func.toString())), { indent_size: 4, break_chained_methods: true })} @@ -102,27 +102,17 @@ const styles = StyleSheet.create({ flex: 1, backgroundColor: '#ffffff', }, - header: { + testLabel: { + padding: 5, + backgroundColor: '#0288d1', fontWeight: '600', - fontSize: 18, - backgroundColor: '#000', - color: '#fff', - padding: 5, - }, - code: { - backgroundColor: '#3F373A', - color: '#c3c3c3', - padding: 5, - fontSize: 12, + color: '#ffffff', + fontSize: 16 }, description: { padding: 5, fontSize: 14, }, - testLabel: { - fontWeight: '600', - fontSize: 16 - } }); function select({ tests, testContexts }, { navigation: { state: { params: { testId } } } }) { From 86d771ba1bf4ac1f41fb8ce9d2b938082b30eff4 Mon Sep 17 00:00:00 2001 From: Aleck Greenham Date: Sat, 6 May 2017 13:10:09 +0100 Subject: [PATCH 39/39] [TestSuite] Add stack traces to failed tests --- tests/lib/TestRun.js | 3 +-- tests/src/actions/TestActions.js | 3 ++- tests/src/reducers/testsReducers.js | 1 + tests/src/screens/Test.js | 26 +++++++++++++++----------- 4 files changed, 19 insertions(+), 14 deletions(-) diff --git a/tests/lib/TestRun.js b/tests/lib/TestRun.js index 593d6d3d..82bd4484 100644 --- a/tests/lib/TestRun.js +++ b/tests/lib/TestRun.js @@ -286,8 +286,7 @@ class TestRun { suiteId: this.testSuite.id, status: RunStatus.ERR, time: Date.now() - this.runStartTime, - message: `Test suite failed: ${error.message}`, - stackTrace: error.stack, + message: `Test suite failed: ${error.message}` }); }); } diff --git a/tests/src/actions/TestActions.js b/tests/src/actions/TestActions.js index a2ed5fe3..71487b0a 100644 --- a/tests/src/actions/TestActions.js +++ b/tests/src/actions/TestActions.js @@ -14,13 +14,14 @@ export function setSuiteStatus({ suiteId, status, time, message, progress }) { }; } -export function setTestStatus({ testId, status, time = 0, message = null }) { +export function setTestStatus({ testId, status, stackTrace, time = 0, message = null }) { return { type: TEST_SET_STATUS, testId, status, message, + stackTrace, time, }; } diff --git a/tests/src/reducers/testsReducers.js b/tests/src/reducers/testsReducers.js index 204e600f..cfd6fb07 100644 --- a/tests/src/reducers/testsReducers.js +++ b/tests/src/reducers/testsReducers.js @@ -12,6 +12,7 @@ function testsReducers(state = initState.tests, action: Object): State { flattened[`${action.testId}.status`] = action.status; flattened[`${action.testId}.message`] = action.message; flattened[`${action.testId}.time`] = action.time; + flattened[`${action.testId}.stackTrace`] = action.stackTrace; return unflatten(flattened); } diff --git a/tests/src/screens/Test.js b/tests/src/screens/Test.js index b4499656..d69cb412 100644 --- a/tests/src/screens/Test.js +++ b/tests/src/screens/Test.js @@ -52,25 +52,26 @@ class Test extends React.Component { } render() { - const { test: { message, description, func, status, time }, testContextName } = this.props; + const { test: { stackTrace, description, func, status, time }, testContextName } = this.props; return ( {Test.renderBanner({ status, time })} - - {testContextName}:{description} + + {testContextName} + {description} - - Test Error + + Test Error - {message || 'None'} + {stackTrace || 'None.'} - + Test Code Preview - + {beautify(removeLastLine(removeFirstLine(func.toString())), { indent_size: 4, break_chained_methods: true })} @@ -85,8 +86,8 @@ Test.propTypes = { test: PropTypes.shape({ status: PropTypes.string, time: PropTypes.number, - message: PropTypes.string, func: PropTypes.function, + stackTrace: PropTypes.function, description: PropTypes.string, }).isRequired, @@ -102,12 +103,15 @@ const styles = StyleSheet.create({ flex: 1, backgroundColor: '#ffffff', }, - testLabel: { + sectionContainer: { + minHeight: 100, + }, + heading: { padding: 5, backgroundColor: '#0288d1', fontWeight: '600', color: '#ffffff', - fontSize: 16 + fontSize: 16, }, description: { padding: 5,