New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

react-native-screenshot-aware

Package Overview
Dependencies
Maintainers
0
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-native-screenshot-aware

React Native module for real-time screenshot detection on Android and iOS

  • 1.0.6
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1.4K
decreased by-35.59%
Maintainers
0
Weekly downloads
 
Created
Source

React Native Screenshot Aware

npm version npm downloads license

Real-time screenshot detection for React Native apps

Features

  • 🚀 Real-time screenshot detection
  • 🔄 Cross-platform support (iOS & Android)
  • 🎣 Easy-to-use React hooks
  • ⚡ Optimized for performance
  • 📱 Supports Android 14+ (API level 34+) and iOS 14+
  • 🏗️ Supports the new architecture for React Native

Installation

yarn add react-native-screenshot-aware

or

npm install react-native-screenshot-aware

Important Notes

Android

  • Supports Android 14+ (API level 34 and above)
  • Utilizes the latest Android API for efficient screenshot detection
  • Leverages the new DETECT_SCREEN_CAPTURE permission introduced in Android 14
  • Provides a more privacy-friendly and performant approach to screenshot detection

Permissions

To use the screenshot detection feature on Android, you need to add the following permission to your AndroidManifest.xml file:

<uses-permission android:name="android.permission.DETECT_SCREEN_CAPTURE" />

Note: Callbacks will never be triggered on devices running Android versions below 14. This is due to the reliance on the new DETECT_SCREEN_CAPTURE permission and APIs introduced in Android 14, which are not available in earlier versions.

Note: The decision to support only Android 14+ is based on the introduction of new, dedicated screenshot detection APIs. These APIs offer improved performance and respect user privacy better than previous methods. For more details, see the Android 14 screenshot detection documentation.

API Reference

useScreenshotAware(callback)

This hook allows you to detect when a screenshot is taken on the device. It takes a callback function as an argument, which will be executed whenever a screenshot event is detected.

Parameters
  • callback (function): A function to be called when a screenshot is detected. This function does not take any arguments.
Example
import { useScreenshotAware } from 'react-native-screenshot-aware';

useScreenshotAware(() => {
  console.log('A screenshot was taken!');
});

addListener(callback)

This function allows you to add a listener for the screenshot event. It takes a callback function as an argument, which will be executed whenever a screenshot event is detected.

Parameters
  • callback (function): A function to be called when a screenshot is detected. This function does not take any arguments.
Example
import ScreenshotAware from 'react-native-screenshot-aware';

useEffect(() => {
  const listener = ScreenshotAware.addListener(() => {
    console.log('A screenshot was taken!');
  });
  return () => {
    listener.remove();
  }
}, [])

removeAllListeners()

This function allows you to remove all listeners for the screenshot event.

Example
import ScreenshotAware from 'react-native-screenshot-aware';

function removeScreenshotListeners() {
  ScreenshotAware.removeAllListeners();
}

Jest Mocks

jest.mock('react-native-screenshot-aware', () => ({
  useScreenshotAware: jest.fn(),
  addListener: jest.fn().mockReturnValue({
    remove: jest.fn(),
  }),
  removeAllListeners: jest.fn(),
}));

Contributing

We welcome contributions! Please see our Contributing Guide for more details.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Support

If you like this project, please consider supporting it by giving it a ⭐️ on GitHub!

Acknowledgements

Keywords

FAQs

Package last updated on 21 Jan 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc