mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-02-11 22:32:38 +08:00
Updates from Mon Mar 2
- [ReactNative] Move merge & mergeInto from downstream to vendor | Christopher Chedeau - [ReactNative] Replace all the call sites of mergeInto by Object.assign | Christopher Chedeau - [WIP] Migrated View Managers over to new architecture | Nick Lockwood - [ReactNative] Replace all the call sites of copyProperties by Object.assign | Christopher Chedeau - [ReactNative] Migrate navigator.geolocation to open source | Christopher Chedeau - [ReactNative] Remove README.md, LICENSE and .travis.yml from fbobjc | Christopher Chedeau - [react-packager] Better transform errors | Amjad Masad - [React Native][react-packager] Fix test runner and fialing tests | Amjad Masad
This commit is contained in:
72
Examples/UIExplorer/GeoLocationExample.js
Normal file
72
Examples/UIExplorer/GeoLocationExample.js
Normal file
@@ -0,0 +1,72 @@
|
||||
/**
|
||||
* Copyright 2004-present Facebook. All Rights Reserved.
|
||||
*
|
||||
* @providesModule GeoLocationExample
|
||||
*/
|
||||
/* eslint no-console: 0 */
|
||||
'use strict';
|
||||
|
||||
|
||||
var React = require('react-native');
|
||||
var {
|
||||
StyleSheet,
|
||||
Text,
|
||||
View,
|
||||
} = React;
|
||||
|
||||
exports.framework = 'React';
|
||||
exports.title = 'GeoLocation';
|
||||
exports.description = 'Examples of using the GeoLocation API.';
|
||||
|
||||
exports.examples = [
|
||||
{
|
||||
title: 'navigator.geolocation',
|
||||
render: function() {
|
||||
return <GeoLocationExample />;
|
||||
},
|
||||
}
|
||||
];
|
||||
|
||||
var GeoLocationExample = React.createClass({
|
||||
getInitialState: function() {
|
||||
return {
|
||||
initialPosition: 'unknown',
|
||||
lastPosition: 'unknown',
|
||||
};
|
||||
},
|
||||
|
||||
componentDidMount: function() {
|
||||
navigator.geolocation.getCurrentPosition(
|
||||
(initialPosition) => this.setState({initialPosition}),
|
||||
(error) => console.error(error)
|
||||
);
|
||||
this.watchID = navigator.geolocation.watchPosition((lastPosition) => {
|
||||
this.setState({lastPosition});
|
||||
});
|
||||
},
|
||||
|
||||
componentWillUnmount: function() {
|
||||
navigator.geolocation.clearWatch(this.watchID);
|
||||
},
|
||||
|
||||
render: function() {
|
||||
return (
|
||||
<View>
|
||||
<Text>
|
||||
<Text style={styles.title}>Initial position: </Text>
|
||||
{JSON.stringify(this.state.initialPosition)}
|
||||
</Text>
|
||||
<Text>
|
||||
<Text style={styles.title}>Current position: </Text>
|
||||
{JSON.stringify(this.state.lastPosition)}
|
||||
</Text>
|
||||
</View>
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
var styles = StyleSheet.create({
|
||||
title: {
|
||||
fontWeight: 'bold',
|
||||
},
|
||||
});
|
||||
Reference in New Issue
Block a user