UNPKG

react-native-location-enabler

Version:

This package makes it easy for an React Native App to ensure that the android device's system settings are properly configured for the app's location needs. If your app needs to request location, the device needs to enable the appropriate system s

47 lines (37 loc) 1.63 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = void 0; var _react = require("react"); var _reactNative = require("react-native"); const { LocationEnabler } = _reactNative.NativeModules; const EVENT_NAME = 'onChangeLocationSettings'; // Override const locationEnabler = new _reactNative.NativeEventEmitter(LocationEnabler); LocationEnabler.addListener = (listener, context) => _reactNative.Platform.OS === 'android' ? locationEnabler.addListener(EVENT_NAME, listener, context) : () => {}; LocationEnabler.once = (listener, context) => locationEnabler.once(EVENT_NAME, listener, context); LocationEnabler.PRIORITIES = LocationEnabler.getConstants(); LocationEnabler.useLocationSettings = (settings, initial) => { const [enabled, setEnabled] = (0, _react.useState)(initial || undefined); const callback = (0, _react.useCallback)(() => { const listner = LocationEnabler.addListener(_ref => { let { locationEnabled } = _ref; return setEnabled(locationEnabled); }); LocationEnabler.checkSettings(settings); if (enabled) listner.remove();else return listner; }, [enabled, settings]); (0, _react.useEffect)(() => { const listner = callback(); return () => listner === null || listner === void 0 ? void 0 : listner.remove(); }, [callback]); const requestResolutionSettings = (0, _react.useCallback)(() => LocationEnabler.requestResolutionSettings(settings), [settings]); return [enabled, requestResolutionSettings]; }; var _default = LocationEnabler; exports.default = _default; //# sourceMappingURL=index.js.map