-
Notifications
You must be signed in to change notification settings - Fork 0
/
App.js
91 lines (89 loc) · 2.22 KB
/
App.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
/**
* Sample React Native App
* https://github.com/facebook/react-native
* @flow
*/
import React, { Component } from 'react';
import {
NetInfo,
Animated,
StyleSheet,
View,
Text,
Platform,
} from 'react-native';
import global from './app/common/global';
import NetInfoDecorator from './app/common/NetInfoDecorator';
import Root from './app/Root';
global.nowRouteName='';
console.disableYellowBox = true;
@NetInfoDecorator
export default class App extends Component<{}> {
constructor(props) {
super(props);
this.state = {
promptPosition: new Animated.Value(0),
}
}
componentWillReceiveProps(nextProps) {
const {isConnected} = nextProps
// 无网络
if (!isConnected) {
Animated.timing(this.state.promptPosition, {
toValue: 1,
duration: 200
}).start(() => {
setTimeout(() => {
Animated.timing(this.state.promptPosition, {
toValue: 0,
duration: 200
}).start()
}, 2000);
})
}
}
render() {
let positionY = this.state.promptPosition.interpolate({
inputRange: [
0, 1
],
outputRange: [
-30, Platform.OS === 'ios'
? 20
: 0
]
});
return (
<View style={styles.container}>
<Root onNavigationStateChange={(prevState,currentState)=>{
nowRouteName = currentState.routes[currentState.routes.length-1].routeName;
}} />
<Animated.View style={[
styles.netInfoView, {
top: positionY
}
]}>
<Text style={styles.netInfoPrompt}>网络异常,请检查网络稍后重试~</Text>
</Animated.View>
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
},
netInfoView: {
justifyContent: 'center',
alignItems: 'center',
height: 30,
position: 'absolute',
right: 0,
left: 0,
backgroundColor: 'rgb(217, 51, 58)'
},
netInfoPrompt: {
color: 'white',
fontWeight: 'bold'
}
});