forked from gbumps/react-native-screenguard
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
145 lines (145 loc) · 4.84 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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
import { NativeModules, NativeEventEmitter } from 'react-native';
import * as ScreenGuardConstants from './constant';
import { Platform } from 'react-native';
const { ScreenGuard } = NativeModules;
var screenShotEmitter = null;
var screenRecordingEmitter = null;
export default {
/**
* activate screenshot blocking (iOS 13+, Android 5+)
* @param capturedBackgroundColor background color layout after taking a screenshot
* @version v0.0.2+
*/
register(capturedBackgroundColor) {
let currentColor =
capturedBackgroundColor == null ||
capturedBackgroundColor.trim().length === 0 ||
!capturedBackgroundColor.trim().startsWith('#') ||
ScreenGuardConstants.REGEX.test(
capturedBackgroundColor.trim().substring(1)
)
? ScreenGuardConstants.BLACK_COLOR
: capturedBackgroundColor;
ScreenGuard.activateShield(currentColor);
},
/**
* Activate screenshot blocking with a blur effect after captured (iOS 13+, Android 6+)
* @param data ScreenGuardBlurDataObject data object
* @param callback void callback after a screenshot or a video capture has been taken
* @version v1.0.2-beta+
*/
registerWithBlurView(data, callback) {
console.warn(
'Install the beta version to continue. Head over to README.md -> Install -> Beta section for how to install'
);
},
/**
* activate without blocking screenshot (iOS 10+, Android 5+ )
* For screenshot detector only, this will fit your need.
* @deprecated this function is deprecated and will be removed at least from ver 4.0.0+ or in the near future
* consider using registerScreenRecordingEventListener and registerScreenshotEventListener instead
* @param void callback callback after a screenshot or a video screen capture has been taken
* @version v0.0.6+
*/
registerWithoutScreenguard(callback) {
console.warn(
'This function is deprecated and will be removed at least from ver 4.0.0+',
'consider switching to registerScreenshotEventListener or registerScreenRecordingEventListener instead'
);
ScreenGuard.activateWithoutShield();
if (screenShotEmitter == null) {
screenShotEmitter = new NativeEventEmitter(ScreenGuard);
}
const _callback = (res) => {
callback(res);
};
const listenerCount = screenShotEmitter.listenerCount(
ScreenGuardConstants.SCREENSHOT_EVT
);
if (!listenerCount) {
screenShotEmitter.addListener(
ScreenGuardConstants.SCREENSHOT_EVT,
_callback
);
}
},
/**
* activate with an Image uri (iOS 13+, Android 8+)
* @param data ScreenGuardImageDataObject data object,
* @param callback void callback after a screenshot or a video screen capture has been taken
* @version v1.0.2-beta+
*/
registerWithImage(data, callback) {
console.warn(
'Install the beta version to continue. Head over to README.md -> Install -> Beta section for how to install'
);
},
/**
* Deactivate screenguard
* Clear all screen protector and event listening
* @version v0.0.2+
*/
unregister() {
ScreenGuard.deactivateShield();
if (screenShotEmitter != null) {
screenShotEmitter.removeAllListeners(ScreenGuardConstants.SCREENSHOT_EVT);
screenShotEmitter = null;
}
if (screenRecordingEmitter != null) {
screenRecordingEmitter.removeAllListeners(
ScreenGuardConstants.SCREEN_RECORDING_EVT
);
screenRecordingEmitter = null;
}
},
/**
* Screenshot event listener
* Register for screenshot event listener
* @version v0.3.6+
*/
registerScreenshotEventListener(callback) {
if (Platform.OS === 'ios') {
ScreenGuard.registerScreenShotEventListener();
}
if (screenShotEmitter == null) {
screenShotEmitter = new NativeEventEmitter(ScreenGuard);
}
const _onScreenCapture = (res) => {
callback(res);
};
const listenerCount = screenShotEmitter.listenerCount(
ScreenGuardConstants.SCREENSHOT_EVT
);
if (!listenerCount) {
screenShotEmitter.addListener(
ScreenGuardConstants.SCREENSHOT_EVT,
_onScreenCapture
);
}
},
/**
* Screen recording event listener (iOS only)
* Register for screen recording event listener
* @version v0.3.6+
*/
registerScreenRecordingEventListener(callback) {
if (Platform.OS === 'ios') {
ScreenGuard.registerScreenRecordingEventListener();
if (screenRecordingEmitter == null) {
screenRecordingEmitter = new NativeEventEmitter(ScreenGuard);
}
const _onScreenRecording = (res) => {
callback(res);
};
const listenerCount = screenRecordingEmitter.listenerCount(
ScreenGuardConstants.SCREEN_RECORDING_EVT
);
if (!listenerCount) {
screenRecordingEmitter.addListener(
ScreenGuardConstants.SCREEN_RECORDING_EVT,
_onScreenRecording
);
}
}
},
};