forked from osdio/noder-react-native
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUtils.js
More file actions
75 lines (64 loc) · 1.54 KB
/
Utils.js
File metadata and controls
75 lines (64 loc) · 1.54 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
import React, {Component} from 'react';
import {Platform, View, StyleSheet, Text, StatusBar, AppState} from 'react-native';
import Toast from '../components/base/Toast';
import * as codePushUtils from '../utils/codePushSync';
class Utils extends Component {
componentDidMount() {
const {actions} = this.props;
actions.getReducerFromAsyncStorage(({user})=> {
if (user && user.secret) {
actions.getUnreadMessageCount();
}
});
if (Platform.OS !== 'web') {
codePushUtils.sync();
AppState.addEventListener("change", (newState) => {
if (newState === "active") {
codePushUtils.sync();
this.props.user.secret && actions.getUnreadMessageCount();
}
});
}
// if (__DEV__) {
// actions.checkToken('your secretKey', ()=> {
// actions.toast('登陆成功');
// });
// }
}
componentWillReceiveProps(nextProps) {
if (this.props.toast.id !== nextProps.toast.id) {
this.toast.show(nextProps.toast.text, nextProps.toast.timeout);
}
}
render() {
if (Platform.OS === 'web') {
return (
<View style={styles.container}>
<Toast ref={ (view)=> this.toast=view }/>
</View>
);
} else {
return (
<View style={styles.container}>
<StatusBar barStyle="light-content"/>
<Toast ref={ (view)=> this.toast=view }/>
</View>
);
}
}
}
const styles = StyleSheet.create({
container: {
position: 'absolute',
top: 0,
left: 0
}
});
export const LayoutComponent = Utils;
export function mapStateToProps(state) {
const {utils = {}, user} = state;
return {
...utils,
user
}
}