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

@react-native-ohos/react-native-shake

v6.1.0

Published

React Native shake event detector

Readme

模板版本:v0.4.2

本项目基于 react-native-shake 开发。

该第三方库的仓库已迁移至 Gitcode,且支持直接从 npm 下载,新的包名为:@react-native-ohos/react-native-shake 版本所属关系如下:

| 三方库名称 | 三方库版本(npm地址) | 发布信息 | 支持RN版本 | Autolink | 编译API版本 | 社区基线版本 | 源码地址 | | ------------ | ------------ | ------------------------------ | ------------- | ------------- |------------------------ | ------------- | ------------- | | @react-native-ohos/react-native-shake | ~ 6.1.0(开发中) | Gitcode Releases | 0.82.* | 是 | API12+ | 6.8.1 | br_rnoh0.82 | | @react-native-ohos/react-native-shake | ~ 6.0.3 | Gitcode Releases | 0.77.* | 否 | API12+ | 6.0.0-beta.2| br_rnoh0.77 | | @react-native-ohos/react-native-shake | ~ 5.6.4 | Gitcode Releases | 0.72.* | 是 | API12+ | 5.6.2 | br_rnoh0.72 | | @react-native-oh-tpl/react-native-shake | <= 5.6.2-0.0.1@deprecated | Github Releases(deprecated) | 0.72.* | 否 | API12+ | 5.6.2 | sig |

简介

一个监听手机摇一摇手势检测与回调的react-native三方库。

安装与使用

进入到工程目录并输入以下命令:

npm

npm install @react-native-ohos/react-native-shake

yarn

yarn add @react-native-ohos/react-native-shake

下面的代码展示了这个库的基本使用场景:

[!WARNING] 使用时 import 的库名不变。

import React, { useState } from 'react';
import { Text, View, StyleSheet } from 'react-native'
import RNShake from 'react-native-shake';

export function ShakeExample() {
    const [result, setResult] = useState<string>('')
    myComponent(setResult)
    return (
      <View style={styles.container}>
      <Text style={styles.title}>shake(摇晃手机)</Text>
      <Text style={styles.resultText}>{result}</Text>
  </View>
    )
}

export const myComponent = (setResult: React.Dispatch<React.SetStateAction<string>>) => {
    React.useEffect(() => {
        const subscription = RNShake.addListener(() => {
            setResult('shake listen success')
        })
        return () => {
            subscription.remove()
        }
    }, [])
}

const styles = StyleSheet.create({
  container: {
      flex: 1,
      backgroundColor: 'white',
      width: '100%',
      justifyContent: 'center',
      alignItems: 'center',
      padding: 20
  },
  title: {
      fontSize: 18,
      fontWeight: 'bold',
      marginBottom: 15,
      textAlign: 'center'
  },
  resultText: {
      fontSize: 16,
      color: '#2196F3',
      textAlign: 'center',
      marginTop: 10
  }
});

Link

| | 是否支持autolink | RN框架版本 | |--------------------------------------|-----------------|------------| | ~6.1.0 | 是 | 0.82 |

使用AutoLink的工程需要根据该文档配置,Autolink框架指导文档:https://gitcode.com/openharmony-sig/ohos_react_native/blob/master/docs/zh-cn/Autolinking.md

如您使用的版本支持 Autolink,并且工程已接入 Autolink,可跳过ManualLink配置。

首先需要使用 DevEco Studio 打开项目里的 HarmonyOS 工程 harmony

1.在工程根目录的 oh-package.json5 添加 overrides字段

{
  ...
  "overrides": {
    "@rnoh/react-native-openharmony" : "./react_native_openharmony"
  }
}

2.引入原生端代码

目前有两种方法:

  1. 通过 har 包引入(在 IDE 完善相关功能后该方法会被遗弃,目前首选此方法);
  2. 直接链接源码。

方法一:通过 har 包引入(推荐)

[!TIP] har 包位于三方库安装路径的 harmony 文件夹下。

打开 entry/oh-package.json5,添加以下依赖

"dependencies": {
    "@rnoh/react-native-openharmony": "file:../react_native_openharmony",
    "@react-native-ohos/react-native-shake": "file:../../node_modules/@react-native-ohos/react-native-shake/harmony/shake_package.har"
  }

点击右上角的 sync 按钮

或者在终端执行:

cd entry
ohpm install

方法二:直接链接源码

[!TIP] 如需使用直接链接源码,请参考直接链接源码说明

3.在 ArkTs 侧引入 ShakePackage

打开 entry/src/main/ets/RNPackagesFactory.ts,添加:

...
+ import { ShakePackage } from "@react-native-ohos/react-native-shake/ts";

export function createRNPackages(ctx: RNPackageContext): RNPackage[] {
  return [
    new SamplePackage(ctx),
+   new ShakePackage(ctx)
  ];
}

4.配置 CMakeLists 和引入 ShakePackage

若使用的是 <= 5.6.2-0.0.1 版本,请跳过本章。

打开 entry/src/main/cpp/CMakeLists.txt,添加:

project(rnapp)
cmake_minimum_required(VERSION 3.4.1)
set(RNOH_APP_DIR "${CMAKE_CURRENT_SOURCE_DIR}")
+set(OH_MODULES "${CMAKE_CURRENT_SOURCE_DIR}/../../../oh_modules")
set(RNOH_CPP_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../../../../../../react-native-harmony/harmony/cpp")

add_subdirectory("${RNOH_CPP_DIR}" ./rn)

# RNOH_BEGIN: add_package_subdirectories
add_subdirectory("../../../../sample_package/src/main/cpp" ./sample-package)

+ add_subdirectory("${OH_MODULES}/@react-native-ohos/react-native-shake/src/main/cpp" ./shake_package)
# RNOH_END: add_package_subdirectories

add_library(rnoh_app SHARED
    "./PackageProvider.cpp"
    "${RNOH_CPP_DIR}/RNOHAppNapiBridge.cpp"
)

target_link_libraries(rnoh_app PUBLIC rnoh)

# RNOH_BEGIN: link_packages
target_link_libraries(rnoh_app PUBLIC rnoh_sample_package)
+ target_link_libraries(rnoh_app PUBLIC rnoh_shake)
# RNOH_END: link_packages

打开 entry/src/main/cpp/PackageProvider.cpp,添加:

#include "RNOH/PackageProvider.h"
#include "SamplePackage.h"
+ #include "ShakePackage.h"

using namespace rnoh;

std::vector<std::shared_ptr<Package>> PackageProvider::getPackages(Package::Context ctx) {
    return {
      std::make_shared<SamplePackage>(ctx),
+     std::make_shared<ShakePackage>(ctx)
    };
}

运行

点击右上角的 sync 按钮

或者在终端执行:

cd entry
ohpm install

然后编译、运行即可。

约束与限制

兼容性

要使用此库,需要使用正确的 React-Native 和 RNOH 版本。另外,还需要使用配套的 DevEco Studio 和 手机 ROM。

在以下版本验证通过:

  1. RNOH: 0.82.22; SDK: HarmonyOS 6.0.0 Release SDK; IDE: DevEco Studio 6.0.0.878; ROM: 6.0.0.130;

权限要求

此库接口需要normal权限:ohos.permission.ACCELEROMETER,权限需配置在entry/src/main目录下module.json5文件中

 "requestPermissions": [
      {
        "name": "ohos.permission.ACCELEROMETER"
      }
    ]

API

[!TIP] "Platform"列表示该属性在原三方库上支持的平台。

[!TIP] "HarmonyOS Support"列为 yes 表示 HarmonyOS 平台支持该属性;no 则表示不支持;partially 表示部分支持。使用方法跨平台一致,效果对标 iOS 或 Android 的效果。

| Name | Description | Type | Required | Platform | HarmonyOS Support | | :--- | :--- | :--- | :--- | :--- | :--- | | addListener | 添加摇一摇事件监听 | function | yes | ios/android | yes | | removeAllListeners | 移除事件监听 | function | yes | ios/android | yes |

遗留问题

目录结构

/rntpc_react-native-shake  # 项目根目录
├── harmony              # 鸿蒙适配代码
│    └─ shake_package.har          # har包
│    └─ shake_package                  # 鸿蒙适配核心代码
│          └─ Index.ets    # 鸿蒙适配代码入口    
│          └─ ts.ets       # Package / TurboModule 导出
│          └─ src/main/ets  
│              └─ ShakePackage.ets       # RNOH Package 注册
│              └─ ShakeTuboModule.ts     # 实现 TurboModule 接口
│              └─ RNShakeModuleImpl.ts   # 摇晃检测实现
│          └─ src/main/cpp
│              └─ ShakePackage.h         # C++ Package
│              └─ RNShake.cpp / RNShake.h
├── src
│    └─ index.tsx        # RN 代码入口文件
│    └─ NativeShake.ts   # TurboModule 类型 / Spec
├── README_en.md           # 英文安装使用方法    
├── README.md   # 中文安装使用方法                  

贡献代码

使用过程中发现任何问题都可以提交 Issue,当然,也非常欢迎提交 PR

开源协议

本项目基于 The MIT License (MIT) ,请自由地享受和参与开源。