Skip to content

tomruijgrok/react-native-screenshot-prevent

This branch is 24 commits behind killserver/react-native-screenshot-prevent:main.

Folders and files

NameName
Last commit message
Last commit date

Latest commit

872edcc · Jun 23, 2023

History

62 Commits
Mar 9, 2023
Jun 16, 2023
Jun 23, 2023
May 18, 2021
Jun 23, 2023
May 18, 2021
Mar 7, 2023
Jun 19, 2023
Jun 23, 2023
Jun 23, 2023
May 7, 2023
Jun 23, 2023
Jun 23, 2023

Repository files navigation

SWUbanner

react-native-screenshot-prevent

This fork contains fully working blank screenshot 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

  1. In XCode, in the project navigator, right click LibrariesAdd Files to [your project's name]
  2. Go to node_modulesreact-native-screenshot-prevent and add RNScreenshotPrevent.xcodeproj
  3. In XCode, in the project navigator, select your project. Add libRNScreenshotPrevent.a to your project's Build PhasesLink Binary With Libraries
  4. Run your project (Cmd+R)<

Android

  1. Open up android/app/src/main/java/[...]/MainActivity.java
  • Add import com.killserver.screenshotprev.RNPreventScreenshotPackage; to the imports at the top of the file
  • Add new RNPreventScreenshotPackage() to the list returned by the getPackages() method
  1. 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')
    
  2. Insert the following lines inside the dependencies block in android/app/build.gradle:
      compile 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
 */
RNPreventScreenshot.enabled(true/false);

/* (IOS) enableSecureView for IOS13+ 
 * creates a hidden secureTextField which prevents Application UI capture on screenshots
 */
if(!__DEV__) RNPreventScreenshot.enableSecureView();

/* (IOS) disableSecureView for IOS13+ 
 * remove a hidden secureTextField which prevents Application UI capture on screenshots
 */
if(!__DEV__) RNPreventScreenshot.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 = RNPreventScreenshot.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();
	}
}, []);

"Buy Me A Coffee"

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Objective-C 80.0%
  • TypeScript 9.3%
  • Java 8.5%
  • Ruby 2.2%