UNPKG

react-native-brightness-control

Version:
49 lines (48 loc) 1.92 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = void 0; var _reactNative = require("react-native"); const LINKING_ERROR = `The package 'react-native-brightness-control' doesn't seem to be linked. Make sure: \n\n` + '- You rebuilt the app after installing the package\n' + '- You are not using Expo Go\n'; const BrightnessModule = _reactNative.NativeModules.Brightness ? _reactNative.NativeModules.Brightness : new Proxy({}, { get() { throw new Error(LINKING_ERROR); } }); const setBrightness = async (brightness, durationMs = 0) => { if (brightness < 0 || brightness > 1 || brightness === undefined) { console.error(`Invalid brightness value: ${brightness}. It must be between 0 and 1`); return; } await BrightnessModule.setBrightness(brightness, durationMs); }; const getBrightness = async () => BrightnessModule.getBrightness(); const setIsNeedRestoreBrightness = isNeedRestoreBrightness => { if (_reactNative.Platform.OS === 'ios') { BrightnessModule.setIsNeedRestoreBrightness(isNeedRestoreBrightness); } }; const Brightness = { /** * Sets the screen brightness. * @param brightness - A value between 0 and 1 representing the brightness level * @param durationMs - Duration in milliseconds for which the brightness transition should occur */ setBrightness, /** * Gets the current screen brightness. * @returns A promise that resolves the current brightness level (0 to 1) */ getBrightness, /** * The method is responsible for determining whether the user's original brightness * should be restored when the application is minimized * * @param isNeedRestoreBrightness - If `true`, restores original brightness upon app minimization (initial value is "true") * @platform ios */ setIsNeedRestoreBrightness }; var _default = exports.default = Brightness; //# sourceMappingURL=index.js.map