npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

react-native-capture-protection

v2.3.5

Published

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

Readme

🛡️ 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
  );
};

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