Skip to content

Commit

Permalink
release: v.1.9.1 (#26)
Browse files Browse the repository at this point in the history
## Release

fix to reload black screen with prevent screenshot event #23
  • Loading branch information
wn-na authored Sep 25, 2023
2 parents c283b11 + 07374de commit dfef8e5
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
27 changes: 26 additions & 1 deletion ios/CaptureProtection.mm
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@
#import <React/RCTBridge.h>
#import <React/RCTEventDispatcher.h>
static int TAG_RECORD_PROTECTION_SCREEN = -1002;
static int TAG_SCREEN_PROTECTION = -1004;

@implementation CaptureProtection {
bool hasScreenRecordObserver;
bool hasScreenshotObserver;
bool isPreventScreenRecord;
bool isPreventScreenshot;
bool isBundleObserver;
enum CaptureProtectionStatus {
INIT_RECORD_LISTENER,
REMOVE_RECORD_LISTENER,
Expand Down Expand Up @@ -53,6 +55,24 @@ - (void)eventScreenshot: (NSNotification *)notification {
[self sendEventWithName:@"CaptureProtectionListener" body:[self eventMessage:CAPTURE_DETECTED]];
}

- (void)bundleObserver {
[[NSNotificationCenter defaultCenter] addObserverForName:RCTBridgeWillReloadNotification object:nil queue:nil usingBlock:^(NSNotification * _Nonnull note) {
dispatch_async(dispatch_get_main_queue(), ^{
NSLog(@"RCTBridgeWillReloadNotification");
if (self->secureTextField) {
[self->secureTextField setSecureTextEntry:false];
}
[self removeScreenShotObserver];
[self removeScreenRecordObserver];
self->protecterViewController = nil;
self->hasScreenRecordObserver = false;
self->hasScreenshotObserver = false;
self->isPreventScreenRecord = false;
self->isPreventScreenshot = false;
});
}];
}

- (void)eventScreenRecordWithInit: (NSNotification *)notification init:(BOOL) init {
bool isCaptured = [[[UIScreen mainScreen] valueForKey:@"isCaptured"] boolValue];
if (isCaptured) {
Expand Down Expand Up @@ -130,15 +150,20 @@ - (void)removeRecordProtectionScreen {

- (void)secureScreenshotView: (BOOL)isSecure {
dispatch_async(dispatch_get_main_queue(), ^{
if (self->isBundleObserver != true) {
self->isBundleObserver = true;
[self bundleObserver];
}
if (self->secureTextField == nil) {
self->secureTextField = [[UITextField alloc] init];
self->secureTextField.userInteractionEnabled = false;
self->secureTextField.tag = TAG_SCREEN_PROTECTION;
UIWindow *window = [UIApplication sharedApplication].keyWindow;

[window makeKeyAndVisible];

[window.layer.superlayer addSublayer:self->secureTextField.layer];
[self->secureTextField.layer.sublayers.firstObject addSublayer:window.layer];

}
[self->secureTextField setSecureTextEntry:isSecure];
});
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-native-capture-protection",
"version": "1.9.0",
"version": "1.9.1",
"description": "It’s a library for React Native to control simple capture events(i.e. Screenshot or Screen record)",
"main": "lib/commonjs/index",
"module": "lib/module/index",
Expand Down

0 comments on commit dfef8e5

Please sign in to comment.