Skip to content

Commit 2e2f64d

Browse files
authored
docs(cndocs): 同步翻译更新(高质量) (#1001)
1 parent b09e6d7 commit 2e2f64d

10 files changed

+1945
-554
lines changed

cndocs/debugging-native-code.md

Lines changed: 50 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,29 +10,70 @@ import Tabs from '@theme/Tabs'; import TabItem from '@theme/TabItem'; import con
1010
<p>以下部分仅适用于包含原生代码的项目。如果你使用的是托管型 Expo 工作流,请参阅 <a href="https://docs.expo.dev/workflow/prebuild/" target="_blank">prebuild</a> 指南以使用此 API。</p>
1111
</div>
1212

13-
## 打印日志
13+
## 查看日志
1414

15-
当应用正在运行时,你可以在终端中使用以下命令打印 iOS 或 Android 应用的日志
15+
当应用正在运行时,你可以在终端中使用以下命令查看 iOS 或 Android 应用的原生日志
1616

1717
```shell
18-
# For Android:
18+
# Android
1919
npx react-native log-android
20-
# Or, for iOS:
20+
# iOS
2121
npx react-native log-ios
2222
```
2323

24-
你也可以通过 iOS 模拟器中的 "Debug > Open System Log..." 菜单,或者在运行 Android 应用的设备或模拟器中运行 `adb logcat "*:S" ReactNative:V ReactNativeJS:V` 来访问这些日志。
24+
你也可以通过 iOS 模拟器中的 Debug > Open System Log… 菜单,或者在运行 Android 应用的设备或模拟器中执行 `adb logcat "*:S" ReactNative:V ReactNativeJS:V` 来查看这些日志。
25+
26+
<details>
27+
<summary>**💡 自定义原生日志**</summary>
28+
29+
如果你正在编写原生模块,并且想为你的模块添加自定义日志用于调试,可以使用以下方法:
30+
31+
#### Android(Java/Kotlin)
32+
33+
在原生模块中,使用 `Log` 类添加可在 Logcat 中查看的日志:
34+
35+
```java
36+
import android.util.Log;
37+
38+
private void log(String message) {
39+
Log.d("YourModuleName", message);
40+
}
41+
```
42+
43+
要在 Logcat 中查看这些日志,请使用以下命令,将 `YourModuleName` 替换为你的自定义标签:
44+
45+
```shell
46+
adb logcat "*:S" ReactNative:V ReactNativeJS:V YourModuleName:D
47+
```
48+
49+
#### iOS(Objective-C/Swift)
50+
51+
在原生模块中,使用 `NSLog` 添加自定义日志:
52+
53+
```objective-c
54+
NSLog(@"YourModuleName: %@", message);
55+
```
56+
57+
或者在 Swift 中:
58+
59+
```swift
60+
print("YourModuleName: \(message)")
61+
```
62+
63+
运行应用时,这些日志将出现在 Xcode 控制台中。
64+
65+
</details>
2566

2667
## 在原生 IDE 中调试
2768

28-
当你编写原生模块时,你可以使用 Android Studio 或 Xcode 来启动应用,并使用其原生调试功能(设置断点等),就像在构建标准原生应用时一样
69+
当你编写原生代码(如原生模块)时,可以从 Android Studio 或 Xcode 启动应用,并利用其原生调试功能(设置断点等),就像构建标准原生应用一样
2970

30-
另一种选择是使用 React Native CLI 运行应用,并从原生 IDE(Android Studio 或 Xcode)中附加到进程
71+
另一种选择是使用 React Native CLI 运行应用,然后将原生 IDE(Android Studio 或 Xcode)的原生调试器附加到进程上
3172

3273
### Android Studio
3374

34-
在 Android Studio 中,你可以通过点击菜单栏中的 "Run" 选项,然后选择 "Attach to Process...",并选择正在运行的 React Native 应用。
75+
在 Android Studio 中,点击菜单栏上的"Run"选项,选择"Attach to Process...",然后选择正在运行的 React Native 应用。
3576

3677
### Xcode
3778

38-
在 Xcode 中,点击菜单栏中的 "Debug",选择 "Attach to Process...",然后从 "Likely Targets" 列表中选择正在运行的应用
79+
在 Xcode 中,点击顶部菜单栏的"Debug",选择"Attach to process"选项,然后从"Likely Targets"列表中选择你的应用

cndocs/global-PerformanceObserver.md

Lines changed: 52 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,56 @@ id: global-PerformanceObserver
33
title: PerformanceObserver
44
---
55

6-
:::warning
7-
🚧 本页面仍在完善中,请参考 [MDN 文档](https://developer.mozilla.org/zh-CN/docs/Web/API/PerformanceObserver) 获取更多信息。
8-
:::
6+
全局 [`PerformanceObserver`](https://developer.mozilla.org/zh-CN/docs/Web/API/PerformanceObserver) 类,按照 Web 规范定义。
97

10-
全局 `PerformanceObserver` 类,按照 Web 规范定义。
8+
## 示例
9+
10+
```ts
11+
const observer = new PerformanceObserver(
12+
(list, observer, options) => {
13+
for (const entry of list.getEntries()) {
14+
console.log(
15+
'Received entry with type',
16+
entry.entryType,
17+
'and name',
18+
entry.name,
19+
'that started at',
20+
entry.startTime,
21+
'and took',
22+
entry.duration,
23+
'ms',
24+
);
25+
}
26+
},
27+
);
28+
29+
observer.observe({entryTypes: ['mark', 'measure']});
30+
```
31+
32+
---
33+
34+
# 参考
35+
36+
## 构造函数
37+
38+
### `PerformanceObserver()`
39+
40+
参见 [MDN 文档](https://developer.mozilla.org/zh-CN/docs/Web/API/PerformanceObserver/PerformanceObserver)
41+
42+
## 静态属性
43+
44+
### `supportedEntryTypes`
45+
46+
参见 [MDN 文档](https://developer.mozilla.org/zh-CN/docs/Web/API/PerformanceObserver/supportedEntryTypes)
47+
48+
返回 `['mark', 'measure', 'event', 'longtask', 'resource']`
49+
50+
## 实例方法
51+
52+
### `observe()`
53+
54+
参见 [MDN 文档](https://developer.mozilla.org/zh-CN/docs/Web/API/PerformanceObserver/observe)
55+
56+
### `disconnect()`
57+
58+
参见 [MDN 文档](https://developer.mozilla.org/zh-CN/docs/Web/API/PerformanceObserver/disconnect)

cndocs/global-performance.md

Lines changed: 79 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,84 @@ id: global-performance
33
title: performance
44
---
55

6-
:::warning
7-
🚧 本页面仍在完善中,请参考 [MDN 文档](https://developer.mozilla.org/zh-CN/docs/Web/API/Performance) 获取更多信息。
6+
全局 [`performance`](https://developer.mozilla.org/zh-CN/docs/Web/API/Window/performance) 对象,按照 Web 规范定义。
7+
8+
---
9+
10+
# 参考
11+
12+
## 实例属性
13+
14+
### `eventCounts`
15+
16+
参见 [MDN 文档](https://developer.mozilla.org/zh-CN/docs/Web/API/Performance/eventCounts)
17+
18+
### `memory`
19+
20+
参见 [MDN 文档](https://developer.mozilla.org/zh-CN/docs/Web/API/Performance/memory)
21+
22+
### `rnStartupTiming` ⚠️
23+
24+
:::warning 非标准
25+
这是 React Native 特有的扩展。
26+
:::
27+
28+
提供应用启动时间的相关信息。
29+
30+
```ts
31+
get rnStartupTiming(): ReactNativeStartupTiming;
32+
```
33+
34+
`ReactNativeStartupTiming` 接口提供以下字段:
35+
36+
| 名称 | 类型 | 描述 |
37+
| ---------------------------------------- | -------------- | ---------------------------------------------- |
38+
| `startTime` | number \| void | React Native 运行时初始化开始的时间。 |
39+
| `executeJavaScriptBundleEntryPointStart` | number \| void | 应用 bundle 开始执行的时间。 |
40+
| `endTime` | number \| void | React Native 运行时完全初始化完成的时间。 |
41+
42+
### `timeOrigin`
43+
44+
:::warning 部分支持
45+
提供的是从 UNIX 纪元到系统启动的毫秒数,而非从 UNIX 纪元到应用启动的毫秒数。
46+
:::
47+
48+
参见 [MDN 文档](https://developer.mozilla.org/zh-CN/docs/Web/API/Performance/timeOrigin)
49+
50+
## 实例方法
51+
52+
### `clearMarks()`
53+
54+
参见 [MDN 文档](https://developer.mozilla.org/zh-CN/docs/Web/API/Performance/clearMarks)
55+
56+
### `clearMeasures()`
57+
58+
参见 [MDN 文档](https://developer.mozilla.org/zh-CN/docs/Web/API/Performance/clearMeasures)
59+
60+
### `getEntries()`
61+
62+
参见 [MDN 文档](https://developer.mozilla.org/zh-CN/docs/Web/API/Performance/getEntries)
63+
64+
### `getEntriesByName()`
65+
66+
参见 [MDN 文档](https://developer.mozilla.org/zh-CN/docs/Web/API/Performance/getEntriesByName)
67+
68+
### `getEntriesByType()`
69+
70+
参见 [MDN 文档](https://developer.mozilla.org/zh-CN/docs/Web/API/Performance/getEntriesByType)
71+
72+
### `mark()`
73+
74+
参见 [MDN 文档](https://developer.mozilla.org/zh-CN/docs/Web/API/Performance/mark)
75+
76+
### `measure()`
77+
78+
参见 [MDN 文档](https://developer.mozilla.org/zh-CN/docs/Web/API/Performance/measure)
79+
80+
### `now()`
81+
82+
:::warning 部分支持
83+
提供的是从系统启动开始的毫秒数,而非从应用启动开始的毫秒数。
884
:::
985

10-
全局 `performance` 对象,按照 Web 规范定义
86+
参见 [MDN 文档](https://developer.mozilla.org/zh-CN/docs/Web/API/Performance/now)

0 commit comments

Comments
 (0)