Merge branch 'v2' of github.com:invertase/react-native-firebase into v2

This commit is contained in:
Elliot Hesp 2017-06-20 13:22:24 +01:00
commit 7e3042cc92
7 changed files with 113 additions and 90 deletions

View File

@ -42,19 +42,30 @@ The native SDKs also allow us to hook into device sdk's which are not possible w
| Firebase Features | v1 | [v2](https://github.com/invertase/react-native-firebase/pull/130) | Web SDK | | Firebase Features | v1 | [v2](https://github.com/invertase/react-native-firebase/pull/130) | Web SDK |
| ---------------------- | :---: | :---: | :---: | | ---------------------- | :---: | :---: | :---: |
| AdMob | ❌ | ✅ | ❌ |
| Analytics             | ✅ | ✅ | ❌ | | Analytics             | ✅ | ✅ | ❌ |
| Cloud Messaging | ✅ | ✅ | ❌ |
| Authentication | ✅ | ✅ | ✅ |
| Realtime Database | ✅ | ✅ | ✅ |
| - Offline Persistance | ✅ | ✅ | ❌ |
| Storage | ✅ | ✅ | ❌ |
| Performance Monitoring | ✅ | ✅ | ❌ |
| Crash Reporting | ✅ | ✅ | ❌ |
| Remote Config | ✅ | ✅ | ❌ |
| App Indexing           | ❌ | ❌ | ❌ | | App Indexing           | ❌ | ❌ | ❌ |
| Authentication | ✅ | ✅ | ✅ |
| Cloud Messaging | ✅ | ✅ | ❌ |
| Crash Reporting | ✅ | ✅ | ❌ |
| Dynamic Links | ❌ | ❌ | ❌ | | Dynamic Links | ❌ | ❌ | ❌ |
| Invites | ❌ | ❌ | ❌ | | Invites | ❌ | ❌ | ❌ |
| AdMob | ❌ | ✅ | ❌ | | Performance Monitoring | ✅ | ✅ | ❌ |
| Realtime Database | ✅ | ✅ | ✅ |
| - Offline Persistance | ✅ | ✅ | ❌ |
| Remote Config | ✅ | ✅ | ❌ |
| Storage | ✅ | ✅ | ❌ |
---
### Supported versions - Firebase / React Native
> The table below shows the minimum supported versions of the Firebase SDKs and React Native
| | v1 | [v2](https://github.com/invertase/react-native-firebase/pull/130)
| ---------------------- | :---: | :---: |
| React Native | 0.36.0+ | 0.40.0 + |
| Firebase Android SDK | 10.2.0+ | 11.0.0 + |
| Firebase iOS SDK | 3.15.0+ | 4.0.0 + |
--- ---

View File

@ -32,17 +32,27 @@ The native SDKs also allow us to hook into device sdk's which are not possible w
| Firebase Features | v1 | [v2](https://github.com/invertase/react-native-firebase/pull/130) | Web SDK | | Firebase Features | v1 | [v2](https://github.com/invertase/react-native-firebase/pull/130) | Web SDK |
| ---------------------- | :---: | :---: | :---: | | ---------------------- | :---: | :---: | :---: |
| AdMob | ❌ | ✅ | ❌ |
| Analytics             | ✅ | ✅ | ❌ | | Analytics             | ✅ | ✅ | ❌ |
| Cloud Messaging | ✅ | ✅ | ❌ |
| Authentication | ✅ | ✅ | ✅ |
| Realtime Database | ✅ | ✅ | ✅ |
| - Offline Persistance | ✅ | ✅ | ❌ |
| Storage | ✅ | ✅ | ❌ |
| Performance Monitoring | ✅ | ✅ | ❌ |
| Crash Reporting | ✅ | ✅ | ❌ |
| Remote Config | ✅ | ✅ | ❌ |
| App Indexing           | ❌ | ❌ | ❌ | | App Indexing           | ❌ | ❌ | ❌ |
| Authentication | ✅ | ✅ | ✅ |
| Cloud Messaging | ✅ | ✅ | ❌ |
| Crash Reporting | ✅ | ✅ | ❌ |
| Dynamic Links | ❌ | ❌ | ❌ | | Dynamic Links | ❌ | ❌ | ❌ |
| Invites | ❌ | ❌ | ❌ | | Invites | ❌ | ❌ | ❌ |
| AdMob | ❌ | ✅ | ❌ | | Performance Monitoring | ✅ | ✅ | ❌ |
| Realtime Database | ✅ | ✅ | ✅ |
| - Offline Persistance | ✅ | ✅ | ❌ |
| Remote Config | ✅ | ✅ | ❌ |
| Storage | ✅ | ✅ | ❌ |
---
### Supported versions - Firebase / React Native
> The table below shows the minimum supported versions of the Firebase SDKs and React Native
| | v1 | [v2](https://github.com/invertase/react-native-firebase/pull/130)
| ---------------------- | :---: | :---: |
| React Native | 0.36.0+ | 0.40.0 + |
| Firebase Android SDK | 10.2.0+ | 11.0.0 + |
| Firebase iOS SDK | 3.15.0+ | 4.0.0 + |

View File

@ -77,18 +77,18 @@ dependencies {
compile(project(':react-native-firebase')) { compile(project(':react-native-firebase')) {
transitive = false transitive = false
} }
compile "com.google.firebase:firebase-core:10.2.6" compile "com.google.firebase:firebase-core:11.0.0"
# RNFirebase optional dependencies # RNFirebase optional dependencies
compile "com.google.firebase:firebase-ads:10.2.6" compile "com.google.firebase:firebase-ads:11.0.0"
compile "com.google.firebase:firebase-analytics:10.2.6" compile "com.google.firebase:firebase-analytics:11.0.0"
compile "com.google.firebase:firebase-auth:10.2.6" compile "com.google.firebase:firebase-auth:11.0.0"
compile "com.google.firebase:firebase-config:10.2.6" compile "com.google.firebase:firebase-config:11.0.0"
compile "com.google.firebase:firebase-crash:10.2.6" compile "com.google.firebase:firebase-crash:11.0.0"
compile "com.google.firebase:firebase-database:10.2.6" compile "com.google.firebase:firebase-database:11.0.0"
compile "com.google.firebase:firebase-messaging:10.2.6" compile "com.google.firebase:firebase-messaging:11.0.0"
compile "com.google.firebase:firebase-perf:10.2.6" compile "com.google.firebase:firebase-perf:11.0.0"
compile "com.google.firebase:firebase-storage:10.2.6" compile "com.google.firebase:firebase-storage:11.0.0"
} }
``` ```
@ -175,6 +175,6 @@ In the same file, add the `firebase-perf` module to your dependencies:
``` ```
dependencies { dependencies {
... ...
compile "com.google.firebase:firebase-perf:10.2.6" compile "com.google.firebase:firebase-perf:11.0.0"
} }
``` ```

View File

@ -12,9 +12,9 @@ and this to the `didFinishLaunchingWithOptions:(NSDictionary *)launchOptions` me
`[FIRApp configure];` `[FIRApp configure];`
## 2) Link RNFirebase ## 2) Setup RNFirebase
Unfortunately, due to the fact that Firebase is much easier to setup using Cocoapods, `react-native link` is not recommended as it is not customisable enough for our needs and we have had numerous problems reported. Unfortunately, due to the fact that Firebase is much easier to setup using Cocoapods, *we do not recommend* `react-native link` as it is not customisable enough for our needs and we have had numerous problems reported.
### 2.0) If you don't already have Cocoapods set up ### 2.0) If you don't already have Cocoapods set up
Follow the instructions to install Cocoapods and create your Podfile [here](https://firebase.google.com/docs/ios/setup#add_the_sdk). Follow the instructions to install Cocoapods and create your Podfile [here](https://firebase.google.com/docs/ios/setup#add_the_sdk).

106
index.d.ts vendored
View File

@ -13,14 +13,14 @@ declare module "react-native-firebase" {
on(type: string, handler: (msg: any) => void): any; on(type: string, handler: (msg: any) => void): any;
/** mimics firebase Web SDK */ /** mimics firebase Web SDK */
database(): RNFirebase.database.Database; database(): RNFirebase.database.Database;
/**RNFirebase mimics the Web Firebase SDK Storage, /**RNFirebase mimics the Web Firebase SDK Storage,
* whilst providing some iOS and Android specific functionality. * whilst providing some iOS and Android specific functionality.
*/ */
storage(): RNFirebase.storage.Storage; storage(): RNFirebase.storage.Storage;
/** /**
* Firebase Cloud Messaging (FCM) allows you to send push messages at no cost to both Android & iOS platforms. * Firebase Cloud Messaging (FCM) 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. * Assuming the installation instructions have been followed, FCM is ready to go.
* As the Firebase Web SDK has limited messaging functionality, * As the Firebase Web SDK has limited messaging functionality,
* the following methods within react-native-firebase have been created to handle FCM in the React Native environment. * the following methods within react-native-firebase have been created to handle FCM in the React Native environment.
*/ */
messaging(): RNFirebase.messaging.Messaging; messaging(): RNFirebase.messaging.Messaging;
@ -51,20 +51,20 @@ declare module "react-native-firebase" {
}; };
/** /**
* pass custom options by passing an object with configuration options. * pass custom options by passing an object with configuration options.
* The configuration object will be generated first by the native configuration object, if set and then will be overridden if passed in JS. * The configuration object will be generated first by the native configuration object, if set and then will be overridden if passed in JS.
* That is, all of the following key/value pairs are optional if the native configuration is set. * That is, all of the following key/value pairs are optional if the native configuration is set.
*/ */
interface configurationOptions { interface configurationOptions {
/** /**
* default false * default false
* When set to true, RNFirebase will log messages to the console and fire debug events we can listen to in js * When set to true, RNFirebase will log messages to the console and fire debug events we can listen to in js
* @usage * @usage
* firebase.on('debug', msg => console.log('Received debug message', msg)) * firebase.on('debug', msg => console.log('Received debug message', msg))
*/ */
debug?: boolean; debug?: boolean;
/** /**
* default false * default false
* When set to true, database persistence will be enabled. * When set to true, database persistence will be enabled.
*/ */
persistence?: boolean; persistence?: boolean;
@ -73,47 +73,47 @@ declare module "react-native-firebase" {
*/ */
bundleID?: string; bundleID?: string;
/** /**
* defualt "" * defualt ""
* The Google App ID that is used to uniquely identify an instance of an app. * The Google App ID that is used to uniquely identify an instance of an app.
*/ */
googleAppID?: string; googleAppID?: string;
/** /**
* deufalt "" * deufalt ""
* The database root (i.e. https://my-app.firebaseio.com) * The database root (i.e. https://my-app.firebaseio.com)
*/ */
databaseURL?: string; databaseURL?: string;
/** /**
* defualt "" * defualt ""
* URL scheme to set up durable deep link service * URL scheme to set up durable deep link service
*/ */
deepLinkURLScheme?: string; deepLinkURLScheme?: string;
/** /**
* defualt "" * defualt ""
* The Google Cloud storage bucket name * The Google Cloud storage bucket name
*/ */
storageBucket?: string; storageBucket?: string;
/** /**
* default "" * default ""
* The Android client ID used in Google AppInvite when an iOS app has it's android version * The Android client ID used in Google AppInvite when an iOS app has it's android version
*/ */
androidClientID?: string; androidClientID?: string;
/** /**
* default "" * default ""
* The Project number from the Google Developer's console used to configure Google Cloud Messaging * The Project number from the Google Developer's console used to configure Google Cloud Messaging
*/ */
GCMSenderID?: string; GCMSenderID?: string;
/** /**
* default "" * default ""
* The tracking ID for Google Analytics * The tracking ID for Google Analytics
*/ */
trackingID?: string; trackingID?: string;
/** /**
* default "" * default ""
* The OAuth2 client ID for iOS application used to authenticate Google Users for signing in with Google * The OAuth2 client ID for iOS application used to authenticate Google Users for signing in with Google
*/ */
clientID?: string; clientID?: string;
/** /**
* defualt "" * defualt ""
* The secret iOS API key used for authenticating requests from our app * The secret iOS API key used for authenticating requests from our app
*/ */
APIKey?: string APIKey?: string
@ -270,11 +270,11 @@ declare module "react-native-firebase" {
* */ * */
ref(path?: string): RnReference ref(path?: string): RnReference
/** /**
* register listener * register listener
*/ */
on(path: string, modifiersString: string, modifiers: Array<string>, eventName: string, cb: () => void, errorCb: () => void): any on(path: string, modifiersString: string, modifiers: Array<string>, eventName: string, cb: () => void, errorCb: () => void): any
/** /**
* unregister listener * unregister listener
*/ */
off(path: string, modifiersString: string, eventName?: string, origCB?: () => void): any off(path: string, modifiersString: string, eventName?: string, origCB?: () => void): any
/** /**
@ -376,13 +376,13 @@ declare module "react-native-firebase" {
setAnalyticsCollectionEnabled(enabled: boolean): void setAnalyticsCollectionEnabled(enabled: boolean): void
/** /**
* Sets the current screen name, which specifies the current visual context in your app. * Sets the current screen name, which specifies the current visual context in your app.
* Whilst screenClassOverride is optional, * Whilst screenClassOverride is optional,
* it is recommended it is always sent as your current class name, * it is recommended it is always sent as your current class name,
* for example on Android it will always show as 'MainActivity' if not specified. * for example on Android it will always show as 'MainActivity' if not specified.
*/ */
setCurrentScreen(screenName: string, screenClassOverride?: string): void setCurrentScreen(screenName: string, screenClassOverride?: string): void
/** /**
* Sets the minimum engagement time required before starting a session. * Sets the minimum engagement time required before starting a session.
* The default value is 10000 (10 seconds) * The default value is 10000 (10 seconds)
*/ */
setMinimumSessionDuration(miliseconds: number): void setMinimumSessionDuration(miliseconds: number): void
@ -393,9 +393,9 @@ declare module "react-native-firebase" {
setSessionTimeoutDuration(miliseconds: number): void setSessionTimeoutDuration(miliseconds: number): void
/** /**
* Gives a user a uniqiue identificaition. * Gives a user a uniqiue identificaition.
* @example * @example
* const id = firebase.auth().currentUser.uid; * const id = firebase.auth().currentUser.uid;
* *
* firebase.analytics().setUserId(id); * firebase.analytics().setUserId(id);
*/ */
setUserId(id: string): void setUserId(id: string): void
@ -420,7 +420,7 @@ declare module "react-native-firebase" {
*/ */
emailVerified: boolean emailVerified: boolean
/** /**
* *
*/ */
isAnonymous: boolean isAnonymous: boolean
/** /**
@ -457,19 +457,19 @@ declare module "react-native-firebase" {
*/ */
reload(): Promise<void> reload(): Promise<void>
/** /**
* Sends a verification email to a user. * Sends a verification email to a user.
* This will Promise reject is the user is anonymous. * This will Promise reject is the user is anonymous.
*/ */
sendEmailVerification(): Promise<void> sendEmailVerification(): Promise<void>
/** /**
* Updates the user's email address. * Updates the user's email address.
* See Firebase docs for more information on security & email validation. * See Firebase docs for more information on security & email validation.
* This will Promise reject is the user is anonymous. * This will Promise reject is the user is anonymous.
*/ */
updateEmail(email: string): Promise<void> updateEmail(email: string): Promise<void>
/** /**
* Important: this is a security sensitive operation that requires the user to have recently signed in. * Important: this is a security sensitive operation that requires the user to have recently signed in.
* If this requirement isn't met, ask the user to authenticate again and then call firebase.User#reauthenticate. * If this requirement isn't met, ask the user to authenticate again and then call firebase.User#reauthenticate.
* This will Promise reject is the user is anonymous. * This will Promise reject is the user is anonymous.
*/ */
updatePassword(password: string): Promise<void> updatePassword(password: string): Promise<void>
@ -498,48 +498,48 @@ declare module "react-native-firebase" {
*/ */
currentUser: User | null currentUser: User | null
/** /**
* Listen for changes in the users auth state (logging in and out). * Listen for changes in the users auth state (logging in and out).
* This method returns a unsubscribe function to stop listening to events. * This method returns a unsubscribe function to stop listening to events.
* Always ensure you unsubscribe from the listener when no longer needed to prevent updates to components no longer in use. * Always ensure you unsubscribe from the listener when no longer needed to prevent updates to components no longer in use.
*/ */
onAuthStateChanged( onAuthStateChanged(
nextOrObserver: Object, error?: (a: RnError) => any, nextOrObserver: Object, error?: (a: RnError) => any,
completed?: () => any): () => any; completed?: () => any): () => any;
/** /**
* We can create a user by calling the createUserWithEmailAndPassword() function. * We can create a user by calling the createUserWithEmailAndPassword() function.
* The method accepts two parameters, an email and a password. * The method accepts two parameters, an email and a password.
*/ */
createUserWithEmailAndPassword(email: string, password: string): Promise<User> createUserWithEmailAndPassword(email: string, password: string): Promise<User>
/** /**
* To sign a user in with their email and password, use the signInWithEmailAndPassword() function. * To sign a user in with their email and password, use the signInWithEmailAndPassword() function.
* It accepts two parameters, the user's email and password: * It accepts two parameters, the user's email and password:
*/ */
signInWithEmailAndPassword(email: string, password: string): Promise<User> signInWithEmailAndPassword(email: string, password: string): Promise<User>
/** /**
* Sign an anonymous user. * Sign an anonymous user.
* If the user has already signed in, that user will be returned * If the user has already signed in, that user will be returned
*/ */
signInAnonymously(): Promise<User> signInAnonymously(): Promise<User>
/** /**
* Sign in the user with a 3rd party credential provider. * Sign in the user with a 3rd party credential provider.
* credential requires the following properties: * credential requires the following properties:
*/ */
signInWithCredential(credential: Credential): Promise<User> signInWithCredential(credential: Credential): Promise<User>
/** /**
* Sign a user in with a self-signed JWT token. * Sign a user in with a self-signed JWT token.
* To sign a user using a self-signed custom token, * To sign a user using a self-signed custom token,
* use the signInWithCustomToken() function. * use the signInWithCustomToken() function.
* It accepts one parameter, the custom token: * It accepts one parameter, the custom token:
*/ */
signInWithCustomToken(token: string): Promise<User> signInWithCustomToken(token: string): Promise<User>
/** /**
* Sends a password reset email to the given email address. * Sends a password reset email to the given email address.
* Unlike the web SDK, * Unlike the web SDK,
* the email will contain a password reset link rather than a code. * the email will contain a password reset link rather than a code.
*/ */
sendPasswordResetEmail(email: string): Promise<void> sendPasswordResetEmail(email: string): Promise<void>
/** /**
* Completes the password reset process, * Completes the password reset process,
* given a confirmation code and new password. * given a confirmation code and new password.
*/ */
signOut(): Promise<void> signOut(): Promise<void>
@ -559,13 +559,13 @@ declare module "react-native-firebase" {
*/ */
unsubscribeFromTopic(topic: string): void unsubscribeFromTopic(topic: string): void
/** /**
* When the application has been opened from a notification * When the application has been opened from a notification
* getInitialNotification is called and the notification payload is returned. * getInitialNotification is called and the notification payload is returned.
* Use onMessage for notifications when the app is running. * Use onMessage for notifications when the app is running.
*/ */
getInitialNotification(): Promise<any> getInitialNotification(): Promise<any>
/** /**
* Returns the devices FCM token. * Returns the devices FCM token.
* This token can be used in the Firebase console to send messages to directly. * This token can be used in the Firebase console to send messages to directly.
*/ */
getToken(forceRefresh?: Boolean): Promise<string> getToken(forceRefresh?: Boolean): Promise<string>
@ -573,14 +573,14 @@ declare module "react-native-firebase" {
* On the event a devices FCM token is refreshed by Google, * On the event a devices FCM token is refreshed by Google,
* the new token is returned in a callback listener. * the new token is returned in a callback listener.
*/ */
onTokenRefresh(listener: (token: string) => any): void onTokenRefresh(listener: (token: string) => any): () => any
/** /**
* On a new message, * On a new message,
* the payload object is passed to the listener callback. * the payload object is passed to the listener callback.
* This method is only triggered when the app is running. * This method is only triggered when the app is running.
* Use getInitialNotification for notifications which cause the app to open. * Use getInitialNotification for notifications which cause the app to open.
*/ */
onMessage(listener: (message: any) => any): void onMessage(listener: (message: any) => any): () => any
/** /**
* Create a local notification from the device itself. * Create a local notification from the device itself.
*/ */
@ -600,17 +600,17 @@ declare module "react-native-firebase" {
*/ */
getScheduledLocalNotifications(): Promise<any[]> getScheduledLocalNotifications(): Promise<any[]>
/** /**
* Cancels a location notification by ID, * Cancels a location notification by ID,
* or all notifications by *. * or all notifications by *.
*/ */
cancelLocalNotification(id: string): void cancelLocalNotification(id: string): void
/** /**
* Removes all delivered notifications from device by ID, * Removes all delivered notifications from device by ID,
* or all notifications by *. * or all notifications by *.
*/ */
removeDeliveredNotification(id: string): void removeDeliveredNotification(id: string): void
/** /**
* IOS * IOS
* Requests app notification permissions in an Alert dialog. * Requests app notification permissions in an Alert dialog.
*/ */
requestPermissions(): void requestPermissions(): void
@ -654,7 +654,7 @@ declare module "react-native-firebase" {
*/ */
logcat(level: number, tag: string, message: string): void logcat(level: number, tag: string, message: string): void
/** /**
* Files a crash report, along with any previous logs to Firebase. * Files a crash report, along with any previous logs to Firebase.
* An Error object must be passed into the report method. * An Error object must be passed into the report method.
*/ */
report(error: RnError, maxStackSize: Number): void report(error: RnError, maxStackSize: Number): void
@ -662,4 +662,4 @@ declare module "react-native-firebase" {
} }
} }
} }
} }

View File

@ -203,8 +203,8 @@ export default class Messaging extends Base {
* @param listener * @param listener
* @returns {*} * @returns {*}
*/ */
onMessage(listener: Function) { onMessage(listener: Function): () => any {
return FirebaseMessagingEvt.addListener( const rnListener = FirebaseMessagingEvt.addListener(
EVENT_TYPE.Notification, EVENT_TYPE.Notification,
async(event) => { async(event) => {
const data = { const data = {
@ -217,7 +217,8 @@ export default class Messaging extends Base {
data.finish(); data.finish();
} }
} }
).remove; );
return () => rnListener.remove();
} }
/** /**
@ -225,8 +226,9 @@ export default class Messaging extends Base {
* @param listener * @param listener
* @returns {*} * @returns {*}
*/ */
onTokenRefresh(listener: Function) { onTokenRefresh(listener: Function): () => any {
return FirebaseMessagingEvt.addListener(EVENT_TYPE.RefreshToken, listener).remove; const rnListener = FirebaseMessagingEvt.addListener(EVENT_TYPE.RefreshToken, listener);
return () => rnListener.remove();
} }
/** /**

View File

@ -1,6 +1,6 @@
{ {
"name": "react-native-firebase", "name": "react-native-firebase",
"version": "1.1.0", "version": "1.1.1",
"author": "Invertase <contact@invertase.io> (http://invertase.io)", "author": "Invertase <contact@invertase.io> (http://invertase.io)",
"description": "A well tested, feature rich Firebase implementation for React Native, supporting iOS & Android. Individual module support for Auth, Database, Messaging, Remote Config, Storage, Admob, Analytics, Crash Reporting, and Performance.", "description": "A well tested, feature rich Firebase implementation for React Native, supporting iOS & Android. Individual module support for Auth, Database, Messaging, Remote Config, Storage, Admob, Analytics, Crash Reporting, and Performance.",
"main": "index", "main": "index",