@exodus/react-native-screenshot-detector 1.2.3 → 1.2.5-exodus.0

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,7 +1,7 @@
1
1
 
2
2
  buildscript {
3
3
  repositories {
4
- jcenter()
4
+ mavenCentral()
5
5
  }
6
6
 
7
7
  dependencies {
@@ -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,90 @@ RCT_EXPORT_METHOD(unsubscribeFromScreenshotAndScreenRecording) {
102
103
 
103
104
  // Screenshot Prevention using Secure Text Field
104
105
  - (void)enableTrueScreenshotPrevention {
105
- if (self.secureTextField == nil) {
106
- self.secureTextField = [[UITextField alloc] init];
107
- self.secureTextField.userInteractionEnabled = NO;
108
- self.secureTextField.secureTextEntry = YES;
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
+
125
+ if (self.secureTextField == nil) {
126
+ self.secureTextField = [[UITextField alloc] init];
127
+ self.secureTextField.userInteractionEnabled = NO;
128
+ self.secureTextField.secureTextEntry = YES;
129
+ }
109
130
 
110
131
  UIWindow *keyWindow = [self getKeyWindow];
111
132
  if (keyWindow != nil) {
112
- [keyWindow makeKeyAndVisible];
133
+ originalKeyWindow = keyWindow;
134
+ originalSuperlayer = keyWindow.layer.superlayer;
113
135
 
114
- // Make the app window a sublayer of the secure text field
115
- [keyWindow.layer.superlayer addSublayer:self.secureTextField.layer];
136
+ [keyWindow makeKeyAndVisible];
116
137
 
117
- // Add the window layer as a sublayer of the secure text field's first sublayer
118
- NSArray *sublayers = self.secureTextField.layer.sublayers;
119
- if (sublayers.count > 0) {
120
- [sublayers.firstObject addSublayer:keyWindow.layer];
121
- }
138
+ if (originalSuperlayer != nil) {
139
+ [originalSuperlayer addSublayer:self.secureTextField.layer];
140
+
141
+ [keyWindow.layer removeFromSuperlayer];
142
+
143
+ NSArray *sublayers = self.secureTextField.layer.sublayers;
144
+ if (sublayers.count > 0) {
145
+ [sublayers.firstObject addSublayer:keyWindow.layer];
146
+ } else {
147
+ [self.secureTextField.layer addSublayer:keyWindow.layer];
148
+ }
149
+ }
150
+ } else {
151
+ NSLog(@"[RNScreenshotDetector] No keyWindow found, cannot enable protection");
122
152
  }
123
- } else {
124
- self.secureTextField.secureTextEntry = YES;
153
+ } @catch (NSException *exception) {
154
+ NSLog(@"[RNScreenshotDetector] Error in enableTrueScreenshotPrevention: %@", exception);
125
155
  }
126
156
  }
127
157
 
128
158
  - (void)disableTrueScreenshotPrevention {
129
- if (self.secureTextField != nil) {
130
- self.secureTextField.secureTextEntry = NO;
159
+ @try {
160
+ if (self.secureTextField != nil) {
161
+
162
+ self.secureTextField.secureTextEntry = NO;
163
+
164
+ // Safe recovery: check if references are valid
165
+ if (originalKeyWindow != nil && originalSuperlayer != nil) {
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
+ }
171
+
172
+ [self.secureTextField.layer removeFromSuperlayer];
173
+ }
174
+
175
+ // Safe reference cleanup
176
+ originalKeyWindow = nil;
177
+ originalSuperlayer = nil;
178
+
179
+ [self.secureTextField removeFromSuperview];
180
+ self.secureTextField = nil;
181
+ }
182
+ } @catch (NSException *exception) {
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
+ }
131
190
  }
132
191
  }
133
192
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@exodus/react-native-screenshot-detector",
3
- "version": "1.2.3",
3
+ "version": "1.2.5-exodus.0",
4
4
  "description": "detect when the user takes a screenshot",
5
5
  "scripts": {
6
6
  "test": "echo \"Error: no test specified\" && exit 1"
@@ -11,7 +11,7 @@
11
11
  "author": "gcarling",
12
12
  "repository": {
13
13
  "type": "git",
14
- "url": "https://github.com/ExodusMovement/react-native-screenshot-detector"
14
+ "url": "https://github.com/ExodusForks/react-native-screenshot-detector"
15
15
  },
16
16
  "license": "MIT"
17
17
  }