mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Convert from React.createClass to ES6 classes
Reviewed By: cpojer Differential Revision: D3619143 fbshipit-source-id: e14e81468d467437ee3d79c34c34b7780a46ca1c
This commit is contained in:
committed by
Facebook Github Bot 8
parent
857d2b8eae
commit
a2fb703bbb
@@ -31,33 +31,36 @@ const {
|
||||
View
|
||||
} = ReactNative;
|
||||
|
||||
var AppStateSubscription = React.createClass({
|
||||
getInitialState() {
|
||||
return {
|
||||
appState: AppState.currentState,
|
||||
previousAppStates: [],
|
||||
memoryWarnings: 0,
|
||||
};
|
||||
},
|
||||
componentDidMount: function() {
|
||||
class AppStateSubscription extends React.Component {
|
||||
state = {
|
||||
appState: AppState.currentState,
|
||||
previousAppStates: [],
|
||||
memoryWarnings: 0,
|
||||
};
|
||||
|
||||
componentDidMount() {
|
||||
AppState.addEventListener('change', this._handleAppStateChange);
|
||||
AppState.addEventListener('memoryWarning', this._handleMemoryWarning);
|
||||
},
|
||||
componentWillUnmount: function() {
|
||||
}
|
||||
|
||||
componentWillUnmount() {
|
||||
AppState.removeEventListener('change', this._handleAppStateChange);
|
||||
AppState.removeEventListener('memoryWarning', this._handleMemoryWarning);
|
||||
},
|
||||
_handleMemoryWarning: function() {
|
||||
}
|
||||
|
||||
_handleMemoryWarning = () => {
|
||||
this.setState({memoryWarnings: this.state.memoryWarnings + 1});
|
||||
},
|
||||
_handleAppStateChange: function(appState) {
|
||||
};
|
||||
|
||||
_handleAppStateChange = (appState) => {
|
||||
var previousAppStates = this.state.previousAppStates.slice();
|
||||
previousAppStates.push(this.state.appState);
|
||||
this.setState({
|
||||
appState,
|
||||
previousAppStates,
|
||||
});
|
||||
},
|
||||
};
|
||||
|
||||
render() {
|
||||
if (this.props.showMemoryWarnings) {
|
||||
return (
|
||||
@@ -79,7 +82,7 @@ var AppStateSubscription = React.createClass({
|
||||
</View>
|
||||
);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
exports.title = 'AppState';
|
||||
exports.description = 'app background status';
|
||||
|
||||
Reference in New Issue
Block a user