Skip to content

Commit 45bd2b5

Browse files
cpojerfacebook-github-bot
authored andcommitted
Remove navigator.geolocation, use Geolocation
Summary: This is the first diff in an effort to remove Geolocation from React Native. This diff removes the globally injected navigator.geolocation feature and instead requires explicit importing of `Geolocation`. When using Web APIs, people will need to patch `navigator.geolocation` on their own from now on. Reviewed By: sahrens Differential Revision: D14692386 fbshipit-source-id: c57b290b49728101250d726d67b1956ff23a9a92
1 parent 11ac06f commit 45bd2b5

File tree

4 files changed

+8
-12
lines changed

4 files changed

+8
-12
lines changed

Libraries/Core/InitializeCore.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ require('setUpRegeneratorRuntime');
3737
require('setUpTimers');
3838
require('setUpXHR');
3939
require('setUpAlert');
40-
require('setUpGeolocation');
40+
require('setUpNavigator');
4141
require('setUpBatchedBridge');
4242
require('setUpSegmentFetcher');
4343
if (__DEV__) {
Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,10 @@
1111

1212
const {polyfillObjectProperty} = require('PolyfillFunctions');
1313

14-
/**
15-
* Set up Geolocation.
16-
* You can use this module directly, or just require InitializeCore.
17-
*/
1814
let navigator = global.navigator;
1915
if (navigator === undefined) {
2016
global.navigator = navigator = {};
2117
}
2218

2319
// see https://github.com/facebook/react-native/issues/10881
2420
polyfillObjectProperty(navigator, 'product', () => 'ReactNative');
25-
polyfillObjectProperty(navigator, 'geolocation', () => require('Geolocation'));

Libraries/Geolocation/Geolocation.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,11 @@ type GeoConfiguration = {
2929
skipPermissionRequests: boolean,
3030
};
3131

32-
type GeoOptions = {
32+
export type GeoOptions = {
3333
timeout?: number,
3434
maximumAge?: number,
3535
enableHighAccuracy?: boolean,
36-
distanceFilter: number,
36+
distanceFilter?: number,
3737
useSignificantChanges?: boolean,
3838
};
3939

RNTester/js/GeolocationExample.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
'use strict';
1212

13+
import Geolocation from 'Geolocation';
1314
const React = require('react');
1415
const ReactNative = require('react-native');
1516
const {StyleSheet, Text, View, Alert} = ReactNative;
@@ -23,22 +24,22 @@ class GeolocationExample extends React.Component<{}, $FlowFixMeState> {
2324
watchID: ?number = null;
2425

2526
componentDidMount() {
26-
navigator.geolocation.getCurrentPosition(
27+
Geolocation.getCurrentPosition(
2728
position => {
2829
const initialPosition = JSON.stringify(position);
2930
this.setState({initialPosition});
3031
},
3132
error => Alert.alert('Error', JSON.stringify(error)),
3233
{enableHighAccuracy: true, timeout: 20000, maximumAge: 1000},
3334
);
34-
this.watchID = navigator.geolocation.watchPosition(position => {
35+
this.watchID = Geolocation.watchPosition(position => {
3536
const lastPosition = JSON.stringify(position);
3637
this.setState({lastPosition});
3738
});
3839
}
3940

4041
componentWillUnmount() {
41-
this.watchID != null && navigator.geolocation.clearWatch(this.watchID);
42+
this.watchID != null && Geolocation.clearWatch(this.watchID);
4243
}
4344

4445
render() {
@@ -69,7 +70,7 @@ exports.description = 'Examples of using the Geolocation API.';
6970

7071
exports.examples = [
7172
{
72-
title: 'navigator.geolocation',
73+
title: 'Geolocation',
7374
render: function(): React.Element<any> {
7475
return <GeolocationExample />;
7576
},

0 commit comments

Comments
 (0)