react-native-screenshot-aware

huextratMIT活跃维护

React Native 原生模块,能在 Android 和 iOS 上实时检测用户截屏动作,方便 App 在截图发生时触发提示、水印或埋点等响应。

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

v2.1.3发布于 2026-09-05 15:44 UTC374star8fork同步于 2026-11-10 12:01 UTC

怎么上手

从 README 代码块原样提取,可能是其中一种安装方式
yarn add react-native-screenshot-aware
npm install react-native-screenshot-aware
硬件要求

README 没有说明硬件要求。

下载:源码 zip·GitHub Releases(安装包)本站不镜像安装包

项目说明

这个项目的说明还在生成中,先参考下面「最近发版」和 README。

最近发版

5 个版本v2.1.3
  1. v2.1.3最新正式版2026-09-05 · 2026-09-05 15:44 UTC

    2.1.3 (2026-09-05)

    Bug Fixes

    • android: skip explicit Kotlin plugin when AGP registers the kotlin extension (#613) (c1f8fb0)
  2. v2.1.22026-08-29 · 2026-08-29 22:48 UTC
    查看更新说明

    2.1.2 (2026-08-29)

    Bug Fixes

    • deps: update dependency react-native to v0.87.1 (#609) (061798c)
  3. v2.1.12026-08-28 · 2026-08-28 15:13 UTC
    查看更新说明

    2.1.1 (2026-08-28)

    Bug Fixes

  4. v2.1.02026-08-28 · 2026-08-28 15:05 UTC
    查看更新说明

    2.1.0 (2026-08-28)

    Features

    • refresh dependencies and Renovate configuration (#601) (595404d)
  5. v2.0.02026-03-07 · 2026-03-07 14:15 UTC
    查看更新说明

    2.0.0 (2026-03-07)

用户点评

登录用户的真实使用记录,可按版本和硬件筛选
共 0 条

    还没有人点评。第一个说出真实体验的人最有价值。

    README 原文

    未翻译

    React Native Screenshot Aware

    v2 is here: Version 2 supports only the New Architecture. Versions older than v2 are no longer maintained.

    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+
    • 🏗️ New Architecture only

    Compatibility

    • v2: New Architecture only. No legacy architecture support.
    • v1.x and below: No longer maintained.
    • React Native <0.76, use version 1.2.2 or below 1.2.0 of this package (1.2.1 is buggy)
    • React Native >=0.76, use version 1.3.0 or later
    • React Native >=0.79, use version 1.3.10 or later

    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

    Expo

    For Expo projects, you can use the Expo plugin in app.json

    "plugins": [
      "react-native-screenshot-aware"
    ],
    

    or add the permission manually to your app.json:

    "android": {
      "permissions": ["android.permission.DETECT_SCREEN_CAPTURE"]
    }
    

    Bare RN

    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