@exodus/react-native-screenshot-detector 1.2.4 → 1.2.5
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.
|
@@ -104,6 +104,24 @@ RCT_EXPORT_METHOD(unsubscribeFromScreenshotAndScreenRecording) {
|
|
|
104
104
|
// Screenshot Prevention using Secure Text Field
|
|
105
105
|
- (void)enableTrueScreenshotPrevention {
|
|
106
106
|
@try {
|
|
107
|
+
// Check if the protection is already fully active
|
|
108
|
+
if (isProtectionEnabled && self.secureTextField != nil &&
|
|
109
|
+
originalKeyWindow != nil && originalSuperlayer != nil) {
|
|
110
|
+
|
|
111
|
+
UIWindow *currentKeyWindow = [self getKeyWindow];
|
|
112
|
+
|
|
113
|
+
// Check if the same keyWindow is already fully protected
|
|
114
|
+
if (originalKeyWindow == currentKeyWindow &&
|
|
115
|
+
self.secureTextField.layer.superlayer == originalSuperlayer) {
|
|
116
|
+
NSLog(@"[RNScreenshotDetector] Screenshot protection fully active, skipping");
|
|
117
|
+
return;
|
|
118
|
+
} else {
|
|
119
|
+
NSLog(@"[RNScreenshotDetector] Protection partially active, need to reset");
|
|
120
|
+
// If only partially set, reset and set again
|
|
121
|
+
[self disableTrueScreenshotPrevention];
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
|
|
107
125
|
if (self.secureTextField == nil) {
|
|
108
126
|
self.secureTextField = [[UITextField alloc] init];
|
|
109
127
|
self.secureTextField.userInteractionEnabled = NO;
|
|
@@ -129,7 +147,9 @@ RCT_EXPORT_METHOD(unsubscribeFromScreenshotAndScreenRecording) {
|
|
|
129
147
|
[self.secureTextField.layer addSublayer:keyWindow.layer];
|
|
130
148
|
}
|
|
131
149
|
}
|
|
132
|
-
}
|
|
150
|
+
} else {
|
|
151
|
+
NSLog(@"[RNScreenshotDetector] No keyWindow found, cannot enable protection");
|
|
152
|
+
}
|
|
133
153
|
} @catch (NSException *exception) {
|
|
134
154
|
NSLog(@"[RNScreenshotDetector] Error in enableTrueScreenshotPrevention: %@", exception);
|
|
135
155
|
}
|
|
@@ -138,15 +158,21 @@ RCT_EXPORT_METHOD(unsubscribeFromScreenshotAndScreenRecording) {
|
|
|
138
158
|
- (void)disableTrueScreenshotPrevention {
|
|
139
159
|
@try {
|
|
140
160
|
if (self.secureTextField != nil) {
|
|
161
|
+
|
|
141
162
|
self.secureTextField.secureTextEntry = NO;
|
|
142
163
|
|
|
164
|
+
// Safe recovery: check if references are valid
|
|
143
165
|
if (originalKeyWindow != nil && originalSuperlayer != nil) {
|
|
144
|
-
|
|
145
|
-
|
|
166
|
+
// Check if keyWindow is still valid
|
|
167
|
+
if (originalKeyWindow.superview != nil || originalKeyWindow.layer.superlayer != nil) {
|
|
168
|
+
[originalKeyWindow.layer removeFromSuperlayer];
|
|
169
|
+
[originalSuperlayer addSublayer:originalKeyWindow.layer];
|
|
170
|
+
}
|
|
146
171
|
|
|
147
172
|
[self.secureTextField.layer removeFromSuperlayer];
|
|
148
173
|
}
|
|
149
174
|
|
|
175
|
+
// Safe reference cleanup
|
|
150
176
|
originalKeyWindow = nil;
|
|
151
177
|
originalSuperlayer = nil;
|
|
152
178
|
|
|
@@ -155,6 +181,12 @@ RCT_EXPORT_METHOD(unsubscribeFromScreenshotAndScreenRecording) {
|
|
|
155
181
|
}
|
|
156
182
|
} @catch (NSException *exception) {
|
|
157
183
|
NSLog(@"[RNScreenshotDetector] Error in disableTrueScreenshotPrevention: %@", exception);
|
|
184
|
+
originalKeyWindow = nil;
|
|
185
|
+
originalSuperlayer = nil;
|
|
186
|
+
if (self.secureTextField != nil) {
|
|
187
|
+
[self.secureTextField removeFromSuperview];
|
|
188
|
+
self.secureTextField = nil;
|
|
189
|
+
}
|
|
158
190
|
}
|
|
159
191
|
}
|
|
160
192
|
|