[BREAKGLASS] 🛡️ A React Native library to prevent and detect for screen capture, screenshots and app switcher for enhanced security. Fully compatible with both Expo and CLI. https://www.npmjs.com/package/react-native-capture-protection https://www.npmjs.com/package/react-native-capture-protection https://www.npmjs.com/package/react-native-capture-protection
Go to file
2026-03-18 13:34:20 +09:00
.github chore: remove github action 2025-04-03 22:47:34 +09:00
android fix: productFlavors 2025-12-26 13:31:53 +09:00
docs docs: Add example 2025-05-10 10:56:41 +09:00
example@85bc31c85c chore: update example 2025-04-13 13:29:18 +09:00
ios fix: config is immutable 2025-11-30 12:44:32 +09:00
jest feat: support mock 2025-10-09 14:06:42 +09:00
plugins fix: productFlavors 2025-12-26 13:31:53 +09:00
src fix: remove return value 2026-01-24 18:33:36 +09:00
.gitattributes chore: initial commit 2022-12-02 09:47:36 +09:00
.gitignore chore: update example app for RN 0.73 2024-02-08 15:13:13 +09:00
.gitmodules chore: submodule example 2025-03-18 22:05:17 +09:00
.nvmrc feat: nvmrc 2022-12-06 13:44:03 +09:00
.watchmanconfig chore: initial commit 2022-12-02 09:47:36 +09:00
app.plugin.js feat: support expo plugin 2025-06-28 11:44:59 +09:00
babel.config.js chore: initial commit 2022-12-02 09:47:36 +09:00
CODE_OF_CONDUCT.md chore: initial commit 2022-12-02 09:47:36 +09:00
CONTRIBUTING.md chore: initial commit 2022-12-02 09:47:36 +09:00
lefthook.yml chore: initial commit 2022-12-02 09:47:36 +09:00
LICENSE chore: initial commit 2022-12-02 09:47:36 +09:00
package.json fix: support web 2026-01-24 18:13:35 +09:00
react-native-capture-protection.podspec feat: support ios new architecture 2025-08-17 19:44:52 +09:00
README.md Clarify different dimensions in README.md for Android below 14 2026-03-18 13:34:20 +09:00
tsconfig.build.json fix: codegen not work 2025-08-23 20:50:04 +09:00
tsconfig.json fix: codegen 2025-08-23 15:37:27 +09:00
turbo.json fix: Package does not contain valid config plugin 2025-11-01 19:40:26 +09:00

🛡️ 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

🔧 iOS Setup

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

cd ios && pod install

⚙️ Android Configuration (Required)

By default, it supports capture prevention, capture permission, and capture detection on Android 14 and above. On Android versions below 14 (Android 10-13), capture prevention and capture permission are supported by default; if you want capture detection support too, please refer to the Capture Detection Before Android 14 (Optional) below.

React Native CLI

add to android/app/build.gradle

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

Expo (Dev Client only)

add to app.json

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

Capture Detection Before Android 14 (Optional)

On Android versions below 14 (Android 10-13), capture prevention and capture permission are supported by default and require no more steps. However, if you want capture detection to work on Android versions below 14, please configure the settings as follows (it detects screen captures using the sensitive READ_MEDIA_IMAGES permission):

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 users media storage.

React Native CLI

add to android/app/build.gradle

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

Expo (Dev Client only)

add to app.json

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

📦 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
  );
};

Jest integration

With Jest Setup

  1. Add to your jest.config.js:
module.exports = {
  setupFilesAfterEnv: ['<rootDir>/jest.setup.js'],
};
  1. Create jest.setup.js:
jest.mock('react-native-capture-protection', () =>
  require('react-native-capture-protection/jest/capture-protection-mock')
);

Overriding mock

import { CaptureProtection } from "react-native-capture-protection/jest/capture-protection-mock";

...

    test("prevent is called", async () => {
        await CaptureProtection.prevent();
        expect(CaptureProtection.prevent).toHaveBeenCalled();
    });

📚 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