forked from mockingbot/react-native-immersive
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
32 lines (28 loc) · 1.13 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
import { NativeModules, DeviceEventEmitter, Platform } from 'react-native'
const { RNImmersive } = NativeModules
const unSupportedError = __DEV__
? () => { throw new Error('[react-native-immersive] should not be called on iOS') }
: () => {}
let isListenerEnabled = false
const Immersive = Platform.OS === 'android' ? {
on: () => RNImmersive.setImmersive(true),
off: () => RNImmersive.setImmersive(false),
setImmersive: (isOn) => RNImmersive.setImmersive(isOn),
getImmersive: () => RNImmersive.getImmersive(), // do not always match actual display state
addImmersiveListener: (listener) => {
DeviceEventEmitter.addListener('@@IMMERSIVE_STATE_CHANGED', listener)
if (isListenerEnabled) return
isListenerEnabled = true
RNImmersive.addImmersiveListener()
},
removeImmersiveListener: (listener) => DeviceEventEmitter.removeListener('@@IMMERSIVE_STATE_CHANGED', listener)
} : {
on: unSupportedError,
off: unSupportedError,
setImmersive: unSupportedError,
getImmersive: unSupportedError,
addImmersiveListener: unSupportedError,
removeImmersiveListener: unSupportedError
}
export { Immersive }
export default Immersive