-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAppContainer.js
74 lines (67 loc) · 2.07 KB
/
AppContainer.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import React, {Component} from 'react';
import {View, Text} from 'react-native';
import {connect} from 'react-redux';
import {bindActionCreators} from 'redux';
import NetInfo from '@react-native-community/netinfo';
import * as appActionCreator from './redux/action/appAction';
import Internet from './screen/Internet';
import LoadingComponent from './screen/LodingComponent';
import NavigationService from './redux/NavigationService';
import AppNavigator from './AppNavigator';
class AppContainer extends Component {
constructor(props) {
super(props);
this.state = {
isInternetWarningShow: false,
};
}
componentDidMount() {
NetInfo.addEventListener(this._handleConnectivityChange);
}
_handleConnectivityChange = state => {
this.props.appActions.isConnectionStateChanged(state.isConnected);
};
componentWillUnmount() {
NetInfo.removeEventListener(this._handleConnectivityChange);
}
onTryAgainClick = () => {
if (this.props.isConnected) {
this.props.appActions.isConnectionStateChanged(true);
} else {
this.setState({isInternetWarningShow: true});
setTimeout(() => {
this.setState({isInternetWarningShow: false});
}, 2000);
}
};
render() {
return (
<View style={{flex: 1,}}>
<AppNavigator
ref={navigatorRef => {
NavigationService.setTopLevelNavigator(navigatorRef);
}}
/>
{this.props.isLoading ? <LoadingComponent /> : <View />}
{!this.props.isConnected && this.props.isConnected !== undefined ? (
<Internet
onTryAgainClick={this.onTryAgainClick}
isInternetWarningShow={this.state.isInternetWarningShow}
/>
) : (
<View />
)}
</View>
);
}
}
function mapStateToProps(state) {
return {
isLoading: state.appReducer.isLoading,
isConnected: state.appReducer.isConnected,
};
}
const mapDispatchToProps = dispatch => ({
appActions: bindActionCreators(appActionCreator, dispatch),
});
export default connect(mapStateToProps, mapDispatchToProps)(AppContainer);