react-native-capture-protection
TypeScript icon, indicating that this package has built-in type declarations

2.1.1ย โ€ขย Publicย โ€ขย Published

๐Ÿ›ก๏ธ react-native-capture-protection

A React Native library to prevent screen capture, screenshots, and app switcher previewsโ€”providing enhanced security for your app.
Fully compatible with React Native CLI and Expo (Dev Client only).


๐Ÿ“ธ Screenshots

Screenshot Protection App Switcher Protection
Screen Recording App Switcher

โœจ Features

  • ๐Ÿ”’ iOS: Screenshot, Screen Recording & App Switcher protection
  • ๐Ÿ”’ Android: Screenshot & Screen Recording protection
  • ๐Ÿ“ก Event listeners for capture events
  • ๐Ÿงฉ Hooks & Provider support
  • ๐Ÿ“ฑ Android 14 support

๐Ÿš€ Installation

โš ๏ธ Using React Native < 0.70?
The latest v2.x version may not be compatible with versions below 0.70.
It is recommended to use v1.9.17 for better stability with older React Native projects.

Using npm

npm install react-native-capture-protection

Using yarn

yarn add react-native-capture-protection

Using with Expo

โš ๏ธ Expo Dev Client only This library includes native code, so it does not work with Expo Go. You must use a custom dev client.

npx expo install react-native-capture-protection

โš™๏ธ Android Configuration (Required)

Android 13 and Below: Enable Storage Permissions To detect screenshots on Android versions below 14, add the following

๐Ÿ”ง iOS Setup

If you're developing for iOS, don't forget to install CocoaPods dependencies after installing the package.

cd ios && pod install

React Native CLI

add to android/app/build.gradle

defaultConfig {
    ...
    missingDimensionStrategy "react-native-capture-protection", "fullMediaCapture"
}

Expo (Dev Client only)

add to app.json

{
  ...
  "plugins": [
    ...,
    [
      "react-native-capture-protection",
      {
        "captureType": "fullMediaCapture"
      }
    ]
  ]
}

Google Play Store Policy (READ_MEDIA_IMAGES)

If publishing to the Play Store, explain the usage of READ_MEDIA_IMAGES like this:

Used by the application to detect screenshots, by checking for screenshot files in the userโ€™s media storage.

Disable Capture Detection (Optional)

If you want to disable screenshot detection and only block recording/switcher:

React Native CLI

add to android/app/build.gradle

defaultConfig {
    ...
    missingDimensionStrategy "react-native-capture-protection", "restrictedCapture"
}

Expo (Dev Client only)

add to app.json

{
  ...
  "plugins": [
    ...,
    [
      "react-native-capture-protection",
      {
        "captureType": "restrictedCapture"
      }
    ]
  ]
}

๐Ÿ“ฆ Usage

import {
  CaptureProtection,
  useCaptureProtection,
  CaptureEventType
} from 'react-native-capture-protection';

const Component = () => {
  const { protectionStatus, status } = useCaptureProtection();

  React.useEffect(() => {
    // Prevent all capture events
    CaptureProtection.prevent();

    // Or prevent specific events
    CaptureProtection.prevent({
      screenshot: true,
      record: true,
      appSwitcher: true
    });
  }, []);

  React.useEffect(() => {
    // Check if any capture is prevented
    console.log('Prevent Status:', protectionStatus);

    // Check current protection status
    console.log('Protection Status:', status);
  }, [protectionStatus, status]);

  // Allow all capture events
  const onAllow = async () => {
    await CaptureProtection.allow();
  };

  // Allow specific events
  const onAllowSpecific = async () => {
    await CaptureProtection.allow({
      screenshot: true,
      record: false,
      appSwitcher: true
    });
  };

  // Check if screen is being recorded
  const checkRecording = async () => {
    const isRecording = await CaptureProtection.isScreenRecording();
    console.log('Is Recording:', isRecording);
  };

  return (
    // Your component JSX
  );
};

๐Ÿ“š Documentation

๐Ÿงช Methods โ€“ All available API methods

๐Ÿ“˜ Types โ€“ Type definitions and interfaces

๐Ÿ›  Migration Guide โ€“ From v1.x to v2.x

๐Ÿค Contributing

See CONTRIBUTING.md for details on contributing to this project.

๐Ÿ“„ License

MIT


Made with create-react-native-library

Package Sidebar

Install

npm i react-native-capture-protection

Weekly Downloads

4,259

Version

2.1.1

License

MIT

Unpacked Size

165 kB

Total Files

64

Last publish

Collaborators

  • wn-na