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
@@ -45,17 +45,15 @@ exports.examples = [
|
||||
}
|
||||
];
|
||||
|
||||
var GeolocationExample = React.createClass({
|
||||
watchID: (null: ?number),
|
||||
class GeolocationExample extends React.Component {
|
||||
state = {
|
||||
initialPosition: 'unknown',
|
||||
lastPosition: 'unknown',
|
||||
};
|
||||
|
||||
getInitialState: function() {
|
||||
return {
|
||||
initialPosition: 'unknown',
|
||||
lastPosition: 'unknown',
|
||||
};
|
||||
},
|
||||
watchID: ?number = null;
|
||||
|
||||
componentDidMount: function() {
|
||||
componentDidMount() {
|
||||
navigator.geolocation.getCurrentPosition(
|
||||
(position) => {
|
||||
var initialPosition = JSON.stringify(position);
|
||||
@@ -68,13 +66,13 @@ var GeolocationExample = React.createClass({
|
||||
var lastPosition = JSON.stringify(position);
|
||||
this.setState({lastPosition});
|
||||
});
|
||||
},
|
||||
}
|
||||
|
||||
componentWillUnmount: function() {
|
||||
componentWillUnmount() {
|
||||
navigator.geolocation.clearWatch(this.watchID);
|
||||
},
|
||||
}
|
||||
|
||||
render: function() {
|
||||
render() {
|
||||
return (
|
||||
<View>
|
||||
<Text>
|
||||
@@ -88,7 +86,7 @@ var GeolocationExample = React.createClass({
|
||||
</View>
|
||||
);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
var styles = StyleSheet.create({
|
||||
title: {
|
||||
|
||||
Reference in New Issue
Block a user