-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
46 lines (42 loc) · 1.2 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
import { Alert } from 'react-native';
import { NativeModules, Platform, NativeEventEmitter } from 'react-native';
const { RnScreenShot } = NativeModules;
const SCREENSHOT_EVENT = 'ScreenshotTaken';
let eventEmitter = null;
/**
* Disable action screenshot
*/
const DisableScreenShot = (cb) => new Promise((resolve, reject) => {
try {
if (Platform.OS === "android") {
RnScreenShot.DisableScreenShot();
} else {
RnScreenShot.addListener(SCREENSHOT_EVENT)
console.log("enable screenshot", RnScreenShot)
eventEmitter = new NativeEventEmitter(RnScreenShot);
eventEmitter.addListener(SCREENSHOT_EVENT, cb, {})
resolve(eventEmitter)
}
} catch (error) {
// alert(error)
}
})
/**
* Disable action screenshot
*/
const EnableScreenShot = () => new Promise((resolve, reject) => {
try {
if (Platform.OS === "android") {
RnScreenShot.EnableScreenshot();
resolve(null)
} else {
eventEmitter && eventEmitter.removeAllListeners(SCREENSHOT_EVENT);
}
} catch (error) {
console.log(error)
}
})
export {
DisableScreenShot,
EnableScreenShot
}