Skip to content

Commit 5558491

Browse files
authored
React native firebase (#261)
* Fix API doc upload utility (catch errors better) * `react-native-firebase` complete example added * Native modules docs updated
1 parent 710007a commit 5558491

File tree

36 files changed

+7032
-54
lines changed

36 files changed

+7032
-54
lines changed

.gitignore

Lines changed: 77 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,84 @@
1-
# Dependency directory
1+
# ---- Dependency directory ----
22
node_modules
3+
4+
# ---- Logs ----
5+
*.log
6+
7+
# OS-specific files
8+
.DS_Store
9+
.DS_Store?
10+
._*
11+
.Spotlight-V100
12+
.Trashes
13+
14+
/.idea
15+
16+
# ---- Project ----
317
examples/**/node_modules
18+
_book/**
19+
_site/**
420
coverage
521
dist
622
es
723
lib
8-
_book/**
9-
_site/**
10-
# Logs
11-
*.log
12-
.DS_Store
1324
examples/complete/react-native/ios/build
14-
/.idea
25+
examples/complete/react-native-firebase/ios/build
26+
27+
# ---- React Native ----
28+
# Xcode
29+
*.pbxuser
30+
*.mode1v3
31+
*.mode2v3
32+
*.perspectivev3
33+
*.xcuserstate
34+
project.xcworkspace/
35+
xcuserdata/
36+
37+
# Built application files
38+
**/android/**/build/
39+
40+
# Crashlytics configuations
41+
android/com_crashlytics_export_strings.xml
42+
43+
# Signing files
44+
android/.signing/
45+
46+
# Local configuration file (sdk path, etc)
47+
**/android/local.properties
48+
49+
# Gradle generated files
50+
**/android/.gradle/
51+
52+
# Signing files
53+
android/.signing/
54+
55+
# User-specific configurations
56+
android/.idea/gradle.xml
57+
android/.idea/libraries/
58+
android/.idea/workspace.xml
59+
android/.idea/tasks.xml
60+
android/.idea/.name
61+
android/.idea/compiler.xml
62+
android/.idea/copyright/profiles_settings.xml
63+
android/.idea/encodings.xml
64+
android/.idea/misc.xml
65+
android/.idea/modules.xml
66+
android/.idea/scopes/scope_settings.xml
67+
android/.idea/vcs.xml
68+
**/android/**/*.iml
69+
ios/RnFirebase.xcodeproj/xcuserdata
70+
ehthumbs.db
71+
Thumbs.dbandroid/gradle
72+
android/gradlew
73+
android/build
74+
android/.gradle
75+
android/gradlew.bat
76+
android/gradle
77+
lib/.watchmanconfig
78+
.idea
79+
.gradle
80+
local.properties
81+
*.iml
82+
**/ios/Pods/**
83+
**/ios/build/**
84+
**/ios/ReactNativeFirebaseDemo.xcworkspace/

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ Include `reactReduxFirebase` in your store compose function and `firebaseStateR
6363
```javascript
6464
import { createStore, combineReducers, compose } from 'redux'
6565
import { reactReduxFirebase, firebaseStateReducer } from 'react-redux-firebase'
66-
import * as firebase from 'firebase'
66+
import firebase from 'firebase'
6767

6868
// Add Firebase to reducers
6969
const rootReducer = combineReducers({

bin/api-docs-upload.js

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ const exec = require('child-process-promise').exec
22
const version = require('../package.json').version
33

44
/**
5-
NOTE: Split into two arrays because gsutil acts differently when
6-
no files exist at a location. First array includes at least one file for each
7-
folder that will be copied in the second.
8-
*/
5+
* NOTE: Split into two arrays because gsutil acts differently when
6+
* no files exist at a location. First array includes at least one file for each
7+
* folder that will be copied in the second.
8+
*/
99
const first = [
1010
'_book/index.html',
1111
'_book/search_index.json',
@@ -26,15 +26,15 @@ const project = 'docs.react-redux-firebase.com'
2626
* @return {Promise} Resolves with stdout of running command
2727
* @private
2828
*/
29-
const runCommand = (cmd) => {
30-
const baseCommand = cmd.split(' ')[0]
31-
return exec(baseCommand)
29+
const runCommand = (cmd) =>
30+
exec(cmd)
3231
.catch((err) =>
33-
err.message && err.message.indexOf('not found') !== -1
34-
? Promise.reject(new Error(`${baseCommand} must be installed to upload`))
35-
: Promise.reject(err)
32+
Promise.reject(
33+
err.message && err.message.indexOf('not found') !== -1
34+
? new Error(`${cmd.split(' ')[0]} must be installed to upload`)
35+
: err
36+
)
3637
)
37-
}
3838

3939
/**
4040
* Upload file or folder to cloud storage. gsutil is used instead of
@@ -44,10 +44,13 @@ const runCommand = (cmd) => {
4444
* @private
4545
*/
4646
const upload = (entityPath) => {
47-
const prefix = `history/${version.split('-')[0]}`
47+
const prefix = `history/v${version.split('-')[0]}`
4848
const uploadPath = `${project}/${prefix}/${entityPath.replace('_book/', '').replace('/**', '')}`
49-
return runCommand(`gsutil -m cp -r -a public-read ${entityPath} gs://${uploadPath}`)
50-
.then((stdout) => ({ stdout, uploadPath }))
49+
const command = `gsutil -m cp -r -a public-read ${entityPath} gs://${uploadPath}`
50+
return runCommand(command)
51+
.then(({ stdout, stderr }) =>
52+
stdout ? Promise.reject(stdout) : ({ output: stderr, uploadPath })
53+
)
5154
}
5255

5356
/**
@@ -60,16 +63,21 @@ const uploadList = (files) => {
6063
return Promise.all(
6164
files.map(file =>
6265
upload(file)
63-
.then(({ uploadPath }) => {
66+
.then(({ uploadPath, output }) => {
6467
console.log(`Successfully uploaded: ${uploadPath}`) // eslint-disable-line no-console
65-
return file
68+
return output
69+
})
70+
.catch((err) => {
71+
console.log('error:', err.message || err) // eslint-disable-line no-console
72+
return Promise.reject(err)
6673
})
6774
)
6875
)
6976
}
7077

7178
(function () {
72-
uploadList(first)
79+
runCommand('gsutil') // check for existence of gsutil
80+
.then(() => uploadList(first))
7381
.then(() => uploadList(second))
7482
.then(() => {
7583
console.log('Docs uploaded successfully') // eslint-disable-line no-console

docs/recipes/react-native.md

Lines changed: 52 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,58 @@ Regardless of which path you want to take, initial setup is the same, so we will
66

77
**NOTE:** Make sure you include `enableRedirectHandling: false` when using react-native with `v2.0.0`. This is required to disable redirect handling (which uses http) since it is not supported in react-native. There has been discussion of a way to make this happen automatically, but for now it is required.
88

9+
## Native Modules
10+
11+
Passing in an instance also allows for libraries with similar APIs (such as [`react-native-firebase`](https://github.com/invertase/react-native-firebase)) to be used instead:
12+
13+
1. Follow [use instructions in README](http://react-redux-firebase.com/#use)
14+
1. When creating redux store pass `react-native-firebase` App instance into `reactReduxFirebase` when creating store:
15+
16+
**createStore.js**
17+
```js
18+
import { compose, createStore } from 'redux';
19+
import RNFirebase from 'react-native-firebase';
20+
import { getFirebase, reactReduxFirebase } from 'react-redux-firebase';
21+
import thunk from 'redux-thunk';
22+
import makeRootReducer from './reducers';
23+
24+
const reactNativeFirebaseConfig = {
25+
debug: true
26+
};
27+
28+
const reduxFirebaseConfig = {
29+
userProfile: 'users', // save users profiles to 'users' collection
30+
};
31+
32+
export default (initialState = { firebase: {} }) => {
33+
// initialize firebase
34+
const firebase = RNFirebase.initializeApp(reactNativeFirebaseConfig);
35+
36+
const store = createStore(
37+
makeRootReducer(),
38+
initialState,
39+
compose(
40+
reactReduxFirebase(firebase, reduxFirebaseConfig), // pass initialized react-native-firebase app instance
41+
// applyMiddleware can be placed here
42+
)
43+
);
44+
45+
return store;
46+
};
47+
```
48+
49+
Full `react-native-firebase` example app source with styling available [in the react-native-firebase complete example](https://github.com/prescottprue/react-redux-firebase/tree/v2.0.0/examples/complete/react-native-firebase).
50+
51+
### Setup
52+
1. Run `create-react-native-app my-app`
53+
1. Enter the app folder `cd my-app`
54+
1. Run the eject command `yarn run eject` or `npm run eject` and choose "Regular React Native App"
55+
1. Run `npm i --save redux react-redux react-redux-firebase@canary redux-thunk`
56+
1. Open the xcode project in ios/myapp
57+
* Drag the `GoogleService-Info.plist` into the project -> check box saying copy
58+
* switch the identifier to the one you just gave Firebase
59+
1. Follow the [react-native-firebase initial setup guide](http://invertase.io/react-native-firebase/#/initial-setup)
60+
961
## JS/Web
1062

1163
**NOTE**: Only works for versions `v2.0.0-alpha` and higher. For older versions please view the docs associated with previous version.
@@ -36,37 +88,8 @@ const store = createStore(
3688
)
3789
```
3890

39-
## Native Modules
40-
41-
Passing in an instance also allows for libraries with similar APIs (such as [`react-native-firebase`](https://github.com/invertase/react-native-firebase)) to be used instead:
42-
43-
```js
44-
import RNFirebase from 'react-native-firebase';
45-
46-
const configurationOptions = {
47-
debug: true
48-
};
49-
50-
const firebase = RNFirebase.initializeApp(configurationOptions);
51-
52-
const reduxConfig = {
53-
enableRedirectHandling: false // required
54-
}
55-
56-
const store = createStore(
57-
reducer,
58-
undefined,
59-
compose(
60-
reactReduxFirebase(firebase, reduxConfig), // pass in react-native-firebase instance instead of config
61-
applyMiddleware(...middleware)
62-
)
63-
)
64-
```
65-
The [react-native-firebase initial setup guide](http://invertase.io/react-native-firebase/#/initial-setup) has more information about how to setup your project for iOS/Android.
66-
6791
Full project source: [react-native complete example app](https://github.com/prescottprue/react-redux-firebase/tree/master/examples/complete/react-native)
6892

69-
7093
### Setup
7194

7295
1. Click "Add Firebase To iOS"
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"presets": [
3+
"babel-preset-react-native-stage-0/decorator-support"
4+
],
5+
"env": {
6+
"development": {
7+
"plugins": [
8+
"transform-react-jsx-source"
9+
]
10+
}
11+
}
12+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
node_modules/
2+
.expo/
3+
npm-debug.*
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import React from 'react';
2+
import { StyleSheet, Text, View } from 'react-native';
3+
4+
export default class App extends React.Component {
5+
render() {
6+
return (
7+
<View style={styles.container}>
8+
<Text>Open up App.js to start working on your app!</Text>
9+
<Text>Changes you make will automatically reload.</Text>
10+
<Text>Shake your phone to open the developer menu.</Text>
11+
</View>
12+
);
13+
}
14+
}
15+
16+
const styles = StyleSheet.create({
17+
container: {
18+
flex: 1,
19+
backgroundColor: '#fff',
20+
alignItems: 'center',
21+
justifyContent: 'center',
22+
},
23+
});
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import React from 'react';
2+
import App from './App';
3+
4+
import renderer from 'react-test-renderer';
5+
6+
it('renders without crashing', () => {
7+
const rendered = renderer.create(<App />).toJSON();
8+
expect(rendered).toBeTruthy();
9+
});
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# React Native Firebase Example
2+
3+
> Simple example of using native modules with react-redux-firebase by using react-native-firebase
4+
5+
This project was bootstrapped with [Create React Native App](https://github.com/react-community/create-react-native-app).
6+
7+
8+
## Get Started
9+
10+
1. `yarn install`
11+
1. `react-native run-ios`

0 commit comments

Comments
 (0)