From 3ee5162079cbd79ac946f3db1f39b41d0e7bd0ad Mon Sep 17 00:00:00 2001 From: xiawenqiang Date: Mon, 3 Jun 2024 11:18:36 +0800 Subject: [PATCH 1/3] =?UTF-8?q?docs:=20[Issues:=20#I9OYIF]=20=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0react-native-safe-module=E6=8C=87=E5=AF=BC=E6=96=87?= =?UTF-8?q?=E6=A1=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- zh-cn/react-native-safe-module.md | 134 ++++++++++++++++++++++++++++++ 1 file changed, 134 insertions(+) create mode 100644 zh-cn/react-native-safe-module.md diff --git a/zh-cn/react-native-safe-module.md b/zh-cn/react-native-safe-module.md new file mode 100644 index 00000000..95f44b9f --- /dev/null +++ b/zh-cn/react-native-safe-module.md @@ -0,0 +1,134 @@ +> 模板版本:v0.2.1 + +

+

react-native-safe-module

+

+

+ + Supported platforms + + + License + +

+ +> [!TIP] [Github 地址](https://github.com/react-native-oh-library/react-native-safe-module) + +## 安装与使用 + +请到三方库的 Releases 发布地址查看配套的版本信息:[@react-native-oh-tpl/react-native-safe-module Releases](https://github.com/react-native-oh-library/react-native-safe-module/releases),并下载适用版本的 tgz 包。 + + +进入到工程目录并输入以下命令: + +> [!TIP] # 处替换为 tgz 包的路径 + + + +#### **npm** + +```bash +npm install @react-native-oh-tpl/react-native-safe-module@file:# +``` + +#### **yarn** + +```bash +yarn add @react-native-oh-tpl/react-native-safe-module@file:# +``` + + + +下面的代码展示了这个库的基本使用场景: + +> [!WARNING] 使用时 import 的库名不变。 + +## 用法 + +Importing `SafeModule` is as simple as: + +```js +import SafeModule from 'react-native-safe-module'; +``` + +### 基本用法 + +If you were using a Native Module before, such as `NativeModules.FooModule` +like this: + +```js +import { NativeModules } from 'react-native'; +const { FooModule } = NativeModules; + +// ... + +FooModule.doSomething().then(...) + +``` + +You can instead do: + +```js +import SafeModule from 'react-native-safe-module'; +const FooModule = SafeModule.create({ + moduleName: 'FooModule', + mock: { + doSomething: () => Promise.resolve(...), + }, +}); + +// ... + +FooModule.doSomething().then(...) +``` + +## 约束与限制 + +### 兼容性 + +要使用此库,需要使用正确的 React-Native 和 RNOH 版本。另外,还需要使用配套的 DevEco Studio 和 手机 ROM。 + +请到三方库相应的 Releases 发布地址查看 Release 配套的版本信息:[Releases](https://github.com/react-native-oh-library/react-native-safe-module/releases) + +本文档内容基于以下版本验证通过: + +1. RNOH: 0.72.20; SDK:HarmonyOS NEXT Developer Preview2; IDE:DevEco Studio 5.0.3.200; ROM:3.0.0.18; + +## 方法 + +> [!tip] "Platform"列表示该属性在原三方库上支持的平台。 + +> [!tip] "HarmonyOS Support"列为 yes 表示 HarmonyOS 平台支持该属性;no 则表示不支持;partially 表示部分支持。使用方法跨平台一致,效果对标 iOS 或 Android 的效果。 + + +Name | Description | Type | Required | HarmonyOS Support +-- | -- | -- | -- | -- +SafeModule.create(options) | 创建Module | Function | Yes | Yes | + + +## 属性 + +> [!tip] "Platform"列表示该属性在原三方库上支持的平台。 + +> [!tip] "HarmonyOS Support"列为 yes 表示 HarmonyOS 平台支持该属性;no 则表示不支持;partially 表示部分支持。使用方法跨平台一致,效果对标 iOS 或 Android 的效果。 + +**options**:SafeModule.create(options) 方法的参数 + +| Name | Description | Type | Required | Platform | HarmonyOS Support | +| --------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------- | -------- | -------- | -------- | ----------------- | +| options.moduleName | The name, or array of names, to look for the module at on the NativeModules namespace. | string/Array | Yes | All | Yes | +| options.mock | The mock implementation of the native module. | mixed | Yes | All | Yes | +| options.getVersion | A function that returns the version of the native module. Only needed if you are specifying overrides and not exporting a VERSION property on your native module. Defaults to x => x.VERSION. | (module) => string/number | No | All | Yes | +| options.overrides | A map of version numbers to overridden implementations of the corresponding property/method. If an overridden property or method is a function, it will be called during SafeModule.create(...) with two arguments, the original value of that property on the original module, and the original module itself. The return value of this function will be put on the return value of SafeModule.create(...). | [version: string]: mixed | No | All | Yes | +| options.isEventEmitter | A flag indicating that the native module is expected to be an EventEmitter. Puts the EventEmitter instance on the emitter property of the resulting module. Defaults to false. | bool | No | All | Yes | + + + +## 遗留问题 + + +## 其他 + +## 开源协议 + +本项目基于 [MIT License](https://github.com/react-native-oh-library/react-native-safe-module/blob/master/LICENSE) ,请自由地享受和参与开源。 \ No newline at end of file -- Gitee From a1b6fcebc81f7d64f72299e1c76a0cb536bd38e2 Mon Sep 17 00:00:00 2001 From: xiawenqiang Date: Wed, 26 Jun 2024 15:57:49 +0800 Subject: [PATCH 2/3] =?UTF-8?q?docs:=20[Issues:=20#I9OYIF]=20=E4=BF=AE?= =?UTF-8?q?=E6=94=B9react-native-safe-module=E6=8C=87=E5=AF=BC=E6=96=87?= =?UTF-8?q?=E6=A1=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- zh-cn/react-native-safe-module.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/zh-cn/react-native-safe-module.md b/zh-cn/react-native-safe-module.md index 95f44b9f..7440beb8 100644 --- a/zh-cn/react-native-safe-module.md +++ b/zh-cn/react-native-safe-module.md @@ -1,4 +1,5 @@ -> 模板版本:v0.2.1 + +> 模板版本:v0.2.2

react-native-safe-module

@@ -131,4 +132,5 @@ SafeModule.create(options) | 创建Module | Function | Yes | Yes | ## 开源协议 -本项目基于 [MIT License](https://github.com/react-native-oh-library/react-native-safe-module/blob/master/LICENSE) ,请自由地享受和参与开源。 \ No newline at end of file +本项目基于 [MIT License](https://github.com/react-native-oh-library/react-native-safe-module/blob/master/LICENSE) ,请自由地享受和参与开源。 + \ No newline at end of file -- Gitee From f150ecf6d96a9d2a2a74cf42f9752acab9405f7d Mon Sep 17 00:00:00 2001 From: wuleilei <244295790@qq.com> Date: Wed, 3 Jul 2024 10:56:46 +0800 Subject: [PATCH 3/3] =?UTF-8?q?docs:=20[Issues:=20#I9OYIF]=20=E4=BF=AE?= =?UTF-8?q?=E6=94=B9react-native-safe-module=E6=8C=87=E5=AF=BC=E6=96=87?= =?UTF-8?q?=E6=A1=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- zh-cn/react-native-safe-module.md | 64 ++----------------------------- 1 file changed, 3 insertions(+), 61 deletions(-) diff --git a/zh-cn/react-native-safe-module.md b/zh-cn/react-native-safe-module.md index 7440beb8..fe77ad69 100644 --- a/zh-cn/react-native-safe-module.md +++ b/zh-cn/react-native-safe-module.md @@ -8,7 +8,7 @@ Supported platforms - + License

@@ -44,31 +44,6 @@ yarn add @react-native-oh-tpl/react-native-safe-module@file:# > [!WARNING] 使用时 import 的库名不变。 -## 用法 - -Importing `SafeModule` is as simple as: - -```js -import SafeModule from 'react-native-safe-module'; -``` - -### 基本用法 - -If you were using a Native Module before, such as `NativeModules.FooModule` -like this: - -```js -import { NativeModules } from 'react-native'; -const { FooModule } = NativeModules; - -// ... - -FooModule.doSomething().then(...) - -``` - -You can instead do: - ```js import SafeModule from 'react-native-safe-module'; const FooModule = SafeModule.create({ @@ -89,40 +64,7 @@ FooModule.doSomething().then(...) 要使用此库,需要使用正确的 React-Native 和 RNOH 版本。另外,还需要使用配套的 DevEco Studio 和 手机 ROM。 -请到三方库相应的 Releases 发布地址查看 Release 配套的版本信息:[Releases](https://github.com/react-native-oh-library/react-native-safe-module/releases) - -本文档内容基于以下版本验证通过: - -1. RNOH: 0.72.20; SDK:HarmonyOS NEXT Developer Preview2; IDE:DevEco Studio 5.0.3.200; ROM:3.0.0.18; - -## 方法 - -> [!tip] "Platform"列表示该属性在原三方库上支持的平台。 - -> [!tip] "HarmonyOS Support"列为 yes 表示 HarmonyOS 平台支持该属性;no 则表示不支持;partially 表示部分支持。使用方法跨平台一致,效果对标 iOS 或 Android 的效果。 - - -Name | Description | Type | Required | HarmonyOS Support --- | -- | -- | -- | -- -SafeModule.create(options) | 创建Module | Function | Yes | Yes | - - -## 属性 - -> [!tip] "Platform"列表示该属性在原三方库上支持的平台。 - -> [!tip] "HarmonyOS Support"列为 yes 表示 HarmonyOS 平台支持该属性;no 则表示不支持;partially 表示部分支持。使用方法跨平台一致,效果对标 iOS 或 Android 的效果。 - -**options**:SafeModule.create(options) 方法的参数 - -| Name | Description | Type | Required | Platform | HarmonyOS Support | -| --------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------- | -------- | -------- | -------- | ----------------- | -| options.moduleName | The name, or array of names, to look for the module at on the NativeModules namespace. | string/Array | Yes | All | Yes | -| options.mock | The mock implementation of the native module. | mixed | Yes | All | Yes | -| options.getVersion | A function that returns the version of the native module. Only needed if you are specifying overrides and not exporting a VERSION property on your native module. Defaults to x => x.VERSION. | (module) => string/number | No | All | Yes | -| options.overrides | A map of version numbers to overridden implementations of the corresponding property/method. If an overridden property or method is a function, it will be called during SafeModule.create(...) with two arguments, the original value of that property on the original module, and the original module itself. The return value of this function will be put on the return value of SafeModule.create(...). | [version: string]: mixed | No | All | Yes | -| options.isEventEmitter | A flag indicating that the native module is expected to be an EventEmitter. Puts the EventEmitter instance on the emitter property of the resulting module. Defaults to false. | bool | No | All | Yes | - +请到三方库相应的 Releases 发布地址查看 Release 配套的版本信息:[@react-native-oh-tpl/react-native-safe-module Releases](https://github.com/react-native-oh-library/react-native-safe-module/releases) ## 遗留问题 @@ -132,5 +74,5 @@ SafeModule.create(options) | 创建Module | Function | Yes | Yes | ## 开源协议 -本项目基于 [MIT License](https://github.com/react-native-oh-library/react-native-safe-module/blob/master/LICENSE) ,请自由地享受和参与开源。 +本项目基于 [MIT License](https://github.com/lelandrichardson/react-native-safe-module/blob/master/LICENSE) ,请自由地享受和参与开源。 \ No newline at end of file -- Gitee