mirror of
https://github.com/zhigang1992/react-navigation.git
synced 2026-04-28 20:35:19 +08:00
[examples] Update ReduxExample (#4267)
Using two new utils: 1. `createNavigationPropConstructor`, which is now preferred over `createReduxBoundAddListener`. 2. `initializeListeners`, which is necessary to trigger the event listeners with the initial state.
This commit is contained in:
committed by
Brent Vatne
parent
046a9f8930
commit
f6c47a6c66
@@ -2,11 +2,12 @@ import React from 'react';
|
||||
import PropTypes from 'prop-types';
|
||||
import { connect } from 'react-redux';
|
||||
import { 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';
|
||||
import { navigationPropConstructor } from '../utils/redux';
|
||||
|
||||
export const AppNavigator = StackNavigator({
|
||||
Login: { screen: LoginScreen },
|
||||
@@ -20,17 +21,14 @@ class AppWithNavigationState extends React.Component {
|
||||
nav: PropTypes.object.isRequired,
|
||||
};
|
||||
|
||||
componentDidMount() {
|
||||
initializeListeners('root', this.props.nav);
|
||||
}
|
||||
|
||||
render() {
|
||||
const { dispatch, nav } = this.props;
|
||||
return (
|
||||
<AppNavigator
|
||||
navigation={{
|
||||
dispatch,
|
||||
state: nav,
|
||||
addListener,
|
||||
}}
|
||||
/>
|
||||
);
|
||||
const navigation = navigationPropConstructor(dispatch, nav);
|
||||
return <AppNavigator navigation={navigation} />;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,15 +1,12 @@
|
||||
import {
|
||||
createReactNavigationReduxMiddleware,
|
||||
createReduxBoundAddListener,
|
||||
createNavigationPropConstructor,
|
||||
} from 'react-navigation-redux-helpers';
|
||||
|
||||
const middleware = createReactNavigationReduxMiddleware(
|
||||
"root",
|
||||
state => state.nav,
|
||||
'root',
|
||||
state => state.nav
|
||||
);
|
||||
const addListener = createReduxBoundAddListener("root");
|
||||
const navigationPropConstructor = createNavigationPropConstructor('root');
|
||||
|
||||
export {
|
||||
middleware,
|
||||
addListener,
|
||||
};
|
||||
export { middleware, navigationPropConstructor };
|
||||
|
||||
Reference in New Issue
Block a user