@tecnavia/react-native-screenshot-prevent (1.3.0)
Published 2024-12-20 15:58:34 +00:00 by naquilini
Installation
@tecnavia:registry=
npm install @tecnavia/react-native-screenshot-prevent@1.3.0
"@tecnavia/react-native-screenshot-prevent": "1.3.0"
About this package
react-native-screenshot-prevent
This fork contains fully working blank screenshot on IOS13+ including screen recording
This fork contains fully working image screenshot cover on IOS13+ including screen recording
App layout is white / or black in dark theme
For now you might disable RNPreventScreenshot.enableSecureView() in development mode (check DEV variable)
because disableSecureView() is not working yet correctly
Getting started
$ npm install react-native-screenshot-prevent --save
Mostly automatic installation
React-Native version 0.59.X and higher: on IOS you might use only pod install
in your ios folder
$ react-native link react-native-screenshot-prevent
Manual installation
iOS
- In XCode, in the project navigator, right click
Libraries
➜Add Files to [your project's name]
- Go to
node_modules
➜react-native-screenshot-prevent
and addRNScreenshotPrevent.xcodeproj
- In XCode, in the project navigator, select your project. Add
libRNScreenshotPrevent.a
to your project'sBuild Phases
➜Link Binary With Libraries
- Run your project (
Cmd+R
)<
Android
- Open up
android/app/src/main/java/[...]/MainApplication.java
- Add
import com.killserver.screenshotprev.RNScreenshotPreventPackage;
to the imports at the top of the file - Add
new RNScreenshotPreventPackage()
to the list returned by thegetPackages()
method
- Append the following lines to
android/settings.gradle
:include ':react-native-screenshot-prevent' project(':react-native-screenshot-prevent').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-screenshot-prevent/android')
- Insert the following lines inside the dependencies block in
android/app/build.gradle
:implementation project(':react-native-screenshot-prevent')
Usage
// sample code
import RNScreenshotPrevent, { addListener } from 'react-native-screenshot-prevent';
/* (IOS, Android) for android might be the only step to get secureView
* on IOS enables blurry view when app goes into inactive state
*/
RNScreenshotPrevent.enabled(true/false);
/* (IOS) enableSecureView for IOS13+
* creates a hidden secureTextField which prevents Application UI capture on screenshots
*/
if(!__DEV__) RNScreenshotPrevent.enableSecureView();
/* (IOS) enableSecureView for IOS13+
* creates a hidden secureTextField which prevents Application UI capture on screenshots
* and uses imgUri as the source of the background image (can be both https://, file:///)
*/
if(!__DEV__) RNPreventScreenshot.enableSecureView(imgUri);
/* (IOS) disableSecureView for IOS13+
* remove a hidden secureTextField which prevents Application UI capture on screenshots
*/
if(!__DEV__) RNScreenshotPrevent.disableSecureView();
/* (IOS) notification handler
* notifies when user has taken screenshot (yes, after taking) - you can show alert or do some actions
*
* @param {function} callback fn
* @returns object with .remove() method
*/
addListener(fn);
/** example using the listener */
useEffect(() => {
const subscription = RNScreenshotPrevent.addListener(() => {
console.log('Screenshot taken');
showAlert({
title: 'Warning',
message: 'You have taken a screenshot of the app. This is prohibited due to security reasons.',
confirmText: 'I understand'
});
})
return () => {
subscription.remove();
}
}, []);
Dependencies
Development Dependencies
ID | Version |
---|---|
@commitlint/config-conventional | ^17.0.2 |
@evilmartians/lefthook | ^1.2.2 |
@react-native-community/eslint-config | ^3.0.2 |
@release-it/conventional-changelog | ^5.0.0 |
@types/jest | ^28.1.2 |
@types/node | ^20.3.1 |
@types/react | ~17.0.21 |
@types/react-native | 0.70.0 |
del-cli | ^5.0.0 |
eslint | ^8.4.1 |
eslint-config-prettier | ^8.5.0 |
eslint-plugin-prettier | ^4.0.0 |
jest | ^28.1.1 |
metro-react-native-babel-preset | ^0.66.2 |
pod-install | ^0.1.0 |
prettier | ^2.0.5 |
react | 18.2.0 |
react-native | 0.71.7 |
react-native-builder-bob | ^0.20.0 |
typescript | ^4.5.2 |
Peer Dependencies
ID | Version |
---|---|
react | * |
react-native | * |
Keywords
react-native
ios
android