forked from Calvin-Huang/react-native-device-brightness
-
Notifications
You must be signed in to change notification settings - Fork 21
/
index.ts
32 lines (26 loc) · 902 Bytes
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import { NativeModules, Platform } from 'react-native';
const { RNDeviceBrightness } = NativeModules;
export const setBrightnessLevel = async (
brightnessLevel: number
): Promise<void> => {
if (brightnessLevel < 0 || brightnessLevel > 1) {
if (!(Platform.OS === 'android' && brightnessLevel === -1)) {
throw Error('⚠️ BrightnessLevel value must betweens 0 to 1 ⚠️');
}
}
await RNDeviceBrightness.setBrightnessLevel(brightnessLevel);
};
export const getBrightnessLevel = async (): Promise<number> => {
return RNDeviceBrightness.getBrightnessLevel();
};
export const getSystemBrightnessLevel = (): Promise<number> => {
if (Platform.OS !== 'android') {
throw Error('⚠️ Android only supported ⚠️');
}
return RNDeviceBrightness.getSystemBrightnessLevel();
};
export default {
setBrightnessLevel,
getBrightnessLevel,
getSystemBrightnessLevel,
};