Я новичок в React-native, пытаюсь использовать хранилище React-redux, но его не вызывает метод редуктора, пожалуйста, помогите мне, где я допустил ошибку.
создаю мобильное приложение от React Native и Redux.
Кажется, что мои действия, состояние работают правильно, потому что я сделал console.log их.
Проблема здесь в том, что мой редуктор не вызывается.
Я сделал журналэто на консоли, но нет результата.
Я не знаю, что вызывает это.
Index.js
import {AppRegistry} from 'react-native';
import React from 'react'
import App from './App'
import {name as appName} from './app.json';
import {Provider} from 'react-redux';
import configureStore from './Components/Store/configureStore'
const store = configureStore();
const RNRedux = () => (
<Provider store = {store}>
<App />
</Provider>
)
AppRegistry.registerComponent(appName, () => RNRedux);
APP.js
import React, {Component} from 'react';
import {Platform,Text, ScrollView,StyleSheet,KeyboardAvoidingView,Image,TouchableOpacity, View,Button,TextInput,ImageBackground} from 'react-native';
import jnpBgImage from './Components/Assets/Login_BG_Image.png'
import jnpImageTitle from './Components/Assets/jnptextlogo.png'
import {uiStartLoading, uiStopLoading} from './Components/Store/actions/index'
import {connect} from 'react-redux';
const instructions = Platform.select({
ios: 'Press Cmd+R to reload,\n' + 'Cmd+D or shake for dev menu',
android:
'Double tap R on your keyboard to reload,\n' +
'Shake or press menu button for dev menu',
});
class App extends Component {
startLoadHandler = () =>{
this.props.startLoad();
}
stopLoadHandler = () =>{
this.props.stopLoad();
}
render() {
return (
<View style={{flex :1}}>
<ImageBackground
resizeMode={'stretch'} // or cover
style={{flex: 1}} // must be passed from the parent, the number may vary depending upon your screen size
source={jnpBgImage}
>
<ScrollView contentContainerStyle={{flex:1}} showsVerticalScrollIndicator = {false}>
<View style = {styles.container}>
<Image style={styles.logo} source={jnpImageTitle} />
<TextInput placeholder = 'User Name'
selectionColor = 'blue'
// value={this.state.username}
// onChangeText={username => this.setState({username})}
style = {styles.input}>
</TextInput>
<TextInput secureTextEntry = {true}
placeholder = 'Password'
//value={this.state.password}
//onChangeText={password => this.setState({password})}
style = {styles.input}
></TextInput>
<View style = {styles.helpContainer}>
<TouchableOpacity
onPress={() => this.props.navigation.navigate('WebView',{nTitle : 'Help',url : 'https://jobsnprofiles.com/mobile/contact-sales.html'})}
>
<Text style = {{color : '#663333'}}>Need Help?</Text>
</TouchableOpacity>
<TouchableOpacity
//onPress={() => this.props.navigation.navigate('ForgotPassword')}
>
<Text style = {{textDecorationLine: 'underline'}}>Forgor Password</Text>
</TouchableOpacity>
</View>
<View>
<TouchableOpacity
style={styles.button}
// onPress={this.onLoginPress.bind(this)}
onPress={this.startLoadHandler}
>
<Text style={styles.buttonText}>SignIn</Text>
</TouchableOpacity>
<TouchableOpacity style={styles.button}>
<Text
style={styles.buttonText}
//onPress={() => this.props.navigation.navigate('Registration')}
onPress={this.stopLoadHandler}
// title="Sign up"
>
Signup
</Text>
</TouchableOpacity>
</View>
</View>
</ScrollView>
</ImageBackground>
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex : 1,
justifyContent : 'center',
alignItems : 'center',
// borderRadius : 2,
// borderColor :'red'
},
logo: {
width: 300,
height: 80 ,
marginBottom : 40
},
Scrollcontainer: {
flex : 1,
borderRadius : 2,
borderColor :'red'
},
helpContainer :{
flexDirection : 'row',
justifyContent : 'space-between',
width : '80%',
},
input : {
width : '80%',
height : 40,
backgroundColor: '#BDBDBD',
color: "black",
paddingHorizontal: 20,
borderRadius : 5,
marginBottom : 10,
},
button: {
backgroundColor: "#663333",
paddingVertical: 10,
width : 200,
justifyContent : 'center',
alignItems : 'center',
marginTop : 10,
borderWidth: 1,
borderRadius: 10,
borderColor: '#663333'
},
buttonText: {
textAlign: "center",
color: "#FFF",
fontWeight: "700",
},
});
const mapsStateToProps = (state) =>{
return {
isLoading : state.isLoading.isLoading
}
};
const mapDispatchToProps = (dispatch) => {
return {
startLoad : () => dispatch(uiStartLoading),
stopLoad : () => dispatch(uiStopLoading)
};
};
export default connect(mapsStateToProps,mapDispatchToProps)(App);
ActionType.js
export const UI_START_LOADIG = 'UI_START_LOADIG';
export const UI_STOP_LOADIG = 'UI_STOP_LOADIG';
ui.js (редуктор)
import { UI_START_LOADING, UI_STOP_LOADING } from "../actions/actionTypes";
const initialState = {
isLoading : false
};
const reducer = ( state = initialState, action) => {
// This method is not trigging
console.log('calling reducer')
switch (action.type) {
case UI_START_LOADING:
return {
...state,
isLoading: true
};
case UI_STOP_LOADING:
return {
...state,
isLoading: false
};
default:
return state;
}
};
export default reducer;
ui.js (действие)
import {UI_START_LOADIG,UI_STOP_LOADIG} from './actionTypes';
export const uiStartLoading = () => {
console.log('loading')
return{
type : UI_START_LOADIG
};
};
export const uiStopLoading = () => {
console.log('stop loading')
return{
type : UI_STOP_LOADIG
};
};
configureStore.js
import thunk from "redux-thunk";
import uiReducers from './reducers/ui'
const rootReducers = combineReducers({
isLoading : uiReducers
});
let composeEnhancers = compose;
if (__DEV__) {
composeEnhancers = window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ || compose;
}
const configureStore = () => {
return createStore(rootReducers, composeEnhancers(applyMiddleware(thunk)))
}
export default configureStore;
index.js (действие)
export { uiStartLoading,uiStopLoading} from '../actions/ui'