@exodus/react-native-screenshot-detector 1.2.2 → 1.2.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
|
|
2
2
|
package com.reactlibrary;
|
|
3
3
|
|
|
4
|
+
import android.app.Activity;
|
|
4
5
|
import android.view.Window;
|
|
5
6
|
import android.view.WindowManager;
|
|
6
7
|
|
|
@@ -25,25 +26,38 @@ public class RNScreenshotDetectorModule extends ReactContextBaseJavaModule {
|
|
|
25
26
|
|
|
26
27
|
@ReactMethod
|
|
27
28
|
public void disableScreenshots() {
|
|
28
|
-
getCurrentActivity()
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
29
|
+
Activity currentActivity = getCurrentActivity();
|
|
30
|
+
if (currentActivity != null) {
|
|
31
|
+
currentActivity.runOnUiThread(new Runnable() {
|
|
32
|
+
@Override
|
|
33
|
+
public void run() {
|
|
34
|
+
Window window = getWindow();
|
|
35
|
+
if (window != null) {
|
|
36
|
+
window.setFlags(WindowManager.LayoutParams.FLAG_SECURE, WindowManager.LayoutParams.FLAG_SECURE);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
}
|
|
34
41
|
}
|
|
35
42
|
|
|
36
43
|
@ReactMethod
|
|
37
44
|
public void enableScreenshots() {
|
|
38
|
-
getCurrentActivity()
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
45
|
+
Activity currentActivity = getCurrentActivity();
|
|
46
|
+
if (currentActivity != null) {
|
|
47
|
+
currentActivity.runOnUiThread(new Runnable() {
|
|
48
|
+
@Override
|
|
49
|
+
public void run() {
|
|
50
|
+
Window window = getWindow();
|
|
51
|
+
if (window != null) {
|
|
52
|
+
window.clearFlags(WindowManager.LayoutParams.FLAG_SECURE);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
}
|
|
44
57
|
}
|
|
45
58
|
|
|
46
59
|
private Window getWindow() {
|
|
47
|
-
|
|
60
|
+
Activity currentActivity = getCurrentActivity();
|
|
61
|
+
return currentActivity != null ? currentActivity.getWindow() : null;
|
|
48
62
|
}
|
|
49
63
|
}
|
|
@@ -13,6 +13,8 @@
|
|
|
13
13
|
id screenshotObserver;
|
|
14
14
|
id screenRecordingObserver;
|
|
15
15
|
BOOL isProtectionEnabled;
|
|
16
|
+
UIWindow *originalKeyWindow;
|
|
17
|
+
CALayer *originalSuperlayer;
|
|
16
18
|
}
|
|
17
19
|
|
|
18
20
|
RCT_EXPORT_MODULE();
|
|
@@ -91,7 +93,6 @@ RCT_EXPORT_METHOD(isScreenRecording:(RCTPromiseResolveBlock)resolve
|
|
|
91
93
|
resolve(@(isRecording));
|
|
92
94
|
}
|
|
93
95
|
|
|
94
|
-
// Clear and explicit method names
|
|
95
96
|
RCT_EXPORT_METHOD(subscribeToScreenshotAndScreenRecording) {
|
|
96
97
|
[self startObserving];
|
|
97
98
|
}
|
|
@@ -102,32 +103,58 @@ RCT_EXPORT_METHOD(unsubscribeFromScreenshotAndScreenRecording) {
|
|
|
102
103
|
|
|
103
104
|
// Screenshot Prevention using Secure Text Field
|
|
104
105
|
- (void)enableTrueScreenshotPrevention {
|
|
105
|
-
|
|
106
|
-
self.secureTextField
|
|
107
|
-
|
|
108
|
-
|
|
106
|
+
@try {
|
|
107
|
+
if (self.secureTextField == nil) {
|
|
108
|
+
self.secureTextField = [[UITextField alloc] init];
|
|
109
|
+
self.secureTextField.userInteractionEnabled = NO;
|
|
110
|
+
self.secureTextField.secureTextEntry = YES;
|
|
111
|
+
}
|
|
109
112
|
|
|
110
113
|
UIWindow *keyWindow = [self getKeyWindow];
|
|
111
114
|
if (keyWindow != nil) {
|
|
112
|
-
|
|
115
|
+
originalKeyWindow = keyWindow;
|
|
116
|
+
originalSuperlayer = keyWindow.layer.superlayer;
|
|
113
117
|
|
|
114
|
-
|
|
115
|
-
[keyWindow.layer.superlayer addSublayer:self.secureTextField.layer];
|
|
118
|
+
[keyWindow makeKeyAndVisible];
|
|
116
119
|
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
[
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
120
|
+
if (originalSuperlayer != nil) {
|
|
121
|
+
[originalSuperlayer addSublayer:self.secureTextField.layer];
|
|
122
|
+
|
|
123
|
+
[keyWindow.layer removeFromSuperlayer];
|
|
124
|
+
|
|
125
|
+
NSArray *sublayers = self.secureTextField.layer.sublayers;
|
|
126
|
+
if (sublayers.count > 0) {
|
|
127
|
+
[sublayers.firstObject addSublayer:keyWindow.layer];
|
|
128
|
+
} else {
|
|
129
|
+
[self.secureTextField.layer addSublayer:keyWindow.layer];
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
} @catch (NSException *exception) {
|
|
134
|
+
NSLog(@"[RNScreenshotDetector] Error in enableTrueScreenshotPrevention: %@", exception);
|
|
125
135
|
}
|
|
126
136
|
}
|
|
127
137
|
|
|
128
138
|
- (void)disableTrueScreenshotPrevention {
|
|
129
|
-
|
|
130
|
-
self.secureTextField
|
|
139
|
+
@try {
|
|
140
|
+
if (self.secureTextField != nil) {
|
|
141
|
+
self.secureTextField.secureTextEntry = NO;
|
|
142
|
+
|
|
143
|
+
if (originalKeyWindow != nil && originalSuperlayer != nil) {
|
|
144
|
+
[originalKeyWindow.layer removeFromSuperlayer];
|
|
145
|
+
[originalSuperlayer addSublayer:originalKeyWindow.layer];
|
|
146
|
+
|
|
147
|
+
[self.secureTextField.layer removeFromSuperlayer];
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
originalKeyWindow = nil;
|
|
151
|
+
originalSuperlayer = nil;
|
|
152
|
+
|
|
153
|
+
[self.secureTextField removeFromSuperview];
|
|
154
|
+
self.secureTextField = nil;
|
|
155
|
+
}
|
|
156
|
+
} @catch (NSException *exception) {
|
|
157
|
+
NSLog(@"[RNScreenshotDetector] Error in disableTrueScreenshotPrevention: %@", exception);
|
|
131
158
|
}
|
|
132
159
|
}
|
|
133
160
|
|