From db36b5fca913ba4e20b6b39ed5f5e6cae0a20e37 Mon Sep 17 00:00:00 2001 From: shahhussain-t Date: Wed, 12 Mar 2025 08:23:09 +0500 Subject: [PATCH] Fixed The Crash on the React native Restart --- ios/RNScreenshotPrevent.m | 40 +++++++++++++++++++++++++++++++++++---- 1 file changed, 36 insertions(+), 4 deletions(-) diff --git a/ios/RNScreenshotPrevent.m b/ios/RNScreenshotPrevent.m index 2491ea2..948f4ee 100644 --- a/ios/RNScreenshotPrevent.m +++ b/ios/RNScreenshotPrevent.m @@ -192,15 +192,47 @@ -(void) removeSecureTextFieldFromView:(UIView *) view { } } + /** removes secure textfield from the view */ RCT_EXPORT_METHOD(disableSecureView) { - [self enabled:NO]; - secureField.secureTextEntry = false; + NSLog(@"[RNScreenshotPrevent] disableSecureView called."); + + if (secureField != nil) { + NSLog(@"[RNScreenshotPrevent] Found secureField, disabling secure entry."); + secureField.secureTextEntry = NO; + + if (secureField.superview) { + NSLog(@"[RNScreenshotPrevent] Removing secureField from its superview."); + [secureField removeFromSuperview]; + } else { + NSLog(@"[RNScreenshotPrevent] secureField has no superview."); + } + + secureField = nil; + NSLog(@"[RNScreenshotPrevent] secureField reference cleared."); + } else { + NSLog(@"[RNScreenshotPrevent] No secureField found, nothing to disable."); + } + UIView *view = [UIApplication sharedApplication].keyWindow.rootViewController.view; - for(UIView *subview in view.subviews) { - [self removeSecureTextFieldFromView:subview]; + if (view == nil) { + NSLog(@"[RNScreenshotPrevent] Root view is nil, cannot remove secure text fields."); + return; + } + + NSLog(@"[RNScreenshotPrevent] Checking subviews for secure fields to remove."); + int removedFields = 0; + for (UIView *subview in view.subviews) { + if ([subview isKindOfClass:[UITextField class]]) { + NSLog(@"[RNScreenshotPrevent] Removing a UITextField from subviews."); + [self removeSecureTextFieldFromView:subview]; + removedFields++; + } } + + NSLog(@"[RNScreenshotPrevent] Secure view disabled and removed. Total fields removed: %d", removedFields); } + @end