npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@hxa-rn/react-native-events

v1.0.21

Published

Send and receive events from react native modules

Readme

react-native-events

本项目基于 react-native-events 开发,并适配 React Native for OpenHarmony。 如果在使用过程中有任何问题,可以在 GitCode 提交 Issue,我们会及时跟进。

项目介绍

react-native-events 为原生模块提供统一的 EventEmitter 能力,让原生代码与 JavaScript 之间能够发送和接收事件,并通过 conform 对齐 Node.js EventEmitter 接口。

  • 统一各平台的原生事件机制,原生模块可对齐 Node.js EventEmitter。
  • register / conform 注册与适配消费模块。
  • emitNativeEvent / emitJSEvent 分别向原生侧 / JavaScript 侧发送事件。
  • 前置订阅者(pre subscriber)与后置订阅者(subscriber)管理。
  • 适配后注入完整的 EventEmitter 方法集。

集成指南

安装

在 React Native 工程根目录执行:

npm install @hxa-rn/react-native-events

本库依赖 react-native >= 0.72,请确保宿主工程满足该版本要求。

Autolinking

安装依赖后由宿主工程自动接入,无需手动注册。

导入

import RNEvents from '@hxa-rn/react-native-events';

使用说明

基础用法

import { NativeModules } from 'react-native';
import RNEvents from '@hxa-rn/react-native-events';

const MyNativeModule = NativeModules.MyNativeModule;

// 注册并适配消费模块,使其对齐 EventEmitter
RNEvents.register(MyNativeModule);
RNEvents.conform(MyNativeModule);

// 接收事件
MyNativeModule.addListener('somethingHappened', (arg1, arg2) => {
  console.log('my event was called:', arg1, arg2);
});

// 发送事件
MyNativeModule.emit('somethingHappened', { a: 'ayy' }, { b: 'lmao' });

注册并适配后,即可在消费模块上使用 EventEmitter 的方法(如 on、once、removeListener 等)接收事件,并通过 emit 发送事件。emit 会先触发原生侧 onEvent / onJSEvent,再按 pre → main → post 顺序触发 JavaScript 监听器。

接口文档

以下 API 依据 src/index.ts 和相关类型定义整理。

RNEvents

RNEvents 是库的默认导出,用于注册与适配原生模块、发送事件以及管理订阅者。

| 方法 | 说明 | | --- | --- | | register(nativeModule) | 注册符合 RNEventConformer 的消费模块,分配只读 __rnEventsId,返回同一模块对象。 | | conform(nativeModule) | 为已注册模块注入 EventEmitter 的 14 个方法及复合 emit,返回同一模块对象。 | | emitNativeEvent(nativeModule, eventName, ...args) | 仅向原生侧发送事件,触发消费模块的 onEvent 与 onJSEvent。 | | emitJSEvent(nativeModule, eventName, ...args) | 仅按 pre → main → post 顺序向 JavaScript 侧分发事件。 | | addSubscriber(nativeModule, subscriber) | 添加后置订阅者(在模块监听器之后接收)。 | | removeSubscriber(nativeModule, subscriber) | 移除首个匹配的后置订阅者。 | | addPreSubscriber(nativeModule, subscriber) | 添加前置订阅者(在模块监听器之前接收)。 | | removePreSubscriber(nativeModule, subscriber) | 移除首个匹配的前置订阅者。 |

快速验证(运行 Example)

前置条件

| 依赖 | 版本要求 | | :-- | --- | | Node.js | >=18 | | React Native for OpenHarmony | 0.72.139 | | HarmonyOS SDK | API 22+ |

运行步骤

  1. 获取开发分支源码:

    git clone -b br_rnoh0.72_dev https://gitcode.com/hxa-rn/react-native-events.git
  2. 进入仓库根目录:

    cd react-native-events
  3. 安装根目录依赖:

    npm install
  4. 生成供示例工程安装的本地安装包:

    npm pack
  5. 进入 example 目录:

    cd example
  6. 安装示例工程依赖:

    npm install
  7. 生成 React Native JavaScript Bundle:

    npm run dev
  8. 使用 DevEco Studio 打开 example/harmony 工程,同步依赖、完成签名配置后构建运行。

约束与限制

兼容性

| 依赖 | 要求 | | --- | --- | | React Native for OpenHarmony | 0.72.139 | | HarmonyOS SDK | API 22+ | | Example 工程 compatibleSdkVersion | 6.0.2(22) | | Example 工程 targetSdkVersion | 26.0.0 | | Node.js | >=18 |

使用限制

  • 进入原生 TurboModule 的事件参数须满足 RNOH 可序列化约束:字符串、数字、布尔值、数组和普通对象可用;函数、Symbol、循环引用对象不支持跨原生边界。
  • 仅 JavaScript 的 emitJSEvent 不受上述跨边界限制。
  • 消费模块应在自身生命周期或 RNOH RELOAD 回调中调用 unregisterModule 释放原生路由。

系统权限

本库不依赖额外的 HarmonyOS 系统权限。

开源 License

本项目采用 MIT,与上游项目保持一致。

问题反馈渠道

如在使用过程中遇到问题,请在 GitCode 提交 Issue,我们会及时跟进。

  • 提交问题时建议附上项目版本、RN 版本、OpenHarmony SDK/API 版本、DevEco Studio 版本、设备信息、复现步骤及相关日志。
  • 涉及签名、账号、密钥或用户数据时,请勿在 Issue 中上传敏感信息;可按组织安全流程提交脱敏日志。