forked from wrathyz/react-native-immersive-mode
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
73 lines (58 loc) · 1.69 KB
/
index.js
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import { NativeModules, DeviceEventEmitter } from 'react-native';
const { RNImmersiveMode } = NativeModules;
const checkModule = () => {
if (!RNImmersiveMode) {
throw Error('RNImmersiveMode is not properly linked');
}
}
const ImmersiveMode = {
/**
* @deprecated
*/
...RNImmersiveMode, // for constants
fullLayout(full) {
checkModule();
RNImmersiveMode.fullLayout(full);
},
/**
* @deprecated
*/
setImmersive(mode) {
checkModule();
RNImmersiveMode.setImmersive(mode);
},
setBarMode(mode) {
checkModule();
RNImmersiveMode.setBarMode(mode);
},
setBarStyle(style) {
checkModule();
RNImmersiveMode.setBarStyle(style);
},
setBarTranslucent(enable) {
checkModule();
RNImmersiveMode.setBarTranslucent(enable);
},
setBarColor(color) {
checkModule();
if (typeof color === 'string') {
if (color.length === 9) {
// convert #rgba to #argb
color = '#' + color.substr(7, 2) + color.substr(1, 6);
} else if (color.length === 4) {
color = '#' + color[1] + color[1] + color[2] + color[2] + color[3] + color[3];
}
}
RNImmersiveMode.setBarColor(color);
},
addEventListener(callback) {
checkModule();
if (typeof callback !== 'function') return;
RNImmersiveMode.setOnSystemUiVisibilityChangeListener();
const subscription = DeviceEventEmitter.addListener(
RNImmersiveMode.OnSystemUiVisibilityChange,
(e) => callback(e));
return subscription;
}
}
export default ImmersiveMode;