-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathstate.js
38 lines (34 loc) · 821 Bytes
/
state.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
import React, { Component } from 'react';
import {
StyleSheet,
Text,
View,
TouchableHighlight,
AppState,
ToastAndroid,
} from 'react-native';
var state = React.createClass({
getInitialState() {
return {
currentAppState: AppState.currentState,
};
},
componentDidMount() {
AppState.addEventListener('change', this._handleAppStateChange);
},
componentWillUnmount() {
AppState.removeEventListener('change', this._handleAppStateChange);
},
_handleAppStateChange(currentAppState) {
this.setState({ currentAppState, });
ToastAndroid.show('当前状态为:'+currentAppState,ToastAndroid.SHORT);
},
render(){
return (
<Text>Current state is: {this.state.currentAppState}</Text>
);
},
});
var styles = StyleSheet.create({
});
module.exports = state;