diff --git a/packages/expo-location/build/GeolocationPolyfill.d.ts.map b/packages/expo-location/build/GeolocationPolyfill.d.ts.map index 7c9ef8671a8fef..112a22438a897a 100644 --- a/packages/expo-location/build/GeolocationPolyfill.d.ts.map +++ b/packages/expo-location/build/GeolocationPolyfill.d.ts.map @@ -1 +1 @@ -{"version":3,"file":"GeolocationPolyfill.d.ts","sourceRoot":"","sources":["../src/GeolocationPolyfill.ts"],"names":[],"mappings":"AAcA;;GAEG;AACH,wBAAgB,6BAA6B,IAAI,IAAI,CAapD"} \ No newline at end of file +{"version":3,"file":"GeolocationPolyfill.d.ts","sourceRoot":"","sources":["../src/GeolocationPolyfill.ts"],"names":[],"mappings":"AAgBA;;GAEG;AACH,wBAAgB,6BAA6B,IAAI,IAAI,CAqBpD"} \ No newline at end of file diff --git a/packages/expo-location/build/GeolocationPolyfill.js b/packages/expo-location/build/GeolocationPolyfill.js index 0247197d1f75fe..dce38b45c0e85e 100644 --- a/packages/expo-location/build/GeolocationPolyfill.js +++ b/packages/expo-location/build/GeolocationPolyfill.js @@ -8,6 +8,13 @@ import { LocationSubscriber } from './LocationSubscribers'; */ export function installWebGeolocationPolyfill() { 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, diff --git a/packages/expo-location/build/GeolocationPolyfill.js.map b/packages/expo-location/build/GeolocationPolyfill.js.map index 554ec780d31486..0af25ca3953be4 100644 --- a/packages/expo-location/build/GeolocationPolyfill.js.map +++ b/packages/expo-location/build/GeolocationPolyfill.js.map @@ -1 +1 @@ -{"version":3,"file":"GeolocationPolyfill.js","sourceRoot":"","sources":["../src/GeolocationPolyfill.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAE7C,OAAO,YAAY,MAAM,gBAAgB,CAAC;AAC1C,OAAO,EAAkB,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O,CAAC,CAAC;IAE7D,YAAY,CAAC,sBAAsB,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC,KAAK,CAAC,CAAC,GAAG,EAAE,EAAE;QAClE,kBAAkB,CAAC,kBAAkB,CAAC,OAAO,CAAC,CAAC;QAC/C,KAAK,CAAC,EAAE,OAAO,EAAE,OAAO,EAAE,GAAG,CAAC,OAAO,EAAE,IAAI,EAAE,GAAG,CAAC,IAAI,EAAE,CAAC,CAAC;IAC3D,CAAC,CAAC,CAAC;IAEH,OAAO,OAAO,CAAC;AACjB,CAAC;AAED,6CAA6C;AAC7C,SAAS,UAAU,CAAC,OAAe;IACjC,kBAAkB,CAAC,kBAAkB,CAAC,OAAO,CAAC,CAAC;AACjD,CAAC","sourcesContent":["import { Platform } from 'expo-modules-core';\n\nimport ExpoLocation from './ExpoLocation';\nimport { LocationObject, LocationAccuracy, LocationOptions } from './Location.types';\nimport { LocationSubscriber } from './LocationSubscribers';\n\ntype GeolocationSuccessCallback = (data: LocationObject) => void;\ntype GeolocationErrorCallback = (error: any) => void;\n\ntype GeolocationOptions = {\n enableHighAccuracy?: boolean;\n};\n\n// @needsAudit\n/**\n * Polyfills `navigator.geolocation` for interop with the core React Native and Web API approach to geolocation.\n */\nexport function installWebGeolocationPolyfill(): void {\n if (Platform.OS !== 'web') {\n // @ts-ignore\n window.navigator.geolocation = {\n getCurrentPosition,\n watchPosition,\n clearWatch,\n\n // We don't polyfill stopObserving, this is an internal method that probably should not even exist\n // in react-native docs\n stopObserving: () => {},\n };\n }\n}\n\nfunction convertGeolocationOptions(options: GeolocationOptions): LocationOptions {\n return {\n accuracy: options.enableHighAccuracy ? LocationAccuracy.High : LocationAccuracy.Balanced,\n };\n}\n\nfunction getCurrentPosition(\n success: GeolocationSuccessCallback,\n error: GeolocationErrorCallback = () => {},\n options: GeolocationOptions = {}\n): void {\n _getCurrentPositionAsyncWrapper(success, error, options);\n}\n\n// This function exists to let us continue to return undefined from getCurrentPosition, while still\n// using async/await for the internal implementation of it\nasync function _getCurrentPositionAsyncWrapper(\n success: GeolocationSuccessCallback,\n error: GeolocationErrorCallback,\n options: GeolocationOptions\n): Promise {\n try {\n await ExpoLocation.requestPermissionsAsync();\n const result = await ExpoLocation.getCurrentPositionAsync(convertGeolocationOptions(options));\n success(result);\n } catch (e) {\n error(e);\n }\n}\n\n// Polyfill: navigator.geolocation.watchPosition\nfunction watchPosition(\n success: GeolocationSuccessCallback,\n error: GeolocationErrorCallback,\n options: GeolocationOptions\n) {\n const watchId = LocationSubscriber.registerCallback(success);\n\n ExpoLocation.watchPositionImplAsync(watchId, options).catch((err) => {\n LocationSubscriber.unregisterCallback(watchId);\n error({ watchId, message: err.message, code: err.code });\n });\n\n return watchId;\n}\n\n// Polyfill: navigator.geolocation.clearWatch\nfunction clearWatch(watchId: number) {\n LocationSubscriber.unregisterCallback(watchId);\n}\n"]} \ No newline at end of file +{"version":3,"file":"GeolocationPolyfill.js","sourceRoot":"","sources":["../src/GeolocationPolyfill.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAE7C,OAAO,YAAY,MAAM,gBAAgB,CAAC;AAC1C,OAAO,EAAkB,gBAAgB,EAAmB,MAAM,kBAAkB,CAAC;AACrF,OAAO,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAW3D,cAAc;AACd;;GAEG;AACH,MAAM,UAAU,6BAA6B;IAC3C,IAAI,QAAQ,CAAC,EAAE,KAAK,KAAK,EAAE;QACzB,+DAA+D;QAC/D,IAAI,CAAC,CAAC,QAAQ,IAAI,MAAM,CAAC,EAAE;YACzB,MAAM,CAAC,MAAM,GAAG,MAAM,CAAC;SACxB;QACD,IAAI,CAAC,CAAC,WAAW,IAAI,MAAM,CAAC,MAAM,CAAC,EAAE;YACnC,MAAM,CAAC,MAAM,CAAC,SAAS,GAAG,EAAE,CAAC;SAC9B;QAED,aAAa;QACb,MAAM,CAAC,SAAS,CAAC,WAAW,GAAG;Y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I,EAAE,GAAG,CAAC,IAAI,EAAE,CAAC,CAAC;IAC3D,CAAC,CAAC,CAAC;IAEH,OAAO,OAAO,CAAC;AACjB,CAAC;AAED,6CAA6C;AAC7C,SAAS,UAAU,CAAC,OAAe;IACjC,kBAAkB,CAAC,kBAAkB,CAAC,OAAO,CAAC,CAAC;AACjD,CAAC","sourcesContent":["import { Platform } from 'expo-modules-core';\n\nimport ExpoLocation from './ExpoLocation';\nimport { LocationObject, LocationAccuracy, LocationOptions } from './Location.types';\nimport { LocationSubscriber } from './LocationSubscribers';\n\ntype GeolocationSuccessCallback = (data: LocationObject) => void;\ntype GeolocationErrorCallback = (error: any) => void;\n\ntype GeolocationOptions = {\n enableHighAccuracy?: boolean;\n};\n\ndeclare const global: any;\n\n// @needsAudit\n/**\n * Polyfills `navigator.geolocation` for interop with the core React Native and Web API approach to geolocation.\n */\nexport function installWebGeolocationPolyfill(): void {\n if (Platform.OS !== 'web') {\n // Make sure `window.navigator` is defined in the global scope.\n if (!('window' in global)) {\n global.window = global;\n }\n if (!('navigator' in global.window)) {\n global.window.navigator = {};\n }\n\n // @ts-ignore\n window.navigator.geolocation = {\n getCurrentPosition,\n watchPosition,\n clearWatch,\n\n // We don't polyfill stopObserving, this is an internal method that probably should not even exist\n // in react-native docs\n stopObserving: () => {},\n };\n }\n}\n\nfunction convertGeolocationOptions(options: GeolocationOptions): LocationOptions {\n return {\n accuracy: options.enableHighAccuracy ? LocationAccuracy.High : LocationAccuracy.Balanced,\n };\n}\n\nfunction getCurrentPosition(\n success: GeolocationSuccessCallback,\n error: GeolocationErrorCallback = () => {},\n options: GeolocationOptions = {}\n): void {\n _getCurrentPositionAsyncWrapper(success, error, options);\n}\n\n// This function exists to let us continue to return undefined from getCurrentPosition, while still\n// using async/await for the internal implementation of it\nasync function _getCurrentPositionAsyncWrapper(\n success: GeolocationSuccessCallback,\n error: GeolocationErrorCallback,\n options: GeolocationOptions\n): Promise {\n try {\n await ExpoLocation.requestPermissionsAsync();\n const result = await ExpoLocation.getCurrentPositionAsync(convertGeolocationOptions(options));\n success(result);\n } catch (e) {\n error(e);\n }\n}\n\n// Polyfill: navigator.geolocation.watchPosition\nfunction watchPosition(\n success: GeolocationSuccessCallback,\n error: GeolocationErrorCallback,\n options: GeolocationOptions\n) {\n const watchId = LocationSubscriber.registerCallback(success);\n\n ExpoLocation.watchPositionImplAsync(watchId, options).catch((err) => {\n LocationSubscriber.unregisterCallback(watchId);\n error({ watchId, message: err.message, code: err.code });\n });\n\n return watchId;\n}\n\n// Polyfill: navigator.geolocation.clearWatch\nfunction clearWatch(watchId: number) {\n LocationSubscriber.unregisterCallback(watchId);\n}\n"]} \ No newline at end of file diff --git a/packages/expo-location/src/GeolocationPolyfill.ts b/packages/expo-location/src/GeolocationPolyfill.ts index 81287d76f4754c..58f98ef9edf1b3 100644 --- a/packages/expo-location/src/GeolocationPolyfill.ts +++ b/packages/expo-location/src/GeolocationPolyfill.ts @@ -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,