JayantBadlani / ScreenShield

ScreenShield is an iOS library that provides a simple way to protect your app's content from being captured or recorded by screenshots, screen recordings, or other screen capture methods. It works by adding a secure layer on top of your views, which prevents most screen capture mechanisms from recording the underlying content.
MIT License
89 stars 15 forks source link

SafeArea removed in React-Native #11

Closed RZulfikri closed 4 months ago

RZulfikri commented 4 months ago

Hi, I want to thank you for the library, it works perfectly. However, I am having issues with safe-area things. After I add screenshot protection, the bottom inset of the safe-area becomes 0. If I disabled it, it worked normally. I tried to detect the safe-area insets using react-native-safe-area-context. I tried to move the secureTextField to a subview instead of direct view, but no luck. Any advice?

RZulfikri commented 4 months ago

I think it's due to this code,

      layer.superlayer?.addSublayer(secureTextField.layer)
      secureTextField.layer.sublayers?.last?.addSublayer(layer)

that code will trigger safeAreaInsetsDidChange and change the safeAreaInsets.bottom value to 0

JayantBadlani commented 4 months ago

Hi @RZulfikri,

If you've found a solution for the issue, could you please fork this branch to update the code? Additionally, if you'd like to contribute by raising an MR, please feel free to do so. I'll review it and merge it later. Thank you!

RZulfikri commented 4 months ago

finally I found the solution.

  1. I comment this code
    
    @objc func setScreenCaptureProtection() {

the code below makes the main view become blank // if viewWithTag(Constants.secureTextFieldTag) is UITextField { // return // } //
// guard superview != nil else { // for subview in subviews { // subview.setScreenCaptureProtection() // } // return // }

   ...

the code below cause an error when implementing with window // secureTextField.topAnchor.constraint(equalTo: self.topAnchor, constant: 0).isActive = true // secureTextField.bottomAnchor.constraint(equalTo: self.bottomAnchor, constant: 0).isActive = true // secureTextField.leadingAnchor.constraint(equalTo: self.leadingAnchor, constant: 0).isActive = true // secureTextField.trailingAnchor.constraint(equalTo: self.trailingAnchor, constant: 0).isActive = true

}


2. I call window ( `[self.window setScreenCaptureProtection];`) instead of using `view`. The view trigger SafeArea changed.