registerScreenguardPartially 新增 ✨
针对屏幕上的特定视图区域(而非整个屏幕)在截图和录屏中激活 screenguard。(仅限 iOS)
Available from v2.0.2+
v2.0.0+ 要求
在使用此函数之前,必须先调用 initSettings()。
参数
接受一个包含以下参数的 JS 对象:
| 名称 | 是否必填 | 类型 | 默认值 | 描述 |
|---|---|---|---|---|
| viewRef | 是 | React.RefObject<any> | 指向已挂载组件的 React ref。通过 measureInWindow() 测量其屏幕位置和尺寸。 | |
| backgroundColor | 否 | string | '#000000'(黑色) | 用于在截图中填充/遮盖区域的十六进制颜色字符串。 |
注意
此函数仅支持内容或尺寸变化较少的静态屏幕。不支持位置频繁变化的组件,或包含 ScrollView 的屏幕。
示例代码
import React, { useRef } from 'react';
import { View, Text, Button } from 'react-native';
import ScreenGuardModule from 'react-native-screenguard';
const App = () => {
const sensitiveRef = useRef<View>(null);
const enablePartialGuard = async () => {
// 首先初始化(v2.0.0+ 中必需)
await ScreenGuardModule.initSettings();
// 仅遮盖敏感视图区域
await ScreenGuardModule.registerScreenguardPartially({
viewRef: sensitiveRef,
backgroundColor: '#000000',
});
};
return (
<View>
<View ref={sensitiveRef}>
<Text>此内容将在截图中被遮盖</Text>
</View>
<Button title="启用 Guard" onPress={enablePartialGuard} />
</View>
);
};
演示
iOS