diff --git a/en/react-native-background-timer.md b/en/react-native-background-timer.md
index 357d4180a95a5bff817c770cb3ef8e78561c5c8a..f60b24955a0bb8ad41c56a0798315f2d346b160b 100644
--- a/en/react-native-background-timer.md
+++ b/en/react-native-background-timer.md
@@ -1,40 +1,34 @@
-> Template version: v0.2.2
+> Template version: v0.3.0
react-native-background-timer
-
-
-
-
-
-
-
-
-
-> [!TIP] [GitHub address](https://github.com/react-native-oh-library/react-native-background-timer)
+This project is based on [react-native-background-timer@2.4.1](https://github.com/ocetnik/react-native-background-timer)。
-## Installation and Usage
+This third-party library has been migrated to Gitee and is now available for direct download from npm, the new package name is: `@react-native-ohos/react-native-linear-gradient`, The version correspondence details are as follows:
-Find the matching version information in the release address of a third-party library: [@react-native-oh-tpl/react-native-background-timer Releases](https://github.com/react-native-oh-library/react-native-background-timer/releases).For older versions that are not published to npm, please refer to the [installation guide](/en/tgz-usage-en.md) to install the tgz package.
-
-Go to the project directory and execute the following instruction:
+| Version | Package Name | Repository | Release |
+| ------------------------- | ------------------------------------------------- | ------------------ | -------------------------- |
+| <= 2.4.1-0.0.2@deprecated | @react-native-oh-tpl/react-native-background-timer | [Github(deprecated)](https://github.com/react-native-oh-library/react-native-background-timer) | [Github Releases(deprecated)](https://github.com/react-native-oh-library/react-native-background-timer/releases) |
+| > 2.4.2 | @react-native-ohos/react-native-background-timer | [Gitee](https://gitee.com/openharmony-sig/rntpc_react-native-background-timer) | [Gitee Releases](https://gitee.com/openharmony-sig/rntpc_react-native-background-timer/releases) |
+## 1. Installation and Usage
+Go to the project directory and execute the following instruction:
#### **npm**
```bash
-npm install @react-native-oh-tpl/react-native-background-timer
+npm install @react-native-ohos/react-native-background-timer
```
#### **yarn**
```bash
-yarn add @react-native-oh-tpl/react-native-background-timer
+yarn add @react-native-ohos/react-native-background-timer
```
@@ -50,34 +44,37 @@ import BackgroundTimer from "react-native-background-timer";
export function BackgroundTimerExample() {
let [count, setCount] = useState(0);
let [text, setText] = useState("");
+ // BackgroundTimer延时
let [delay, setDelay] = useState("1000");
+ // setTimeout延时
let [timeoutDelay, setTimeoutDelay] = useState("1000");
+ // setInterval延时
let [intervalDelay, setIntervalDelay] = useState("1000");
let timeoutList:number[] = []
let [intervalList, setIntervalList] = useState([]);
-
+
// runBackgroundTimer
function onPressStart(){
- setText("Turn on the timer...")
+ setText("开启定时器...")
BackgroundTimer.runBackgroundTimer(()=>{
setCount(count+=1)
},parseInt(delay))
}
function onPressStop(){
- setText("Turn off the timer")
+ setText("结束定时器")
BackgroundTimer.stopBackgroundTimer()
}
// setTimeout
function setTimeoutStart(){
- setText("Turn on the timer...")
+ setText("开启定时器...")
let timeoutId = BackgroundTimer.setTimeout(()=>{
setCount(count+=1)
},parseInt(timeoutDelay))
timeoutList.push(timeoutId)
}
function setTimeoutStop(){
- setText("Turn off the timer")
+ setText("结束定时器")
if(timeoutList.length>0){
BackgroundTimer.clearTimeout(timeoutList[0])
timeoutList.shift()
@@ -86,14 +83,14 @@ export function BackgroundTimerExample() {
// setInterval
function setIntervalStart(){
- setText("Turn on the timer...")
+ setText("开启定时器...")
let intervalId = BackgroundTimer.setInterval(()=>{
setCount(count+=1)
},parseInt(intervalDelay))
setIntervalList([...intervalList,intervalId])
}
function setIntervalStop(){
- setText("Turn off the timer")
+ setText("结束定时器")
if(intervalList.length>0){
BackgroundTimer.clearInterval(intervalList[0])
intervalList.shift()
@@ -113,7 +110,7 @@ export function BackgroundTimerExample() {
/>
{setDelay(value)}}
value={delay}
/>
@@ -125,7 +122,7 @@ export function BackgroundTimerExample() {
/>
-
+
{setTimeoutDelay(value)}}
value={timeoutDelay}
/>
@@ -146,7 +143,7 @@ export function BackgroundTimerExample() {
/>
-
+
-
+
[!TIP] The HAR file is stored in the `harmony` directory in the installation path of the third-party library.
@@ -232,8 +237,7 @@ Open `entry/oh-package.json5` file and add the following dependencies:
```json
"dependencies": {
- "@rnoh/react-native-openharmony": "file:../react_native_openharmony",
- "@react-native-oh-tpl/react-native-background-timer": "file:../../node_modules/@react-native-oh-tpl/react-native-background-timer/harmony/background_timer.har"
+ "@react-native-ohos/react-native-background-timer": "file:../../node_modules/@react-native-ohos/react-native-background-timer/harmony/background_timer.har"
}
```
@@ -250,39 +254,57 @@ Method 2: Directly link to the source code.
> [!TIP] For details, see [Directly Linking Source Code](/en/link-source-code.md).
-Open `entry/oh-package.json5` file and add the following dependencies:
+### 2.3 Configuring CMakeLists and Introducing BackgroundTimerPackage
-```json
-"dependencies": {
- "@rnoh/react-native-openharmony": "file:../react_native_openharmony",
- "@react-native-oh-tpl/react-native-background-timer": "file:../../node_modules/@react-native-oh-tpl/react-native-background-timer/harmony/background_timer"
- }
+> [!TIP] Version v2.4.2 and above requires.
+
+Open `entry/src/main/cpp/CMakeLists.txt` and add the following code:
+
+```diff
++ set(OH_MODULES "${CMAKE_CURRENT_SOURCE_DIR}/../../../oh_modules")
+
+# RNOH_BEGIN: manual_package_linking_1
++ add_subdirectory("${OH_MODULES}/@react-native-ohos/react-native-background-timer/src/main/cpp" ./background_timer)
+# RNOH_END: manual_package_linking_1
+
+# RNOH_BEGIN: manual_package_linking_2
++ target_link_libraries(rnoh_app PUBLIC rnoh_background_timer)
+# RNOH_END: manual_package_linking_2
```
-Opening the terminal and executing:
+Open `entry/src/main/cpp/PackageProvider.cpp` and add the following code:
-```bash
-cd entry
-ohpm install --no-link
+```diff
+#include "RNOH/PackageProvider.h"
+#include "generated/RNOHGeneratedPackage.h"
++ #include "BackgroundTimerPackage.h"
+
+using namespace rnoh;
+
+std::vector> PackageProvider::getPackages(Package::Context ctx) {
+ return {
+ std::make_shared(ctx),
++ std::make_shared(ctx),
+ };
+}
```
-### 3. Introducing BackgroundTimerTurboModulePackage to ArkTS
+### 2.4. Introducing BackgroundTimerPackage to ArkTS
Open the `entry/src/main/ets/RNPackagesFactory.ts` file and add the following code:
```diff
...
-+ import { BackgroundTimerTurboModulePackage } from '@react-native-oh-tpl/react-native-background-timer/ts';
++ import { BackgroundTimerTurboModulePackage } from '@react-native-ohos/react-native-background-timer/ts';
export function createRNPackages(ctx: RNPackageContext): RNPackage[] {
return [
- new SamplePackage(ctx),
+ new BackgroundTimerTurboModulePackage(ctx)
- ];
+ ];
}
```
-### 4. Running
+### 2.5 Running
Click the `sync` button in the upper right corner.
@@ -295,19 +317,19 @@ ohpm install
Then build and run the code.
-## Constraints
+## 3. Constraints
-### Compatibility
+### 3.1 Compatibility
To use this repository, you need to use the correct React-Native and RNOH versions. In addition, you need to use DevEco Studio and the ROM on your phone.
-Check the release version information in the release address of the third-party library: [@react-native-oh-tpl/react-native-background-timer Releases](https://github.com/react-native-oh-library/react-native-background-timer/releases)
+Check the release version information in the release address of the third-party library: [@react-native-ohos/react-native-background-timer Releases](https://gitee.com/openharmony-sig/rntpc_react-native-background-timer/releases)
This document is verified based on the following versions:
-RNOH: 0.72.20; SDK: HarmonyOS NEXT Developer Beta1 B.0.18; IDE: DevEco Studio 5.0.3.200; ROM: 3.0.0.19;
+RNOH: 0.72.38; SDK: HarmonyOS-5.0.0(API12); ROM: 5.0.0.107;
-## API
+## 4. APIs
> [!TIP] The **Platform** column indicates the platform where the properties are supported in the original third-party library.
@@ -324,12 +346,14 @@ RNOH: 0.72.20; SDK: HarmonyOS NEXT Developer Beta1 B.0.18; IDE: DevEco Studio 5.
| setInterval | 开启定时器,以固定的时间间隔重复执行指定代码 | no | Android | yes |
| clearInterval | 结束 setInterval 开启的定时器 | no | Android | yes |
-## Known Issues
+## 5. Known Issues
+
+- [ ] 使用 worker 开的新线程中不支持 RNOHContext 序列化传参,底层 OS 暂不支持,导致无法在新线程中发送事件,需要底层 OS 框架实现相关业务功能。不开线程的情况下,因 setTimeout 属于异步方法,定时器效果不受影响。[worker 线程 Known Issues:start 和 stop 接口, HarmonyOS RN 框架暂不支持](https://gitee.com/openharmony-sig/rntpc_react-native-background-timer/issues/IB8QGJ)
+
+## 6. Others
-- [ ] 使用 worker 开的新线程中不支持 RNOHContext 序列化传参,底层 OS 暂不支持,导致无法在新线程中发送事件,需要底层 OS 框架实现相关业务功能。不开线程的情况下,因 setTimeout 属于异步方法,定时器效果不受影响。[worker 线程 Known Issues:start 和 stop 接口, HarmonyOS RN 框架暂不支持](https://github.com/react-native-oh-library/react-native-background-timer/issues/3)
-## Others
+## 7. License
-## License
+This project is licensed under (https://gitee.com/openharmony-sig/rntpc_react-native-background-timer/blob/master/LICENSE).
-This project is licensed under [The MIT License (MIT)](https://github.com/ocetnik/react-native-background-timer/blob/master/LICENSE).
diff --git a/zh-cn/react-native-background-timer.md b/zh-cn/react-native-background-timer.md
index eb3321fc3c93227145bb4a509037f7aa50b45ac0..54c4423d06161a86c1ebab07b3e76b4c9d489cca 100644
--- a/zh-cn/react-native-background-timer.md
+++ b/zh-cn/react-native-background-timer.md
@@ -1,24 +1,19 @@
-> 模板版本:v0.2.1
+> 模板版本:v0.3.0
react-native-background-timer
-
-
-
-
-
-
-
-
-
-> [!TIP] [Github 地址](https://github.com/react-native-oh-library/react-native-background-timer)
+本项目基于 [react-native-background-timer@2.4.1](https://github.com/ocetnik/react-native-background-timer) 开发。
+该第三方库的仓库已迁移至 Gitee,且支持直接从 npm 下载,新的包名为:`@react-native-ohos/react-native-background-timer`,具体版本所属关系如下:
-## 安装与使用
+| Version | Package Name | Repository | Release |
+| ------------------------- | ------------------------------------------------- | ------------------ | -------------------------- |
+| <= 2.4.1-0.0.2@deprecated | @react-native-oh-tpl/react-native-background-timer | [Github(deprecated)](https://github.com/react-native-oh-library/react-native-background-timer) | [Github Releases(deprecated)](https://github.com/react-native-oh-library/react-native-background-timer/releases) |
+| > 2.4.2 | @react-native-ohos/react-native-background-timer | [Gitee](https://gitee.com/openharmony-sig/rntpc_react-native-background-timer) | [Gitee Releases](https://gitee.com/openharmony-sig/rntpc_react-native-background-timer/releases) |
-请到三方库的 Releases 发布地址查看配套的版本信息:[@react-native-oh-tpl/react-native-background-timer Releases](https://github.com/react-native-oh-library/react-native-background-timer/releases) 。对于未发布到npm的旧版本,请参考[安装指南](/zh-cn/tgz-usage.md)安装tgz包。
+## 1. 安装与使用
进入到工程目录并输入以下命令:
@@ -27,13 +22,13 @@
#### **npm**
```bash
-npm install @react-native-oh-tpl/react-native-background-timer
+npm install @react-native-ohos/react-native-background-timer
```
#### **yarn**
```bash
-yarn add @react-native-oh-tpl/react-native-background-timer
+yarn add @react-native-ohos/react-native-background-timer
```
@@ -205,29 +200,34 @@ const styles = StyleSheet.create({
```
-## Link
+## 2. Manual Link
+
+此步骤为手动配置原生依赖项的指导。
-目前 HarmonyOS 暂不支持 AutoLink,所以 Link 步骤需要手动配置。
+首先需要使用 DevEco Studio 打开项目里的 HarmonyOS 工程 `harmony`。
-首先需要使用 DevEco Studio 打开项目里的 HarmonyOS 工程 `harmony`
+### 2.1 Overrides RN SDK
-### 1.在工程根目录的 `oh-package.json5` 添加 overrides字段
+为了让工程依赖同一个版本的 RN SDK,需要在工程根目录的 `oh-package.json5` 添加 overrides 字段,指向工程需要使用的 RN SDK 版本。替换的版本既可以是一个具体的版本号,也可以是一个模糊版本,还可以是本地存在的 HAR 包或源码目录。
+
+关于该字段的作用请阅读[官方说明](https://developer.huawei.com/consumer/cn/doc/harmonyos-guides-V5/ide-oh-package-json5-V5#zh-cn_topic_0000001792256137_overrides)
```json
{
- ...
"overrides": {
- "@rnoh/react-native-openharmony" : "./react_native_openharmony"
+ "@rnoh/react-native-openharmony": "^0.72.38" // ohpm 在线版本
+ // "@rnoh/react-native-openharmony" : "./react_native_openharmony.har" // 指向本地 har 包的路径
+ // "@rnoh/react-native-openharmony" : "./react_native_openharmony" // 指向源码路径
}
}
```
-### 2.引入原生端代码
+### 2.2 引入原生端代码
目前有两种方法:
-1. 通过 har 包引入(在 IDE 完善相关功能后该方法会被遗弃,目前首选此方法);
-2. 直接链接源码。
+- 通过 har 包引入;
+- 直接链接源码。
方法一:通过 har 包引入(推荐)
@@ -237,14 +237,13 @@ const styles = StyleSheet.create({
```json
"dependencies": {
- "@rnoh/react-native-openharmony": "file:../react_native_openharmony",
- "@react-native-oh-tpl/react-native-background-timer": "file:../../node_modules/@react-native-oh-tpl/react-native-background-timer/harmony/background_timer.har"
+ "@react-native-ohos/react-native-background-timer": "file:../../node_modules/@react-native-ohos/react-native-background-timer/harmony/background_timer.har"
}
```
点击右上角的 `sync` 按钮
-或者在终端执行:
+或者在命令行终端执行:
```bash
cd entry
@@ -253,45 +252,63 @@ ohpm install
方法二:直接链接源码
-> [!TIP] 源码位于三方库安装路径的 `harmony` 文件夹下。
+> [!TIP] 如需使用直接链接源码,请参考[直接链接源码说明](/zh-cn/link-source-code.md)
-打开 `entry/oh-package.json5`,添加以下依赖
+### 2.3 配置 CMakeLists 和引入 BackgroundTimerPackage
-```json
-"dependencies": {
- "@rnoh/react-native-openharmony": "file:../react_native_openharmony",
- "@react-native-oh-tpl/react-native-background-timer": "file:../../node_modules/@react-native-oh-tpl/react-native-background-timer/harmony/background_timer"
- }
+> [!TIP] 版本 v2.4.2 及以上需要.
+
+打开 `entry/src/main/cpp/CMakeLists.txt`,添加:
+
+```diff
++ set(OH_MODULES "${CMAKE_CURRENT_SOURCE_DIR}/../../../oh_modules")
+
+# RNOH_BEGIN: manual_package_linking_1
++ add_subdirectory("${OH_MODULES}/@react-native-ohos/react-native-background-timer/src/main/cpp" ./background_timer)
+# RNOH_END: manual_package_linking_1
+
+# RNOH_BEGIN: manual_package_linking_2
++ target_link_libraries(rnoh_app PUBLIC rnoh_background_timer)
+# RNOH_END: manual_package_linking_2
```
-打开终端,执行:
+打开 `entry/src/main/cpp/PackageProvider.cpp`,添加:
-```bash
-cd entry
-ohpm install --no-link
+```diff
+#include "RNOH/PackageProvider.h"
+#include "generated/RNOHGeneratedPackage.h"
++ #include "BackgroundTimerPackage.h"
+
+using namespace rnoh;
+
+std::vector> PackageProvider::getPackages(Package::Context ctx) {
+ return {
+ std::make_shared(ctx),
++ std::make_shared(ctx),
+ };
+}
```
-### 3.在 ArkTs 侧引入 BackgroundTimerTurboModulePackage
+### 2.4 在 ArkTs 侧引入 BackgroundTimerPackage
打开 `entry/src/main/ets/RNPackagesFactory.ts`,添加:
```diff
...
-+ import { BackgroundTimerTurboModulePackage } from '@react-native-oh-tpl/react-native-background-timer/ts';
++ import { BackgroundTimerTurboModulePackage } from '@react-native-ohos/react-native-background-timer/ts';
export function createRNPackages(ctx: RNPackageContext): RNPackage[] {
return [
- new SamplePackage(ctx),
+ new BackgroundTimerTurboModulePackage(ctx)
- ];
+ ];
}
```
-### 4.运行
+### 2.5 运行
点击右上角的 `sync` 按钮
-或者在终端执行:
+或者在命令行终端执行:
```bash
cd entry
@@ -300,23 +317,23 @@ ohpm install
然后编译、运行即可。
-## 约束与限制
+## 3. 约束与限制
-### 兼容性
+### 3.1 兼容性
要使用此库,需要使用正确的 React-Native 和 RNOH 版本。另外,还需要使用配套的 DevEco Studio 和 手机 ROM。
-请到三方库相应的 Releases 发布地址查看 Release 配套的版本信息:[@react-native-oh-tpl/react-native-background-timer Releases](https://github.com/react-native-oh-library/react-native-background-timer/releases)
+请到三方库相应的 Releases 发布地址查看 Release 配套的版本信息:[@react-native-ohos/react-native-background-timer Releases](https://gitee.com/openharmony-sig/rntpc_react-native-background-timer/releases)
本文档内容基于以下版本验证通过:
-RNOH: 0.72.20; SDK: HarmonyOS NEXT Developer Beta1 B.0.18; IDE: DevEco Studio 5.0.3.200; ROM: 3.0.0.19;
+RNOH: 0.72.38; SDK: HarmonyOS-5.0.0(API12); ROM: 5.0.0.107;
-## API
+## 4. API
> [!TIP] "Platform"列表示该属性在原三方库上支持的平台。
@@ -333,12 +350,14 @@ RNOH: 0.72.20; SDK: HarmonyOS NEXT Developer Beta1 B.0.18; IDE: DevEco Studio 5.
| setInterval | 开启定时器,以固定的时间间隔重复执行指定代码 | no | Android | yes |
| clearInterval | 结束setInterval开启的定时器 | no | Android | yes |
-## 遗留问题
+## 5. 遗留问题
+
+- [ ] 使用worker开的新线程中不支持RNOHContext序列化传参,底层OS暂不支持,导致无法在新线程中发送事件,需要底层OS框架实现相关业务功能。不开线程的情况下,因setTimeout属于异步方法,定时器效果不受影响。[worker线程遗留问题:start和stop接口, HarmonyOS RN框架暂不支持](https://gitee.com/openharmony-sig/rntpc_react-native-background-timer/issues/IB8QGJ)
+
+## 6. 其他
-- [ ] 使用worker开的新线程中不支持RNOHContext序列化传参,底层OS暂不支持,导致无法在新线程中发送事件,需要底层OS框架实现相关业务功能。不开线程的情况下,因setTimeout属于异步方法,定时器效果不受影响。[worker线程遗留问题:start和stop接口, HarmonyOS RN框架暂不支持](https://github.com/react-native-oh-library/react-native-background-timer/issues/3)
-## 其他
+## 7. 开源协议
-## 开源协议
+本项目基于 [The MIT License (MIT)](https://gitee.com/openharmony-sig/rntpc_react-native-background-timer/blob/master/LICENSE) ,请自由地享受和参与开源。
-本项目基于 [The MIT License (MIT)](https://github.com/ocetnik/react-native-background-timer/blob/master/LICENSE) ,请自由地享受和参与开源。