# @futurejj/react-native-visibility-sensor 中文文档

规范地址：https://npmcn.com/package/%40futurejj/react-native-visibility-sensor/

版本：1\.4\.19
npm 元数据更新时间：2026-10-25T11:35:14.621Z
中文译文更新时间：2026-11-15T18:56:55.035Z
软件包许可：MIT

本文由上游 README 翻译，可能存在偏差，请结合原文核对 API、命令与配置。版权与许可归原作者所有。

原始 npm 页面：https://www.npmjs.com/package/%40futurejj/react-native-visibility-sensor
原文对照：https://npmcn.com/package/%40futurejj/react-native-visibility-sensor/?lang=original
项目主页：https://github.com/JairajJangle/react-native-visibility-sensor#readme
源码仓库：https://github.com/JairajJangle/react-native-visibility-sensor

## 关键信息（来自 npm 元数据）

- 包体积（解压后）：59.8 kB，26 个文件
- 模块格式：ESM + CJS
- TypeScript 类型：包内自带
- Node.js 要求：\>=22
- 运行依赖：0 个
- peer 依赖：react \*，react-native \*
- 首次发布：2024-05-09T04:37:19.235Z
- 最新版本发布：2026-10-25T11:35:14.275Z
- 近 30 天下载量：81512（2026-10-16 至 2026-11-14，npm 官方下载统计）
- 已发布版本数：58（近 12 个月 15 个）

## 中文简介

用于检查一个组件是否在视图端口以跟踪印象并点击的回放本地包装器

## 安装

```sh
npm install @futurejj/react-native-visibility-sensor
```

也可以使用：`pnpm add @futurejj/react-native-visibility-sensor`、`yarn add @futurejj/react-native-visibility-sensor`、`bun add @futurejj/react-native-visibility-sensor`

## README

# @futurejj/反应-本土-可见-传感器

QQ 组件能见度传感器包, 以感知一个组件是否处于可配置的插入阈值和%能见度回调的视图中 .

[![npm version](https://img.shields.io/npm/v/%40futurejj%2Freact-native-visibility-sensor)](https://badge.fury.io/js/%40futurejj%2Freact-native-visibility-sensor) [![License](https://img.shields.io/github/license/JairajJangle/react-native-visibility-sensor)](https://github.com/JairajJangle/react-native-visibility-sensor/blob/main/LICENSE) [![Workflow Status](https://github.com/JairajJangle/react-native-visibility-sensor/actions/workflows/ci.yml/badge.svg)](https://github.com/JairajJangle/react-native-visibility-sensor/actions/workflows/ci.yml) ![Android](https://img.shields.io/badge/-Android-555555?logo=android&logoColor=3DDC84) ![iOS](https://img.shields.io/badge/-iOS-555555?logo=apple&logoColor=white) ![Web](https://img.shields.io/badge/-Web-555555?logo=google-chrome&logoColor=0096FF) [![GitHub issues](https://img.shields.io/github/issues/JairajJangle/react-native-visibility-sensor)](https://github.com/JairajJangle/react-native-visibility-sensor/issues?q=is%3Aopen+is%3Aissue) ![TS](https://img.shields.io/badge/TypeScript-strict_%F0%9F%92%AA-blue) [![Expo Snack 1](https://img.shields.io/badge/Expo%20Snack-555555?style=flat&logo=expo&logoColor=white)](https://snack.expo.dev/@futurejj/react-native-visibility-sensor-example) [![Expo Snack 2](https://img.shields.io/badge/Expo%20Snack-555555?style=flat&logo=expo&logoColor=white)](https://snack.expo.dev/@futurejj/react-native-visibility-sensor-nested-scrollview) ![NPM Downloads](https://img.shields.io/npm/dm/%40futurejj%2Freact-native-visibility-sensor) ![npm bundle size](https://img.shields.io/bundlephobia/minzip/%40futurejj%2Freact-native-visibility-sensor) [![Sponsor](https://img.shields.io/badge/Sponsor-GitHub-ea4aaa?style=flat&logo=github-sponsors)](https://github.com/sponsors/JairajJangle)

![Visibility Sensor demo](https://media2.giphy.com/media/v1.Y2lkPTc5MGI3NjExOXN4ZWs5ejdiYmZ5Zm5xaWw5YXZ5OGYwMmczcnFneXNiYW5hcDh6cCZlcD12MV9pbnRlcm5hbF9naWZfYnlfaWQmY3Q9Zw/gEbrrDtgnoq6Fs8FNq/giphy.gif) ![Visibility Sensor nested scroll view demo](https://media0.giphy.com/media/v1.Y2lkPTc5MGI3NjExdWJocG1idG5jODRmM20xdzd0a3Zlb25rdjIxZWRrdzhreHJpOWd2aiZlcD12MV9pbnRlcm5hbF9naWZfYnlfaWQmY3Q9Zw/ITFXieDSZ0lWaFcrwC/giphy.gif)

## 使用大小写

-   **懒惰装入**: 只有在可见时才装入图像/内容,以优化种子、画廊、图表或网页视图中的性能.
-   **滚动动画**:用于进入取景口的组件的触发动画(如:已淡出,已滑出).
-   **分析跟踪**: 在设定持续时间或百分比内可见的广告/广告的日志印象.
-   **动态 UI 优化**:暂停/重播视频,根据组件能见度在种子或旋转木马中清理出屏幕组件或定时器.

## 安装

使用线条

```sh
yarn add @futurejj/react-native-visibility-sensor
```

使用 npm :

```sh
npm install @futurejj/react-native-visibility-sensor
```

## 使用量

```tsx
import React, { useState } from 'react';
import { ScrollView, Text } from 'react-native';
import { VisibilitySensor } from '@futurejj/react-native-visibility-sensor';

export default function VisibilitySensorExample() {
  const [isVisible, setIsVisible] = useState(false);
  const [percentVisible, setPercentVisible] = useState<number>(0);

  return (
    <ScrollView>
      <VisibilitySensor
        onChange={setIsVisible}
        onPercentChange={setPercentVisible} // optional callback for % change
        threshold={{ top: 100, bottom: 100 }}
        style={[styles.item, { backgroundColor: isVisible ? 'green' : 'red' }]}>
          
        {/* Visibility state */}
        <Text>This View is currently visible? {isVisible ? 'yes' : 'no'}</Text>

        {/* Percent visibility state */}
        <Text>{`Percent visible: ${percentVisible}%`}</Text>
      </VisibilitySensor>
    </ScrollView>
  );
}
```

### 属性

`VisibilitySensorProps` 扩展 `ViewProps` 包含所有视图的共同属性,例如 `style`, (中文(简体) ), `onLayout`等 (中文(简体) ).

| 财产 | 类型 | 需求 | 说明 |
| --- | --- | --- | --- |
| `onChange` | `(visible: boolean) => void` | 对 | 调用函数, 当可见度改变时会点火 . |
| `onPercentChange` | `(percentVisible: number) => void` | 没有 | 调用函数, 当可见度% 变化时点火 . |
| `disabled` | `boolean` | 没有 | 若为 `true`,关闭传感器. |
| `triggerOnce` | `boolean` | 没有 | 若为 `true`传感器只会触发一次. |
| `delay` | `number` 或者说 `undefined` | 没有 | 传感器触发前以毫秒计的延迟. |
| `threshold` | [可见感应阈值](https://npmcn.com/package/%40futurejj/react-native-visibility-sensor/#readme-visibilitysensorthreshold) | 没有 | 定义传感器触发时必须可见的视图部分. |

此外,所有属性来自 `ViewProps` 也适用.

* * *

### 可见感应阈值

| 财产 | 类型 | 需求 | 说明 |
| --- | --- | --- | --- |
| `top` | `number` | 没有 | 可见度最高阈值. |
| `bottom` | `number` | 没有 | 可见度的下限值 . |
| `left` | `number` | 没有 | 可见度的左阈值 . |
| `right` | `number` | 没有 | 可见度的正确阈值 . |

* * *

## 页:1

1.  面对Android的问题? 参考这次讨论: [https://github.com/JairajJangle/ react-native-visibility-senor/pull/1#issuecomment-2251569005 (英语)](https://github.com/JairajJangle/react-native-visibility-sensor/pull/1#issuecomment-2251569005)

## 捐款

见 [贡献指南](https://npmcn.com/package/%40futurejj/react-native-visibility-sensor/CONTRIBUTING.md) 学习如何为储存库和发展工作流程作出贡献.

## 许可证

麻省理工学院

## 支持项目

 [![LiberPay\_Donation\_Button](https://liberapay.com/assets/widgets/donate.svg)](https://liberapay.com/FutureJJ/donate)          [![Paypal\_Donation\_Button](https://npmcn.com/package/%40futurejj/react-native-visibility-sensor/.github/assets/upi.png) ](https://npmcn.com/package/%40futurejj/react-native-visibility-sensor/.github/assets/Jairaj_Jangle_Google_Pay_UPI_QR_Code.jpg)          [![Paypal\_Donation\_Button](https://npmcn.com/package/%40futurejj/react-native-visibility-sensor/.github/assets/paypal_donate.png)](https://www.paypal.com/paypalme/jairajjangle001/usd)

## 谢谢

-   模块使用 [创建- 反应- 本土- 图书馆](https://github.com/callstack/react-native-builder-bob)
-   叉从( D) : [反应-内生-组件-视图](https://github.com/changey/react-native-component-inview) 打开 [@se09deluca/反应-本土-组件-inview](https://github.com/se09deluca/react-native-component-inview)
-   Pokemon 图像来源 : [波克蒙DB](https://pokemondb.net/)
-   Readme 编辑时使用 [泰波拉语Name](https://typora.io/)

* * *

## 常见问题

### @futurejj/react-native-visibility-sensor 是什么？

用于检查一个组件是否在视图端口以跟踪印象并点击的回放本地包装器

### 如何安装 @futurejj/react-native-visibility-sensor？

在项目目录运行 npm install @futurejj/react-native-visibility-sensor，或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖：react（\*）、react-native（\*）。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖，Yarn 需要手动安装。

### @futurejj/react-native-visibility-sensor 支持 TypeScript 吗？

支持。包内自带 TypeScript 类型声明（package\.json 声明了 types 入口），安装后即可获得类型提示，无需再安装 @types 包。

### @futurejj/react-native-visibility-sensor 支持 ESM 还是 CommonJS？

同时提供 ES Module 与 CommonJS 入口，import 和 require\(\) 都可以使用，打包工具会自动选择合适的版本。

### @futurejj/react-native-visibility-sensor 需要什么版本的 Node\.js？

package\.json 的 engines 字段要求 Node\.js \>=22。版本不符时 npm 默认只给出警告，开启 engine-strict 后会拒绝安装。

### @futurejj/react-native-visibility-sensor 可以商用吗？

@futurejj/react-native-visibility-sensor 使用 MIT 许可。宽松许可：允许商业使用、修改和再分发，通常只需在分发时保留原版权与许可声明。以上为概括，不构成法律意见，请以许可原文为准。

### @futurejj/react-native-visibility-sensor 的下载量有多少？

根据 npm 官方下载统计，@futurejj/react-native-visibility-sensor 在 2026/10/16 – 2026/11/14 这 30 天内被下载 81,512 次，日均约 2,717 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入，适合横向比较热度，不能直接等同于使用人数。

### @futurejj/react-native-visibility-sensor 还在维护吗？

最新版本 1\.4\.19 发布于 2026/10/25（21 天前）；至今共发布 58 个版本，其中过去 12 个月发布了 15 个；首次发布于 2024/05/09。发布频率只是参考信号：功能稳定的工具可能很少需要更新，建议结合源码仓库的 issue 和提交记录判断。

