-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7 from theliturgists/redux-start
Wire up redux and react-navigation
- Loading branch information
Showing
16 changed files
with
302 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
import { AppRegistry } from 'react-native'; | ||
import App from './src/App'; | ||
import Root from './src/Root'; | ||
|
||
AppRegistry.registerComponent('app', () => App); | ||
AppRegistry.registerComponent('app', () => Root); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import React from 'react'; | ||
import { Provider } from 'react-redux'; | ||
|
||
import AppNavigator from './navigators/AppNavigator'; | ||
import configureStore from './state/store'; | ||
|
||
const Root = () => ( | ||
<Provider store={configureStore()}> | ||
<AppNavigator /> | ||
</Provider> | ||
); | ||
|
||
export default Root; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
// Bootstrapped from the example app at https://reactnavigation.org/docs/guides/redux | ||
|
||
import React, { Component } from 'react'; | ||
import PropTypes from 'prop-types'; | ||
|
||
import { BackHandler } from 'react-native'; | ||
import { connect } from 'react-redux'; | ||
import { TabNavigator, addNavigationHelpers, NavigationActions } from 'react-navigation'; | ||
|
||
import LoginScreen from '../screens/LoginScreen'; | ||
import MainNavigator from './MainNavigator'; | ||
|
||
export const RawNavigator = TabNavigator({ | ||
Login: { screen: LoginScreen }, | ||
Main: { screen: MainNavigator }, | ||
}, { | ||
navigationOptions: { | ||
tabBarVisible: false, | ||
}, | ||
}); | ||
|
||
class AppNavigator extends Component { | ||
componentDidMount() { | ||
BackHandler.addEventListener('hardwareBackPress', this.onBackPress); | ||
} | ||
|
||
componentWillUnmount() { | ||
BackHandler.removeEventListener('hardwareBackPress', this.onBackPress); | ||
} | ||
|
||
onBackPress() { | ||
const { dispatch, nav } = this.props; | ||
if (nav.index === 0) { | ||
return false; | ||
} | ||
dispatch(NavigationActions.back()); | ||
return true; | ||
} | ||
|
||
render() { | ||
const { dispatch, nav } = this.props; | ||
const navigation = addNavigationHelpers({ | ||
dispatch, | ||
state: nav, | ||
}); | ||
|
||
return <RawNavigator navigation={navigation} />; | ||
} | ||
} | ||
|
||
AppNavigator.propTypes = { | ||
dispatch: PropTypes.func.isRequired, | ||
|
||
nav: PropTypes.shape({}).isRequired, | ||
}; | ||
|
||
function mapStateToProps(state) { | ||
return { | ||
nav: state.navigation, | ||
}; | ||
} | ||
|
||
export default connect(mapStateToProps)(AppNavigator); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { TabNavigator } from 'react-navigation'; | ||
|
||
import HomeScreen from '../screens/HomeScreen'; | ||
import PodcastsScreen from '../screens/PodcastsScreen'; | ||
|
||
export default TabNavigator({ | ||
Home: { screen: HomeScreen }, | ||
Podcasts: { screen: PodcastsScreen }, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { Text, View, Button } from 'react-native'; | ||
|
||
import * as navActions from '../state/ducks/navigation/actions'; | ||
|
||
const HomeScreen = ({ navigation }) => ( | ||
<View> | ||
<Text> | ||
Placeholder home screen | ||
</Text> | ||
<Button | ||
onPress={() => navigation.dispatch(navActions.logout())} | ||
title="Log out" | ||
/> | ||
</View> | ||
); | ||
|
||
HomeScreen.propTypes = { | ||
navigation: PropTypes.shape({ | ||
dispatch: PropTypes.func.isRequired, | ||
}).isRequired, | ||
}; | ||
|
||
export default HomeScreen; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { Text, View, Button } from 'react-native'; | ||
|
||
import * as navActions from '../state/ducks/navigation/actions'; | ||
|
||
const LoginScreen = ({ navigation }) => ( | ||
<View> | ||
<Text> | ||
Placeholder login screen | ||
</Text> | ||
<Button | ||
onPress={() => navigation.dispatch(navActions.login())} | ||
title="Log in" | ||
/> | ||
</View> | ||
); | ||
|
||
LoginScreen.propTypes = { | ||
navigation: PropTypes.shape({ | ||
dispatch: PropTypes.func.isRequired, | ||
}).isRequired, | ||
}; | ||
|
||
export default LoginScreen; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { Text, View, Button } from 'react-native'; | ||
|
||
import * as navActions from '../state/ducks/navigation/actions'; | ||
|
||
const PodcastsScreen = ({ navigation }) => ( | ||
<View> | ||
<Text> | ||
Placeholder podcasts screen | ||
</Text> | ||
<Button | ||
onPress={() => navigation.dispatch(navActions.logout())} | ||
title="Log out" | ||
/> | ||
</View> | ||
); | ||
|
||
PodcastsScreen.propTypes = { | ||
navigation: PropTypes.shape({ | ||
dispatch: PropTypes.func.isRequired, | ||
}).isRequired, | ||
}; | ||
|
||
export default PodcastsScreen; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { default as navigation } from './navigation'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import { NavigationActions } from 'react-navigation'; | ||
|
||
export const login = () => NavigationActions.navigate({ routeName: 'Main' }); | ||
export const logout = () => NavigationActions.navigate({ routeName: 'Login' }); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { default } from './reducer'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
// Bootstrapped from the example app at https://reactnavigation.org/docs/guides/redux | ||
|
||
import { RawNavigator } from '../../../navigators/AppNavigator'; | ||
|
||
const initialAction = RawNavigator.router.getActionForPathAndParams('Login'); | ||
const initialState = RawNavigator.router.getStateForAction(initialAction); | ||
|
||
export default function reducer(state = initialState, action) { | ||
const nextState = RawNavigator.router.getStateForAction(action, state); | ||
return nextState || state; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { combineReducers, createStore } from 'redux'; | ||
|
||
import * as reducers from './ducks'; | ||
|
||
export default function configureStore() { | ||
const reducer = combineReducers(reducers); | ||
return createStore(reducer); | ||
} |
Oops, something went wrong.