Skip to content

Commit dbdeb31

Browse files
committed
basic structure
1 parent 0b3af26 commit dbdeb31

32 files changed

+417
-158
lines changed

mobile/ReactNativeTutorial/android/app/build.gradle

+1
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ android {
126126
}
127127

128128
dependencies {
129+
compile project(':react-native-vector-icons')
129130
compile fileTree(dir: "libs", include: ["*.jar"])
130131
compile "com.android.support:appcompat-v7:23.0.1"
131132
compile "com.facebook.react:react-native:+" // From node_modules
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

mobile/ReactNativeTutorial/android/app/src/main/java/com/reactnativetutorial/MainApplication.java

+3-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import android.util.Log;
55

66
import com.facebook.react.ReactApplication;
7+
import com.oblador.vectoricons.VectorIconsPackage;
78
import com.facebook.react.ReactInstanceManager;
89
import com.facebook.react.ReactNativeHost;
910
import com.facebook.react.ReactPackage;
@@ -23,7 +24,8 @@ protected boolean getUseDeveloperSupport() {
2324
@Override
2425
protected List<ReactPackage> getPackages() {
2526
return Arrays.<ReactPackage>asList(
26-
new MainReactPackage()
27+
new MainReactPackage(),
28+
new VectorIconsPackage()
2729
);
2830
}
2931
};
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
rootProject.name = 'ReactNativeTutorial'
22

33
include ':app'
4+
include ':react-native-vector-icons'
5+
project(':react-native-vector-icons').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-vector-icons/android')

mobile/ReactNativeTutorial/app/App.js

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// @flow
2+
import React from 'react';
3+
import { Provider } from 'react-redux';
4+
import store from './setup/store';
5+
import Comments from './bundles/comments/Comments';
6+
7+
type PropsType = {
8+
9+
}
10+
11+
const App = (props: PropsType) => (
12+
<Provider store={store}>
13+
<Comments />
14+
</Provider>
15+
);
16+
17+
export default App;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// @flow
2+
import React from 'react';
3+
import Add from './components/Add/Add';
4+
5+
type PropsType = {
6+
7+
}
8+
9+
const Comments = (props: PropsType) => (
10+
<Add />
11+
);
12+
13+
export default Comments;
14+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// @flow
2+
import React from 'react';
3+
import { View, Text } from 'react-native';
4+
import { FormLabel, FormInput } from 'react-native-elements'
5+
6+
import withAddProps from '../../hocs/withAddProps'
7+
8+
import styles from './AddStyle';
9+
10+
type PropsType = {
11+
12+
}
13+
14+
const Add = (props: PropsType) => (
15+
<View style={styles.container}>
16+
<FormLabel>Author name</FormLabel>
17+
<FormInput onChangeText={(text) => {props.actions.updateForm({name: text})}}/>
18+
<FormLabel>Comment</FormLabel>
19+
<FormInput onChangeText={(text) => {props.actions.updateForm({comment: text})}}/>
20+
</View>
21+
);
22+
23+
export default withAddProps(Add);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { StyleSheet } from 'react-native';
2+
3+
const styles = StyleSheet.create({
4+
container: {
5+
},
6+
});
7+
8+
export default styles;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// @flow
2+
import { bindActionCreators } from 'redux';
3+
import { connect } from 'react-redux';
4+
import { createSelector } from 'reselect';
5+
6+
import commentFormSelector from '../../../selectors/commentFormSelector';
7+
import { actions } from '../sagas';
8+
9+
const mapStateToProps = createSelector(commentFormSelector, commentForm => commentForm.toJS());
10+
11+
const mapDispatchToProps = (dispatch: Function) => ({
12+
actions: bindActionCreators(actions, dispatch),
13+
});
14+
15+
export default (Component: ReactClass<any>): ReactClass<{}> =>
16+
connect(mapStateToProps, mapDispatchToProps)(Component);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// @flow
2+
import { bindActionCreators } from 'redux';
3+
import { connect } from 'react-redux';
4+
5+
import commentsStoreSelector from '../../../selectors/commentsStoreSelector';
6+
import * as actions from '../sagas';
7+
8+
const mapDispatchToProps = (dispatch: Function) => ({
9+
actions: bindActionCreators(actions, dispatch),
10+
});
11+
12+
export default (Component: ReactClass<any>): ReactClass<{}> =>
13+
connect(commentsStoreSelector, mapDispatchToProps)(Component);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import { takeLatest } from 'redux-saga';
2+
import { call, put } from 'redux-saga/effects';
3+
4+
import { actions as reduxActions } from '../../../reducers'
5+
6+
const FETCH = 'COMMENTS:FETCH';
7+
const UPDATE_FORM = 'COMMENTS:UPDATE_FORM';
8+
9+
function* fetchHandler() {
10+
// try {
11+
// const responsePromise = yield call(api.fetchEntities);
12+
// const { comments } = yield call(() => responsePromise.json());
13+
// yield put({ type: actionTypes.FETCH_COMMENTS_SUCCESS, comments });
14+
// } catch (e) {
15+
// yield put({ type: actionTypes.FETCH_COMMENTS_FAILURE, error: e.message });
16+
// }
17+
}
18+
19+
function* fetchSaga () {
20+
yield* takeLatest(FETCH, fetchHandler);
21+
}
22+
23+
function* updateFormHandler(action) {
24+
yield put(reduxActions.updateCommentForm(action.payload));
25+
}
26+
27+
function* updateFormSaga () {
28+
yield* takeLatest(UPDATE_FORM, updateFormHandler);
29+
}
30+
31+
export default [
32+
fetchSaga,
33+
updateFormSaga,
34+
];
35+
36+
const fetch = () => ({ type: FETCH });
37+
const updateForm = (payload) => ({ type: UPDATE_FORM, payload });
38+
39+
export const actions = {
40+
fetch,
41+
updateForm,
42+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import { fromJS } from 'immutable';
2+
3+
const UPDATE = 'COMMENT_FORM:UPDATE';
4+
const RESET = 'COMMENT_FORM:RESET';
5+
6+
export const initialState = fromJS({
7+
meta: {}
8+
});
9+
10+
const update = (state, action) => {
11+
return state.merge(action.payload);
12+
};
13+
14+
export default (state, action) => {
15+
if (!state) {
16+
return initialState;
17+
}
18+
19+
switch (action.type) {
20+
case UPDATE:
21+
return update(state, action);
22+
case RESET: return initialState;
23+
default:
24+
return state;
25+
}
26+
};
27+
28+
const updateCommentForm = (payload) => {
29+
return {type: UPDATE, payload};
30+
};
31+
32+
const resetCommentForm = () => {
33+
return {type: RESET};
34+
};
35+
36+
export const actions = {
37+
updateCommentForm,
38+
resetCommentForm
39+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import { fromJS } from 'immutable';
2+
3+
const CREATE = 'COMMENTS_STORE:CREATE';
4+
5+
export const initialState = fromJS({
6+
meta: {}
7+
});
8+
9+
const create = (state, action) => {
10+
return state.merge(action.entities);
11+
};
12+
13+
export default (state, action) => {
14+
if (!state) {
15+
return initialState;
16+
}
17+
18+
switch (action.type) {
19+
case CREATE:
20+
return create(state, action);
21+
default:
22+
return state;
23+
}
24+
};
25+
26+
const createComments = (entities) => {
27+
return {type: CREATE, entities};
28+
};
29+
30+
export const actions = {
31+
createComments,
32+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import { Map } from 'immutable';
2+
import { combineReducers } from 'redux-immutable';
3+
import commentsStoreReducer, {
4+
initialState as commentsStoreInitialState,
5+
actions as commentsStoreActions
6+
} from './commentsStoreReducer';
7+
8+
import commentFormReducer, {
9+
initialState as commentFormInitialState,
10+
actions as commentFormActions
11+
} from './commentFormReducer';
12+
13+
14+
export default combineReducers({
15+
comments: commentsStoreReducer,
16+
commentForm: commentFormReducer
17+
});
18+
19+
export const initialState = Map({
20+
comments: commentsStoreInitialState,
21+
commentForm: commentFormInitialState
22+
});
23+
24+
export const actions = {
25+
...commentsStoreActions,
26+
...commentFormActions
27+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export default state => state.get('commentForm')
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export default state => state.get('commentsStore')
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
export default function logger({ getState }) {
2+
return next => action => {
3+
console.info('will dispatch action', action);
4+
const result = next(action);
5+
const state = getState();
6+
console.info('state after dispatch', state.toJS());
7+
return result;
8+
};
9+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import _ from 'lodash/fp';
2+
3+
import commentsSagas from '../bundles/comments/sagas';
4+
5+
const sagas = [
6+
...commentsSagas,
7+
];
8+
9+
const sagaIterators = _.map(saga => saga && saga(), sagas);
10+
11+
function* appSaga() {
12+
yield sagaIterators;
13+
}
14+
15+
export default appSaga;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { applyMiddleware, compose, createStore } from 'redux';
2+
import createSagaMiddleware from 'redux-saga';
3+
4+
import loggerMiddleware from './loggerMiddleware';
5+
import appReducer, { initialState } from '../reducers';
6+
import appSaga from './sagas';
7+
8+
const sagaMiddleware = createSagaMiddleware();
9+
10+
let composedStore;
11+
if (__DEV__) {
12+
composedStore = compose(applyMiddleware(sagaMiddleware, loggerMiddleware));
13+
} else {
14+
composedStore = compose(applyMiddleware(sagaMiddleware));
15+
}
16+
const store = composedStore(createStore)(appReducer, initialState);
17+
18+
sagaMiddleware.run(appSaga);
19+
20+
export default store;
+3-52
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,4 @@
1-
/**
2-
* Sample React Native App
3-
* https://github.com/facebook/react-native
4-
* @flow
5-
*/
1+
import { AppRegistry } from 'react-native';
2+
import App from './app/App';
63

7-
import React, { Component } from 'react';
8-
import {
9-
AppRegistry,
10-
StyleSheet,
11-
Text,
12-
View
13-
} from 'react-native';
14-
15-
export default class ReactNativeTutorial extends Component {
16-
render() {
17-
return (
18-
<View style={styles.container}>
19-
<Text style={styles.welcome}>
20-
Welcome to React Native!
21-
</Text>
22-
<Text style={styles.instructions}>
23-
To get started, edit index.android.js
24-
</Text>
25-
<Text style={styles.instructions}>
26-
Double tap R on your keyboard to reload,{'\n'}
27-
Shake or press menu button for dev menu
28-
</Text>
29-
</View>
30-
);
31-
}
32-
}
33-
34-
const styles = StyleSheet.create({
35-
container: {
36-
flex: 1,
37-
justifyContent: 'center',
38-
alignItems: 'center',
39-
backgroundColor: '#F5FCFF',
40-
},
41-
welcome: {
42-
fontSize: 20,
43-
textAlign: 'center',
44-
margin: 10,
45-
},
46-
instructions: {
47-
textAlign: 'center',
48-
color: '#333333',
49-
marginBottom: 5,
50-
},
51-
});
52-
53-
AppRegistry.registerComponent('ReactNativeTutorial', () => ReactNativeTutorial);
4+
AppRegistry.registerComponent('ReactNativeTutorial', () => App);

0 commit comments

Comments
 (0)