我想在我的app.js文件中集成redux mapstatepros。为什么?因为当我的模式出现时,我需要触发模糊效果。因此,让我们假设我有以下app.js
import React, {Component} from 'react';
import {createStackNavigator, createAppContainer} from 'react-navigation';
import {Provider} from 'react-redux';
import { PersistGate } from 'redux-persist/integration/react'
import store, { persistor } from './src/js/store';
import {createStore, applyMiddleware} from 'redux';
import Reducers from './src/Reducers';
import Preload from './src/screens/Preload';
let store = createStore(Reducers);
const AppNavigator = createStackNavigator({
Preload: {
screen: Preload,
},
});
const AppContainer = createAppContainer(AppNavigator);
export default class App extends Component {
render () {
return (
<Provider store={store}>
<PersistGate loading={null} persistor={persistor}>
<AppContainer />
</PersistGate>
</Provider>
)
}
我需要做类似以下操作的事情,但是当我的状态改变时,模糊不会触发。
import React, {Component} from 'react';
import {createStackNavigator, createAppContainer} from 'react-navigation';
import {Provider} from 'react-redux';
import { findNodeHandle } from 'react-native';
import { PersistGate } from 'redux-persist/integration/react'
import store, { persistor } from './src/js/store';
import {createStore, applyMiddleware} from 'redux';
import { BlurView } from 'react-native-blur';
import Reducers from './src/Reducers';
import Preload from './src/screens/Preload';
let store = createStore(Reducers);
const AppNavigator = createStackNavigator({
Preload: {
screen: Preload,
},
});
onViewLoaded() {
this.setState({ viewRef: findNodeHandle(this.viewRef) });
}
function mapStateToProps(state) {
return {
modalIsOpened: state.modalReducer.modalIsOpened,
}
}
const AppContainer = connect(mapStateToProps)(createAppContainer(AppNavigator));
export default class App extends Component {
render () {
return (
<Provider store={store}>
<PersistGate loading={null} persistor={persistor}>
<AppContainer
ref={(viewRef) => { this.viewRef = viewRef; }}
onLayout={() => { this.onViewLoaded(); }}
/>
{modalIsOpened && <BlurView
style={{
position: "absolute",
top: 0,
left: 0,
bottom: 0,
right: 0
}}
viewRef={this.state.viewRef}
blurType="dark"
blurAmount={5}
blurRadius={5}
/>}
</PersistGate>
</Provider>
)
}
希望我清楚自己:)
您是在此处将modalIsOpened
Prop映射到<AppContainer>
,但期望它存在于<App>
。
将<Blur>
移动到<AppContainer>
中并映射其内部的道具。