Skip to content

Commit a1b4216

Browse files
authored
fix: Import the library correctly on native and web (#32)
1 parent a42d85d commit a1b4216

File tree

3 files changed

+68
-50
lines changed

3 files changed

+68
-50
lines changed

js/implementation.js

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/**
2+
* Copyright (c) Facebook, Inc. and its affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*
7+
* @format
8+
* @flow
9+
*/
10+
11+
type GeoOptions = {
12+
timeout: number,
13+
maximumAge: number,
14+
enableHighAccuracy: boolean,
15+
};
16+
17+
const Geolocation = {
18+
setRNConfiguration: function() {
19+
throw new Error('method not supported by the browser');
20+
},
21+
requestAuthorization: function() {
22+
throw new Error('method not supported by the browser');
23+
},
24+
getCurrentPosition: async function(
25+
success: Function,
26+
error?: Function,
27+
options?: GeoOptions,
28+
) {
29+
if (typeof success !== 'function') {
30+
throw new Error('success callback must be a function');
31+
} else if (!navigator || !navigator.geolocation) {
32+
console.error('Navigator is undefined');
33+
return;
34+
}
35+
navigator.geolocation.getCurrentPosition(success, error, options);
36+
},
37+
watchPosition: function(
38+
success: Function,
39+
error?: Function,
40+
options?: GeoOptions,
41+
) {
42+
if (typeof success !== 'function') {
43+
throw new Error('success callback must be a function');
44+
} else if (!navigator || !navigator.geolocation) {
45+
console.error('Navigator is undefined');
46+
return;
47+
}
48+
navigator.geolocation.watchPosition(success, error, options);
49+
},
50+
clearWatch: function(watchID: number) {
51+
if (!navigator || !navigator.geolocation) {
52+
console.error('Navigator is undefined');
53+
return;
54+
}
55+
navigator.geolocation.clearWatch(watchID);
56+
},
57+
stopObserving: function() {
58+
throw new Error('method not supported by the browser');
59+
},
60+
};
61+
module.exports = Geolocation;
File renamed without changes.

js/index.js

Lines changed: 7 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,13 @@
1-
/*
1+
/**
2+
* Copyright (c) Facebook, Inc. and its affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*
27
* @format
38
* @flow
49
*/
510

6-
type GeoOptions = {
7-
timeout: number,
8-
maximumAge: number,
9-
enableHighAccuracy: boolean,
10-
};
11+
import Geolocation from './implementation';
1112

12-
const Geolocation = {
13-
setRNConfiguration: function() {
14-
throw new Error('method not supported by the browser');
15-
},
16-
requestAuthorization: function() {
17-
throw new Error('method not supported by the browser');
18-
},
19-
getCurrentPosition: async function(
20-
success: Function,
21-
error?: Function,
22-
options?: GeoOptions,
23-
) {
24-
if (typeof success !== 'function') {
25-
throw new Error('success callback must be a function');
26-
} else if (!navigator || !navigator.geolocation) {
27-
console.error('Navigator is undefined');
28-
return;
29-
}
30-
navigator.geolocation.getCurrentPosition(success, error, options);
31-
},
32-
watchPosition: function(
33-
success: Function,
34-
error?: Function,
35-
options?: GeoOptions,
36-
) {
37-
if (typeof success !== 'function') {
38-
throw new Error('success callback must be a function');
39-
} else if (!navigator || !navigator.geolocation) {
40-
console.error('Navigator is undefined');
41-
return;
42-
}
43-
navigator.geolocation.watchPosition(success, error, options);
44-
},
45-
clearWatch: function(watchID: number) {
46-
if (!navigator || !navigator.geolocation) {
47-
console.error('Navigator is undefined');
48-
return;
49-
}
50-
navigator.geolocation.clearWatch(watchID);
51-
},
52-
stopObserving: function() {
53-
throw new Error('method not supported by the browser');
54-
},
55-
};
5613
module.exports = Geolocation;

0 commit comments

Comments
 (0)