forked from mockingbot/react-native-immersive
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
39 lines (35 loc) · 1.17 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
import { NativeModules, DeviceEventEmitter, Platform } from 'react-native'
const { RNFullscreen } = NativeModules
const warnInIOS = () => {
if(__DEV__){
console.warn(
'Fullscreen module is not supported in IOS.' +
'This message will disappear in a release build.'
);
}
}
let isListenerEnabled = false
const Fullscreen = Platform.OS === 'android' ? {
on: () => RNFullscreen.setFullscreen(true),
off: () => RNFullscreen.setFullscreen(false),
setFullscreen: (isOn) => RNFullscreen.setFullscreen(isOn),
getFullscreen: () => RNFullscreen.getFullscreen(), // do not always match actual display state
addFullscreenListener: (listener) => {
DeviceEventEmitter.addListener('@@FULLSCREEN_STATE_CHANGED', listener)
if (isListenerEnabled) return
isListenerEnabled = true
RNFullscreen.addFullscreenListener()
},
removeFullscreenListener: (listener) => {
DeviceEventEmitter.removeListener('@@FULLSCREEN_STATE_CHANGED', listener)
}
} : {
on: warnInIOS,
off: warnInIOS,
setFullscreen: warnInIOS,
getFullscreen: warnInIOS,
addFullscreenListener: warnInIOS,
removeFullscreenListener: warnInIOS
}
export { Fullscreen }
export default Fullscreen