mirror of
https://github.com/zhigang1992/react-navigation.git
synced 2026-04-27 21:08:02 +08:00
This makes the first navigation click work correctly, per https://github.com/react-navigation/react-navigation-redux-helpers/issues/7
47 lines
1.2 KiB
JavaScript
47 lines
1.2 KiB
JavaScript
import React from 'react';
|
|
import PropTypes from 'prop-types';
|
|
import { connect } from 'react-redux';
|
|
import { addNavigationHelpers, StackNavigator } from 'react-navigation';
|
|
import { initializeListeners } from 'react-navigation-redux-helpers';
|
|
|
|
import LoginScreen from '../components/LoginScreen';
|
|
import MainScreen from '../components/MainScreen';
|
|
import ProfileScreen from '../components/ProfileScreen';
|
|
import { addListener } from '../utils/redux';
|
|
|
|
export const AppNavigator = StackNavigator({
|
|
Login: { screen: LoginScreen },
|
|
Main: { screen: MainScreen },
|
|
Profile: { screen: ProfileScreen },
|
|
});
|
|
|
|
class AppWithNavigationState extends React.Component {
|
|
static propTypes = {
|
|
dispatch: PropTypes.func.isRequired,
|
|
nav: PropTypes.object.isRequired,
|
|
};
|
|
|
|
componentDidMount() {
|
|
initializeListeners('root', this.props.nav);
|
|
}
|
|
|
|
render() {
|
|
const { dispatch, nav } = this.props;
|
|
return (
|
|
<AppNavigator
|
|
navigation={addNavigationHelpers({
|
|
dispatch,
|
|
state: nav,
|
|
addListener,
|
|
})}
|
|
/>
|
|
);
|
|
}
|
|
}
|
|
|
|
const mapStateToProps = state => ({
|
|
nav: state.nav,
|
|
});
|
|
|
|
export default connect(mapStateToProps)(AppWithNavigationState);
|