Skip to content

Commit bfa6a44

Browse files
committed
sync
1 parent 3d39f4a commit bfa6a44

11 files changed

+706
-293
lines changed

cndocs/build-speed.md

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@ title: 优化编译速度
99
为了减轻性能损失,本页面提供了一些建议来**改善您的构建时间**
1010

1111
:::info
12-
如果您注意到使用新架构在 Android 上构建时间较慢,请尽量升级 React Native 到最新版本。
12+
13+
请注意,这些建议是高级功能,需要对原生构建工具有一定的了解。
14+
1315
:::
1416

1517
## 仅在开发过程中构建一个 ABI(仅适用于 Android)
@@ -54,6 +56,32 @@ reactNativeArchitectures=armeabi-v7a,arm64-v8a,x86,x86_64
5456

5557
一旦你构建了应用的**发布版本**,不要忘记移除这些标志,因为你希望构建一个适用于所有 ABI 而不仅仅是在日常开发流程中使用的那个的 apk/app bundle。
5658

59+
60+
## 启用 Gradle 配置缓存(仅适用于 Android)
61+
62+
从 React Native 0.79 开始,您还可以启用 Gradle 配置缓存。
63+
64+
当您使用 `yarn android` 运行 Android 构建时,您将执行一个由两个步骤组成的 Gradle 构建:
65+
66+
- 配置阶段,当所有 `.gradle` 文件都被评估时。
67+
- 执行阶段,当任务实际执行时,Java/Kotlin 代码被编译等。
68+
69+
您现在可以启用配置缓存,这将允许您在后续构建中跳过配置阶段。
70+
71+
这对于频繁更改原生代码非常有用,因为它可以提高构建速度。
72+
73+
例如,您可以看到在原生代码更改后重建 RN-Tester 时构建速度有多快:
74+
75+
![gradle config caching](/docs/assets/gradle-config-caching.gif)
76+
77+
您可以通过在 `android/gradle.properties` 文件中添加以下行来启用 Gradle 配置缓存:
78+
79+
```
80+
org.gradle.configuration-cache=true
81+
```
82+
83+
请参阅 [官方 Gradle 文档](https://docs.gradle.org/current/userguide/configuration_cache.html) 了解更多信息。
84+
5785
## 使用编译器缓存
5886

5987
如果您经常运行本地构建(无论是 C++ 还是 Objective-C),您可能会从使用**编译器缓存**中受益。

cndocs/platform.md

Lines changed: 66 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -7,26 +7,33 @@ title: Platform
77

88
```SnackPlayer name=Platform%20API%20Example&supportedPlatforms=ios,android
99
import React from 'react';
10-
import { Platform, StyleSheet, Text, ScrollView } from 'react-native';
10+
import {Platform, StyleSheet, Text, ScrollView} from 'react-native';
11+
import {SafeAreaView, SafeAreaProvider} from 'react-native-safe-area-context';
1112
1213
const App = () => {
1314
return (
14-
<ScrollView contentContainerStyle={styles.container}>
15-
<Text>OS</Text>
16-
<Text style={styles.value}>{Platform.OS}</Text>
17-
<Text>OS Version</Text>
18-
<Text style={styles.value}>{Platform.Version}</Text>
19-
<Text>isTV</Text>
20-
<Text style={styles.value}>{Platform.isTV.toString()}</Text>
21-
{Platform.OS === 'ios' && <>
22-
<Text>isPad</Text>
23-
<Text style={styles.value}>{Platform.isPad.toString()}</Text>
24-
</>}
25-
<Text>Constants</Text>
26-
<Text style={styles.value}>
27-
{JSON.stringify(Platform.constants, null, 2)}
28-
</Text>
29-
</ScrollView>
15+
<SafeAreaProvider>
16+
<SafeAreaView>
17+
<ScrollView contentContainerStyle={styles.container}>
18+
<Text>OS</Text>
19+
<Text style={styles.value}>{Platform.OS}</Text>
20+
<Text>OS Version</Text>
21+
<Text style={styles.value}>{Platform.Version}</Text>
22+
<Text>isTV</Text>
23+
<Text style={styles.value}>{Platform.isTV.toString()}</Text>
24+
{Platform.OS === 'ios' && (
25+
<>
26+
<Text>isPad</Text>
27+
<Text style={styles.value}>{Platform.isPad.toString()}</Text>
28+
</>
29+
)}
30+
<Text>Constants</Text>
31+
<Text style={styles.value}>
32+
{JSON.stringify(Platform.constants, null, 2)}
33+
</Text>
34+
</ScrollView>
35+
</SafeAreaView>
36+
</SafeAreaProvider>
3037
);
3138
};
3239
@@ -39,8 +46,8 @@ const styles = StyleSheet.create({
3946
value: {
4047
fontWeight: '600',
4148
padding: 4,
42-
marginBottom: 8
43-
}
49+
marginBottom: 8,
50+
},
4451
});
4552
4653
export default App;
@@ -54,8 +61,8 @@ export default App;
5461

5562
### `constants`
5663

57-
```jsx
58-
Platform.constants;
64+
```tsx
65+
static constants: PlatformConstants;
5966
```
6067

6168
Returns an object which contains all available common and specific constants related to the platform.
@@ -84,8 +91,8 @@ Returns an object which contains all available common and specific constants rel
8491

8592
### `isPad` <div class="label ios">iOS</div>
8693

87-
```jsx
88-
Platform.isPad;
94+
```tsx
95+
static isPad: boolean;
8996
```
9097

9198
Returns a boolean which defines if device is an iPad.
@@ -98,8 +105,8 @@ Returns a boolean which defines if device is an iPad.
98105

99106
### `isTV`
100107

101-
```jsx
102-
Platform.isTV;
108+
```tsx
109+
static isTV: boolean;
103110
```
104111

105112
Returns a boolean which defines if device is a TV.
@@ -110,10 +117,24 @@ Returns a boolean which defines if device is a TV.
110117

111118
---
112119

120+
### `isVision`
121+
122+
```tsx
123+
static isVision: boolean;
124+
```
125+
126+
Returns a boolean which defines if device is an Apple Vision. _If you are using [Apple Vision Pro (Designed for iPad)](https://developer.apple.com/documentation/visionos/checking-whether-your-app-is-compatible-with-visionos) `isVision` will be `false` but `isPad` will be `true`_
127+
128+
| Type |
129+
| ------- |
130+
| boolean |
131+
132+
---
133+
113134
### `isTesting`
114135

115-
```jsx
116-
Platform.isTesting;
136+
```tsx
137+
static isTesting: boolean;
117138
```
118139

119140
Returns a boolean which defines if application is running in Developer Mode with testing flag set.
@@ -126,8 +147,8 @@ Returns a boolean which defines if application is running in Developer Mode with
126147

127148
### `OS`
128149

129-
```jsx
130-
static Platform.OS
150+
```tsx
151+
static OS: 'android' | 'ios';
131152
```
132153

133154
Returns string value representing the current OS.
@@ -140,8 +161,8 @@ Returns string value representing the current OS.
140161

141162
### `Version`
142163

143-
```jsx
144-
Platform.Version;
164+
```tsx
165+
static Version: 'number' | 'string';
145166
```
146167

147168
Returns the version of the OS.
@@ -154,8 +175,8 @@ Returns the version of the OS.
154175

155176
### `select()`
156177

157-
```jsx
158-
static select(config: object): any
178+
```tsx
179+
static select(config: Record<string, T>): T;
159180
```
160181

161182
Returns the most fitting value for the platform you are currently running on.
@@ -177,45 +198,45 @@ The `config` parameter is an object with the following keys:
177198

178199
**Example usage:**
179200

180-
```jsx
181-
import { Platform, StyleSheet } from 'react-native';
201+
```tsx
202+
import {Platform, StyleSheet} from 'react-native';
182203

183204
const styles = StyleSheet.create({
184205
container: {
185206
flex: 1,
186207
...Platform.select({
187208
android: {
188-
backgroundColor: 'green'
209+
backgroundColor: 'green',
189210
},
190211
ios: {
191-
backgroundColor: 'red'
212+
backgroundColor: 'red',
192213
},
193214
default: {
194215
// other platforms, web for example
195-
backgroundColor: 'blue'
196-
}
197-
})
198-
}
216+
backgroundColor: 'blue',
217+
},
218+
}),
219+
},
199220
});
200221
```
201222

202223
This will result in a container having `flex: 1` on all platforms, a green background color on Android, a red background color on iOS, and a blue background color on other platforms.
203224

204225
Since the value of the corresponding platform key can be of type `any`, [`select`](platform.md#select) method can also be used to return platform-specific components, like below:
205226

206-
```jsx
227+
```tsx
207228
const Component = Platform.select({
208229
ios: () => require('ComponentIOS'),
209-
android: () => require('ComponentAndroid')
230+
android: () => require('ComponentAndroid'),
210231
})();
211232

212233
<Component />;
213234
```
214235

215-
```jsx
236+
```tsx
216237
const Component = Platform.select({
217238
native: () => require('ComponentForNative'),
218-
default: () => require('ComponentForWeb')
239+
default: () => require('ComponentForWeb'),
219240
})();
220241

221242
<Component />;

cnwebsite/package.json

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,22 +14,28 @@
1414
"start": "docusaurus start",
1515
"build": "docusaurus build && yarn run update-redirect ./build/_redirects ./versions.json",
1616
"build:fast": "PREVIEW_DEPLOY=true yarn run build",
17+
"tsc": "npx tsc --noEmit",
1718
"swizzle": "docusaurus swizzle",
1819
"deploy": "docusaurus deploy",
1920
"serve": "docusaurus serve",
2021
"clear": "docusaurus clear",
2122
"test": "yarn build",
2223
"version:cut": "docusaurus docs:version",
23-
"format:source": "prettier --write {{core,src}/**/*.js,*.js}",
24-
"format:markdown": "prettier --write ../docs/*.md && prettier --write {{versioned_docs,src}/**/*.md,blog/*.md}",
24+
"format:source": "prettier --write '{core,src}/**/*.{js,jsx,ts,tsx}'",
25+
"format:markdown": "prettier --write ../docs/*.md && prettier --write {versioned_docs/**/*.md,blog/*.md}",
2526
"format:style": "prettier --write src/**/*.{scss,css}",
27+
"format:examples": "eslint-examples-js --fix && eslint-examples-tsx --fix",
2628
"prettier": "yarn format:source && yarn format:markdown && yarn format:style",
27-
"lint": "eslint ../docs/** blog/** core/** src/**/*.{js,md} ./*.js",
29+
"lint": "eslint ../docs/** blog/** \"{core,src}/**/*.{js,jsx,ts,tsx}\"",
30+
"lint:examples": "eslint-examples-js && eslint-examples-tsx && tsc-examples",
2831
"lint:versioned": "eslint versioned_docs/**",
29-
"language:lint": "cd ../ && alex",
30-
"language:lint:versioned": "cd ../ && alex .",
31-
"ci:lint": "yarn lint && yarn lint:versioned && yarn language:lint:versioned",
32-
"pwa:generate": "npx pwa-asset-generator ./static/img/header_logo.svg ./static/img/pwa --background #20232a --icon-only -opaque true --maskable true --type png"
32+
"lint:markdown": "remark ../docs --quiet -r .remarkrc.mjs",
33+
"lint:markdown:versioned": "remark ./versioned_docs --quiet -r .remarkrc.mjs",
34+
"lint:format": "prettier --check '{core,src}/**/*.{js,jsx,ts,tsx}' ../docs/*.md {versioned_docs/**/*.md,blog/*.md} src/**/*.{scss,css}",
35+
"language:lint": "cd ../ && alex && case-police 'docs/*.md' -d ./website/react-native-dict.json --disable SDK,URI",
36+
"language:lint:versioned": "cd ../ && alex . && case-police '**/*.md' -d ./website/react-native-dict.json --disable SDK,URI",
37+
"ci:lint": "yarn lint && yarn lint:examples && yarn lint:versioned && yarn language:lint:versioned && yarn lint:markdown && yarn lint:format",
38+
"pwa:generate": "npx pwa-asset-generator ./static/img/header_logo.svg ./static/img/pwa --padding '40px' --background 'rgb(32, 35, 42)' --icon-only --opaque true"
3339
},
3440
"browserslist": {
3541
"production": [
@@ -62,9 +68,12 @@
6268
"@react-native-website/lint-examples": "0.0.0",
6369
"@react-native-website/update-redirects": "0.0.0",
6470
"@types/google.analytics": "^0.0.46",
65-
"alex": "^10.0.0",
71+
"alex": "^11.0.1",
72+
"case-police": "^1.0.0",
73+
"eslint": "^8.57.1",
6674
"fs-extra": "^11.2.0",
6775
"glob": "^11.0.0",
76+
"prettier": "^3.5.3",
6877
"remark-cli": "^12.0.1",
6978
"typescript": "^5.7.2"
7079
}
365 KB
Loading
290 KB
Loading
837 KB
Loading
4.56 MB
Loading
614 KB
Loading
2.41 MB
Loading
474 KB
Loading

0 commit comments

Comments
 (0)