已合并
docs: update README document for 0.72 branch of react-native-restart library #27
docs: update README document for 0.72 branch of react-native-restart library #27
已合并
fanwangah创建于 8月4日
2 个文件变更+136-54
MREADME.md+67-26
@@ -1,14 +1,17 @@
1-> 文档模板:v0.4.11+> 文档模板:v0.4.2
2 2 
3-# <center>react-native-restart</center>3+<p align="center">
4+ <h1 align="center"> <code>react-native-restart</code> </h1>
5+</p>
4 6 
5本项目基于 [react-native-restart](https://github.com/avishayil/react-native-restart) 开发。7本项目基于 [react-native-restart](https://github.com/avishayil/react-native-restart) 开发。
6 8 
7该第三方库的仓库已迁移至 Gitcode,且支持直接从 npm 下载,新的包名为:`@react-native-ohos/react-native-restart` 版本所属关系如下:9该第三方库的仓库已迁移至 Gitcode,且支持直接从 npm 下载,新的包名为:`@react-native-ohos/react-native-restart` 版本所属关系如下:
8 10 
9-| 三方库名称 | 三方库版本 | 发布信息 | 支持RN版本 | Autolink | 编译API版本 | 社区基线版本 | npm地址 |11+| 三方库名称 | 三方库版本(npm地址) | 发布信息 | 支持RN版本 | AutoLink | 编译API版本 | 社区基线版本 | 源码地址 |
10-| ------------ | ------------ | ------------------------------ | ------------- | ------------- |------------------------ | ------------- | ------------- |12+| - | - | - | - | - | - | - | - |
11-| @react-native-ohos/react-native-restart | ~0.0.28 | [Gitcode Releases](https://gitcode.com/CPF-RN/rntpc_react-native-restart/releases) | 0.72.* | 是 | API12+ | 0.0.27 | [Npm Address](https://www.npmjs.com/package/@react-native-ohos/react-native-restart) | 13+| @react-native-ohos/react-native-restart | [~ 0.0.28](https://www.npmjs.com/package/@react-native-ohos/react-native-restart) | [Gitcode Releases](https://gitcode.com/CPF-RN/rntpc_react-native-restart/releases) | 0.72.* | 是 | API12+ | 0.0.27 | [br_rnoh0.72](https://gitcode.com/CPF-RN/rntpc_react-native-restart/tree/br_rnoh0.72) |
14+| @react-native-oh-tpl/react-native-restart | [<=0.0.27-0.0.3@deprecated](https://www.npmjs.com/package/@react-native-oh-tpl/react-native-restart) | [Github Releases(deprecated)](https://github.com/react-native-oh-library/react-native-restart/releases) | 0.72.* | 否 | API12+ | 0.0.27 | [sig](https://github.com/react-native-oh-library/react-native-restart/tree/sig) |
12 15 
13## 简介16## 简介
14 17 
@@ -35,6 +38,7 @@ yarn add @react-native-ohos/react-native-restart
35| | 是否支持autolink | RN框架版本 |38| | 是否支持autolink | RN框架版本 |
36|--------------------------------|-----------------|------------|39|--------------------------------|-----------------|------------|
37| ~0.0.28 | Yes | 0.72 |40| ~0.0.28 | Yes | 0.72 |
41+| <=0.0.27-0.0.3@deprecated | No | 0.72 |
38 42 
39使用AutoLink的工程需要根据该文档配置,Autolink框架指导文档:https://gitcode.com/CPF-RN/ohos_react_native/blob/master/docs/zh-cn/Autolinking.md43使用AutoLink的工程需要根据该文档配置,Autolink框架指导文档:https://gitcode.com/CPF-RN/ohos_react_native/blob/master/docs/zh-cn/Autolinking.md
40 44 
@@ -188,6 +192,7 @@ ohpm install
188本文档内容基于以下环境验证通过:192本文档内容基于以下环境验证通过:
189 193 
1901. RNOH: 0.72.96; SDK: HarmonyOS 6.0.0 Release SDK; IDE: DevEco Studio 6.0.0.858; ROM: 6.0.0.112;1941. RNOH: 0.72.96; SDK: HarmonyOS 6.0.0 Release SDK; IDE: DevEco Studio 6.0.0.858; ROM: 6.0.0.112;
195+2. RNOH: 0.72.33; SDK: HarmonyOS NEXT B1; IDE: DevEco Studio 5.0.3.900; ROM: Next.0.0.71;
191 196 
192## 使用示例197## 使用示例
193 198 
@@ -195,27 +200,63 @@ ohpm install
195 200 
196> [!WARNING] 使用时 import 的库名不变。201> [!WARNING] 使用时 import 的库名不变。
197 202 
198-```js203+```tsx
199-import React from 'react';204+import { useState } from "react";
200-import {Text, View, StyleSheet} from 'react-native';205+import { StyleSheet, Text } from "react-native";
201-import RNRestart from 'react-native-restart';206+import RNRestart from "react-native-restart";
207+import { Tester, TestSuite, TestCase } from "@rnoh/testerino";
202 208 
203export default function RestartDemo() {209export default function RestartDemo() {
210+ const [restartReason, setRestartReason] = useState("");
211+ 
204 return (212 return (
205- <View>213+ <Tester>
206- <Text>重启restart</Text>214+ <TestSuite name="restart">
207- <Text style={styles.button} onPress={() => RNRestart.restart()}>215+ <TestCase tags={["C_API"]} itShould="restart">
208- 重启(restart)216+ <Text
209- </Text>217+ style={styles.button}
210- <Text>重启Restart</Text>218+ onPress={() => RNRestart.restart("restart_a")}
211- <Text style={styles.button} onPress={() => RNRestart.Restart()}>219+ >
212- 重启(Restart)220+ restart
213- </Text>221+ </Text>
214- <Text>上次restart的原因(getReason)</Text>222+ </TestCase>
215- <Text style={styles.button} onPress={() => RNRestart.getReason()}>223+ <TestCase tags={["C_API"]} itShould="Restart">
216- getReason224+ <Text
217- </Text>225+ style={styles.button}
218- </View>226+ onPress={() => RNRestart.Restart("restart_b")}
227+ >
228+ Restart
229+ </Text>
230+ </TestCase>
231+ <TestCase
232+ tags={["C_API"]}
233+ itShould="getReason"
234+ initialState={"reason"}
235+ arrange={({ setState }) => {
236+ return (
237+ <Text
238+ style={styles.button}
239+ onPress={async () => {
240+ try {
241+ const reason = await RNRestart.getReason();
242+ setRestartReason(reason);
243+ setState(reason);
244+ } catch (e) {
245+ setRestartReason("");
246+ setState("");
247+ }
248+ }}
249+ >
250+ getReason{restartReason ? `(原因:${restartReason})` : ""}
251+ </Text>
252+ );
253+ }}
254+ assert={async ({ expect, state }) => {
255+ expect(state).include("restart_");
256+ }}
257+ />
258+ </TestSuite>
259+ </Tester>
219 );260 );
220}261}
221 262 
@@ -223,9 +264,9 @@ const styles = StyleSheet.create({
223 button: {264 button: {
224 paddingVertical: 6,265 paddingVertical: 6,
225 paddingHorizontal: 12,266 paddingHorizontal: 12,
226- backgroundColor: 'hsl(193, 95%, 68%)',267+ backgroundColor: "hsl(193, 95%, 68%)",
227 borderWidth: 2,268 borderWidth: 2,
228- borderColor: 'hsl(193, 95%, 30%)',269+ borderColor: "hsl(193, 95%, 30%)",
229 },270 },
230});271});
231 272 
@@ -256,7 +297,7 @@ const styles = StyleSheet.create({
256├── harmony # 鸿蒙适配代码297├── harmony # 鸿蒙适配代码
257│ └─ rn_restart.har # har包298│ └─ rn_restart.har # har包
258│ └─ restart # 鸿蒙适配核心代码299│ └─ restart # 鸿蒙适配核心代码
259-│ └─ index.ets # 鸿蒙适配代码入口 300+│ └─ Index.ets # 鸿蒙适配代码入口
260│ └─ src/main/ets 301│ └─ src/main/ets
261│ └─ RNRestartTurboModule.ts # Restart核心实现 302│ └─ RNRestartTurboModule.ts # Restart核心实现
262├── src # RN代码303├── src # RN代码
@@ -1,14 +1,17 @@
1-> Document Template:v0.4.11+> Document Template:v0.4.2
2 2 
3-# <center>react-native-restart</center>3+<p align="center">
4+ <h1 align="center"> <code>react-native-restart</code> </h1>
5+</p>
4 6 
5This project is based on [react-native-restart](https://github.com/avishayil/react-native-restart).7This project is based on [react-native-restart](https://github.com/avishayil/react-native-restart).
6 8 
7-This third-party library supports direct installation from npm, the new package name is: `@react-native-ohos/react-native-restart`, The version correspondence details are as follows:9+The repository of this third-party library has been migrated to Gitcode, and it supports direct installation from npm. The new package name is: `@react-native-ohos/react-native-restart`. The version correspondence details are as follows:
8 10 
9-| Name | Version | Release Information | Supported RN Version | Supported Autolink | Compile API Version | Community Baseline Version | npm Address |11+| Name | Version(Npm Address) | Release Information | Supported RN Version | Supported Autolink | Compile API Version | Community Baseline Version | Source code address |
10-| - | - | - | - | - | - | - | - |12+| --------------| -------------- | ------------------------------ | ------------- | ------------- |------------------------ | ------------ | ------------- |
11-| @react-native-ohos/react-native-restart | ~0.0.28 | [Gitcode Releases](https://gitcode.com/CPF-RN/rntpc_react-native-restart/releases) | 0.72.* | Yes | API12+ | 0.0.27 | [Npm Address](https://www.npmjs.com/package/@react-native-ohos/react-native-restart) | 13+| @react-native-ohos/react-native-restart | [~ 0.0.28](https://www.npmjs.com/package/@react-native-ohos/react-native-restart) | [Gitcode Releases](https://gitcode.com/CPF-RN/rntpc_react-native-restart/releases) | 0.72.* | Yes | API12+ | 0.0.27 | [br_rnoh0.72](https://gitcode.com/CPF-RN/rntpc_react-native-restart/tree/br_rnoh0.72) |
14+| @react-native-oh-tpl/react-native-restart | [<=0.0.27-0.0.3@deprecated](https://www.npmjs.com/package/@react-native-oh-tpl/react-native-restart) | [Github Releases(deprecated)](https://github.com/react-native-oh-library/react-native-restart/releases) | 0.72.* | No | API12+ | 0.0.27 | [sig](https://github.com/react-native-oh-library/react-native-restart/tree/sig) |
12 15 
13## Introduction16## Introduction
14 17 
@@ -35,6 +38,7 @@ yarn add @react-native-ohos/react-native-restart
35| | Is supported autolink | Supported RN Version |38| | Is supported autolink | Supported RN Version |
36|--------------------------------------|-----------------------|----------------------|39|--------------------------------------|-----------------------|----------------------|
37| ~0.0.28 | Yes | 0.72 |40| ~0.0.28 | Yes | 0.72 |
41+| <=0.0.27-0.0.3@deprecated | No | 0.72 |
38 42 
39Projects using AutoLink need to be configured according to this document, AutoLink framework guide: https://gitcode.com/CPF-RN/ohos_react_native/blob/master/docs/en/Autolinking.md43Projects using AutoLink need to be configured according to this document, AutoLink framework guide: https://gitcode.com/CPF-RN/ohos_react_native/blob/master/docs/en/Autolinking.md
40 44 
@@ -189,6 +193,7 @@ Then build and run the code.
189This document is verified based on the following versions:193This document is verified based on the following versions:
190 194 
1911. RNOH: 0.72.96; SDK: HarmonyOS 6.0.0 Release SDK; IDE: DevEco Studio 6.0.0.858; ROM: 6.0.0.112;1951. RNOH: 0.72.96; SDK: HarmonyOS 6.0.0 Release SDK; IDE: DevEco Studio 6.0.0.858; ROM: 6.0.0.112;
196+2. RNOH: 0.72.33; SDK: HarmonyOS NEXT B1; IDE: DevEco Studio 5.0.3.900; ROM: Next.0.0.71;
192 197 
193## Example198## Example
194 199 
@@ -196,27 +201,63 @@ The following code shows the basic use scenario of the repository:
196 201 
197> [!WARNING] The name of the imported repository remains unchanged.202> [!WARNING] The name of the imported repository remains unchanged.
198 203 
199-```js204+```tsx
200-import React from 'react';205+import { useState } from "react";
201-import {Text, View, StyleSheet} from 'react-native';206+import { StyleSheet, Text } from "react-native";
202-import RNRestart from 'react-native-restart';207+import RNRestart from "react-native-restart";
208+import { Tester, TestSuite, TestCase } from "@rnoh/testerino";
203 209 
204export default function RestartDemo() {210export default function RestartDemo() {
211+ const [restartReason, setRestartReason] = useState("");
212+ 
205 return (213 return (
206- <View>214+ <Tester>
207- <Text>restart</Text>215+ <TestSuite name="restart">
208- <Text style={styles.button} onPress={() => RNRestart.restart()}>216+ <TestCase tags={["C_API"]} itShould="restart">
209- restart217+ <Text
210- </Text>218+ style={styles.button}
211- <Text>Restart</Text>219+ onPress={() => RNRestart.restart("restart_a")}
212- <Text style={styles.button} onPress={() => RNRestart.Restart()}>220+ >
213- Restart221+ restart
214- </Text>222+ </Text>
215- <Text>The reason for the last restart(getReason)</Text>223+ </TestCase>
216- <Text style={styles.button} onPress={() => RNRestart.getReason()}>224+ <TestCase tags={["C_API"]} itShould="Restart">
217- getReason225+ <Text
218- </Text>226+ style={styles.button}
219- </View>227+ onPress={() => RNRestart.Restart("restart_b")}
228+ >
229+ Restart
230+ </Text>
231+ </TestCase>
232+ <TestCase
233+ tags={["C_API"]}
234+ itShould="getReason"
235+ initialState={"reason"}
236+ arrange={({ setState }) => {
237+ return (
238+ <Text
239+ style={styles.button}
240+ onPress={async () => {
cpf-manager
cpf-managercpf-manager8月4日

【AI-Review】【一般】【基础代码问题】【异常处理】getReason 示例未处理 Promise 拒绝场景

● 问题: 示例代码 const reason = await RNRestart.getReason(); 未使用 try-catch 包裹。根据 harmony/restart/src/main/ets/RNRestartTurboModule.ts 第 79-88 行的实现,getReason()restartReason 为空字符串时(即未执行过 restart/Restart)会执行 reject('reason is empty');而 restartReason 静态字段初始值为 ''(第 37 行)。当用户在未先点击 restart 或 Restart 的情况下直接点击 getReason 按钮时,await 将抛出异常,由于 onPress 是 async 回调且无 try-catch,会产生 unhandled promise rejection。

● 影响: 一般。用户按示例代码使用时,若在未执行 restart 的情况下点击 getReason,会触发未捕获的 Promise 拒绝,导致测试框架报告异常或控制台告警,影响示例可用性。

● 建议: 使用 try-catch 包裹 await 调用,处理拒绝场景:

onPress={async () => {
  try {
    const reason = await RNRestart.getReason();
    setRestartReason(reason);
    setState(reason);
  } catch (e) {
    setRestartReason("");
    setState("");
  }
}}
likedislike
fanwangah
8月4日 评论:
241+ try {
242+ const reason = await RNRestart.getReason();
243+ setRestartReason(reason);
244+ setState(reason);
245+ } catch (e) {
246+ setRestartReason("");
247+ setState("");
248+ }
249+ }}
250+ >
cpf-manager
cpf-managercpf-manager8月4日

【AI-Review】【一般】【基础代码问题】【代码逻辑错误】英文 README 示例代码中包含中文文本

● 问题: README_en.md 第 243 行示例代码 getReason{restartReason ? (原因:${restartReason}) : ""} 使用了中文全角括号 和中文文本 原因:。该文件为英文文档(README_en.md),同一段代码在中文 README.md 中使用中文文本是正确的,但在英文文档中应使用英文文本以保持本地化一致性。

● 影响: 一般。英文文档的使用者在代码示例中看到中文文本,影响文档的本地化一致性和可读性,且复制后会在英文环境的应用界面中显示中文。

● 建议: 将中文文本改为英文:

getReason{restartReason ? ` (reason: ${restartReason})` : ""}
likedislike
fanwangah
8月4日 评论:
251+ getReason{restartReason ? ` (reason: ${restartReason})` : ""}
252+ </Text>
253+ );
254+ }}
255+ assert={async ({ expect, state }) => {
256+ expect(state).include("restart_");
257+ }}
258+ />
259+ </TestSuite>
260+ </Tester>
220 );261 );
221}262}
222 263 
@@ -224,9 +265,9 @@ const styles = StyleSheet.create({
224 button: {265 button: {
225 paddingVertical: 6,266 paddingVertical: 6,
226 paddingHorizontal: 12,267 paddingHorizontal: 12,
227- backgroundColor: 'hsl(193, 95%, 68%)',268+ backgroundColor: "hsl(193, 95%, 68%)",
228 borderWidth: 2,269 borderWidth: 2,
229- borderColor: 'hsl(193, 95%, 30%)',270+ borderColor: "hsl(193, 95%, 30%)",
230 },271 },
231});272});
232 273 
@@ -256,9 +297,9 @@ const styles = StyleSheet.create({
256├── harmony # HarmonyOS adaptation code297├── harmony # HarmonyOS adaptation code
257│ └─ rn_restart.har # har package298│ └─ rn_restart.har # har package
258│ └─ restart # HarmonyOS adaptation core code299│ └─ restart # HarmonyOS adaptation core code
259-│ └─ index.ets # HarmonyOS adaptation code entry point 300+│ └─ Index.ets # HarmonyOS adaptation code entry point
260│ └─ src/main/ets 301│ └─ src/main/ets
261-│ └─ RNRestartTurboModule.ts # Restart component implementation 302+│ └─ RNRestartTurboModule.ts # Restart core implementation
262├── src # React Native code303├── src # React Native code
263│ └─ index.tsx # Entry file 304│ └─ index.tsx # Entry file
264│ └─ NativeRestart.ts # Type file 305│ └─ NativeRestart.ts # Type file