Skip to content

Commit

Permalink
[location] Fix the navigator.geolocation polyfill (expo#16019)
Browse files Browse the repository at this point in the history
  • Loading branch information
tsapeta authored Jan 25, 2022
1 parent f015d49 commit 003a5b4
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 2 deletions.
2 changes: 1 addition & 1 deletion packages/expo-location/build/GeolocationPolyfill.d.ts.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions packages/expo-location/build/GeolocationPolyfill.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/expo-location/build/GeolocationPolyfill.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions packages/expo-location/src/GeolocationPolyfill.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,22 @@ type GeolocationOptions = {
enableHighAccuracy?: boolean;
};

declare const global: any;

// @needsAudit
/**
* Polyfills `navigator.geolocation` for interop with the core React Native and Web API approach to geolocation.
*/
export function installWebGeolocationPolyfill(): void {
if (Platform.OS !== 'web') {
// Make sure `window.navigator` is defined in the global scope.
if (!('window' in global)) {
global.window = global;
}
if (!('navigator' in global.window)) {
global.window.navigator = {};
}

// @ts-ignore
window.navigator.geolocation = {
getCurrentPosition,
Expand Down

0 comments on commit 003a5b4

Please sign in to comment.