UNPKG

react-native-rn-in-app-update

Version:

A minimal React Native module that displays the native Android in-app update popup using the Play Core library. Supports both immediate and flexible update types.

86 lines (81 loc) 3.13 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var _exportNames = { showUpdatePopup: true, getUpdateInfo: true, startFlexibleUpdateWithProgress: true, subscribeToUpdateProgress: true }; exports.subscribeToUpdateProgress = exports.startFlexibleUpdateWithProgress = exports.showUpdatePopup = exports.getUpdateInfo = void 0; var _reactNative = require("react-native"); var _types = require("./types.js"); Object.keys(_types).forEach(function (key) { if (key === "default" || key === "__esModule") return; if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return; if (key in exports && exports[key] === _types[key]) return; Object.defineProperty(exports, key, { enumerable: true, get: function () { return _types[key]; } }); }); const LINKING_ERROR = `The package 'react-native-rn-in-app-update' doesn't seem to be linked. Make sure: \n\n` + _reactNative.Platform.select({ ios: "- You have run 'pod install'\n", default: '' }) + '- You rebuilt the app after installing the package\n' + '- You are not using Expo Go\n'; const RnInAppUpdate = _reactNative.NativeModules.RnInAppUpdate ? _reactNative.NativeModules.RnInAppUpdate : new Proxy({}, { get() { throw new Error(LINKING_ERROR); } }); /** * Shows the native Android in-app update popup using the Play Core API. * * @param type - (Optional) The update type to use: * - `'immediate'` (default): Forces the user to update immediately before continuing. * - `'flexible'`: Allows the user to continue using the app while the update is downloaded in the background. * * @returns A Promise that resolves when the update flow is started, or rejects if not available or fails. */ const showUpdatePopup = (type = 'immediate') => { if (_reactNative.Platform.OS !== 'android') { return Promise.resolve(); } const updateType = type === 'immediate' ? 0 : 1; return RnInAppUpdate.showUpdatePopup(updateType); }; /** * Gets metadata about the available update from the Play Store. * * @returns A promise that resolves with update info, or rejects on error or unsupported platform. */ exports.showUpdatePopup = showUpdatePopup; const getUpdateInfo = async () => { if (_reactNative.Platform.OS !== 'android') { return null; } const info = await RnInAppUpdate.getUpdateInfo(); return info; }; /** * Starts a flexible update and listens for download progress. * Emits progress events via DeviceEventEmitter. */ exports.getUpdateInfo = getUpdateInfo; const startFlexibleUpdateWithProgress = async () => { if (_reactNative.Platform.OS !== 'android') return; await RnInAppUpdate.startFlexibleUpdateWithProgress(); }; /** * Subscribes to update progress events */ exports.startFlexibleUpdateWithProgress = startFlexibleUpdateWithProgress; const subscribeToUpdateProgress = callback => { const subscription = _reactNative.DeviceEventEmitter.addListener('in_app_update_progress', callback); return () => subscription.remove(); // return unsubscribe function }; exports.subscribeToUpdateProgress = subscribeToUpdateProgress; //# sourceMappingURL=index.js.map