百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
R

react-native-screenshot-aware

> 前端框架
开源

用于在 Android 和 iOS 上实时检测屏幕截图的 React Native 模块

363 stars0 点赞0 次浏览
访问官网GitHub

工具介绍

用于在 Android 和 iOS 上实时检测屏幕截图的 React Native 模块

React Native Screenshot Aware

Real-time screenshot detection for React Native apps

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.3.0 or later
  • React Native >=0.79, use version 1.3.10 or later

Installation

bash
yarn add react-native-screenshot-aware

or

bash
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

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

or add the permission manually to your app.json:

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:

xml

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

javascript
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

javascript
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

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

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

Jest Mocks

javascript
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

  • create-react-native-library for the initial project setup

Issues· 0 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

TypeScriptandroidiosreact-nativescreenshot

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月17日
分类前端框架
定价开源

> 相关工具

R
React
用于构建用户界面的 JavaScript 库
V
Vue.js
渐进式 JavaScript 框架
N
Next.js
基于 React 的全栈 Web 框架