index.js
6.32 KB
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
/**
* Created by Cassie on 2018/03/06
*/
import React, { Component } from 'react';
import {
StyleSheet,
View,
Text,
NativeModules,
NetInfo,
Platform,
ActivityIndicator,
DeviceEventEmitter,
AsyncStorage,
BackHandler,
Keyboard
} from 'react-native';
import {StackNavigator} from 'react-navigation';
import {zoomW,zoomH} from "./utils/getSize";
import {xnToast} from "./utils/utils";
import Home from './pages/home';
import MomentScreen from './pages/screens/MomentScreen';
import ImageShow from './pages/screens/ImageShowScreen';
import PublishMomentScreen from './pages/screens/PublishMomentScreen';
import CommonLoadingView from './pages/views/CommonLoadingView';
import CommonTitleBar from './pages/views/CommonTitleBar';
import EmojiView from './pages/views/EmojiView';
import ListItem from './pages/views/ListItem';
import ListItemDivider from './pages/views/ListItemDivider';
import LoadingView from './pages/views/LoadingView';
import MomentMenuView from './pages/views/MomentMenuView';
import MoreView from './pages/views/MoreView';
import PopupWindow from './pages/views/PopupWindow';
import ReplyPopWin from './pages/views/ReplyPopWin';
import SideBar from './pages/views/SideBar';
import ImgView from './pages/views/imgView';
import MomentCommentView from "./pages/views/MomentCommentView";
const Navigator = StackNavigator(
{
MomentScreen:{screen:MomentScreen},
ImageShow:{screen:ImageShow},
PublishMomentScreen:{screen:PublishMomentScreen},
CommonTitleBar:{screen:CommonTitleBar},
CommonLoadingView:{screen:CommonLoadingView},
EmojiView:{screen:EmojiView},
ListItem:{screen:ListItem},
ListItemDivider:{screen:ListItemDivider},
LoadingView:{screen:LoadingView},
MomentMenuView:{screen:MomentMenuView},
MoreView:{screen:MoreView},
PopupWindow:{screen:PopupWindow},
ReplyPopWin:{screen:ReplyPopWin},
ImgView:{screen:ImgView},
SideBar:{screen:SideBar},
Home:{screen:Home},
MomentCommentView:{screen:MomentCommentView}
},
{
navigationOptions:({navigation}) => ({
headerStyle:{
elevation:0, // 去掉阴影
backgroundColor:'#fff',
borderBottomWidth:0,
height:(48/zoomH)
},
headerTitleStyle:{
alignSelf:'center',
alignItems:'center',
justifyContent:'center',
flexDirection:'column',
color:'#000',
fontSize:18,
fontWeight:'bold',
}
})
},
);
class App extends Component{
constructor(props){
super(props);
this.state = {
loading:true
};
}
componentWillMount(){
this.setState({
loading:false
})
//todo 网络先设置为true
global.isConnected = true;
let _this = this;
NetInfo.addEventListener('change',function(isConnected){
if(isConnected.toLocaleLowerCase() != 'none'){
global.isConnected = true;
/*global.tenantId = __IOS__ ?JSON.parse(global.initParam.passport).passport.tenantId:JSON.parse(global.initParam.passport).tenantId;
global.userId = __IOS__ ?JSON.parse(global.initParam.passport).passport.userId:JSON.parse(global.initParam.passport).userId;
AsyncStorage.getItem('draft', function (errs, result) {
if(!errs){
if(result){
let params = JSON.parse(result);
if(global.userId != params.userId){
AsyncStorage.clear(function(){
_this.setState({
loading:false
});
})
}else{
_this.setState({
loading:false
});
}
}else{
_this.setState({
loading:false
});
}
}
});*/
}else{
_this.setState({
loading:false
});
global.isConnected = false;
xnToast('暂无网络连接111,请稍后重试!')
}
});
/*NativeModules.security.getIdentityId().then((result) => {
AppService.getIdentity({id:result}).then(data=>{
if(data.message) {
xnToast(data.message);
return
}
if(data.errors.length > 0) {
xnToast(data.errors[0].message);
}else{
this.state.loading = false;
global.passportId = data.passport.id;
global.userId = data.passport.userId;
global.userName = data.passport.userName;
}
});
}
).catch((error) => {
console.log(error)
});
*/
}
render() {
return (
<View style={styles.root}>
{!this.state.loading && <Navigator />}
{this.state.loading && <View style={styles.loadingBg}>
<View style={styles.loadingBox}>
<ActivityIndicator size='large' color='#fff' />
<Text style={{fontSize:16,color:'#fff',marginTop:(6/zoomH)}}>加载中...</Text>
</View>
</View>}
</View>
);
}
}
const styles = StyleSheet.create({
root:{
flex:1
},
loadingBg:{
position:'absolute',
top:0,
width:'100%',
height:'100%',
display:'flex',
justifyContent:'center',
alignItems:'center'
},
loadingBox:{
width:(100/zoomW),
height:(120/zoomH),
backgroundColor:'rgba(0,0,0,.5)',
borderRadius:8,
display:'flex',
alignItems:'center',
justifyContent:'center'
}
});
export default App;