Skip to content

Commit d6b2007

Browse files
authored
Merge pull request #81 from AsteriskZuo/doc
rn: upate quick start
2 parents 2d26a0d + 58940ea commit d6b2007

File tree

1 file changed

+110
-44
lines changed

1 file changed

+110
-44
lines changed

docs/docs/sdk/react-native/quickstart.md

Lines changed: 110 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
- MacOS 12 或更高版本
1818
- React-Native 0.66 或更高版本
19-
- NodeJs 16.18 或更高版本
19+
- NodeJs 18 或更高版本
2020

2121
对于 iOS 应用:
2222

@@ -40,12 +40,13 @@
4040
2. 打开终端,进入需要创建项目的目录,输入命令创建 React Native 项目:
4141

4242
```sh
43-
npx @react-native-community/cli init --skip-install simple_demo
44-
cd simple_demo
43+
npx @react-native-community/cli init --skip-install --version 0.76 quick_start_demo
44+
cd quick_start_demo
45+
yarn set version 1.22.19
4546
yarn
4647
```
4748

48-
创建的项目名称为 `simple_demo`
49+
创建的项目名称为 `quick_start_demo`
4950

5051
3. 在终端命令行,输入以下命令添加依赖:
5152

@@ -95,7 +96,7 @@ cd ios && pod install && cd ..
9596

9697
## 实现发送和接收单聊消息
9798

98-
建议使用 `visual studio code` 打开文件夹 `simple_demo`,打开文件 `App.js`,删除全部内容,并添加如下内容:
99+
建议使用 `visual studio code` 打开文件夹 `quick_start_demo`,打开文件 `App.js`,删除全部内容,并添加如下内容:
99100

100101
```javascript
101102
// 导入依赖包。
@@ -292,99 +293,164 @@ const App = () => {
292293
// UI 渲染。
293294
return (
294295
<SafeAreaView>
295-
<View>
296-
<Text>{title}</Text>
296+
<View style={styles.titleContainer}>
297+
<Text style={styles.title}>{title}</Text>
297298
</View>
298299
<ScrollView>
299-
<View>
300+
<View style={styles.inputCon}>
300301
<TextInput
301302
multiline
303+
style={styles.inputBox}
302304
placeholder="Enter username"
303305
onChangeText={(text) => setUsername(text)}
304306
value={username}
305307
/>
306308
</View>
307-
<View>
309+
<View style={styles.inputCon}>
308310
<TextInput
309311
multiline
312+
style={styles.inputBox}
310313
placeholder="Enter chatToken"
311314
onChangeText={(text) => setChatToken(text)}
312315
value={chatToken}
313316
/>
314317
</View>
315-
<View>
316-
<Text onPress={login}>SIGN IN</Text>
317-
<Text onPress={logout}>SIGN OUT</Text>
318+
<View style={styles.buttonCon}>
319+
<Text style={styles.eachBtn} onPress={login}>
320+
SIGN IN
321+
</Text>
322+
<Text style={styles.eachBtn} onPress={logout}>
323+
SIGN OUT
324+
</Text>
318325
</View>
319-
<View>
326+
<View style={styles.inputCon}>
320327
<TextInput
321328
multiline
329+
style={styles.inputBox}
322330
placeholder="Enter the username you want to send"
323331
onChangeText={(text) => setTargetId(text)}
324332
value={targetId}
325333
/>
326334
</View>
327-
<View>
335+
<View style={styles.inputCon}>
328336
<TextInput
329337
multiline
338+
style={styles.inputBox}
330339
placeholder="Enter content"
331340
onChangeText={(text) => setContent(text)}
332341
value={content}
333342
/>
334343
</View>
344+
<View style={styles.buttonCon}>
345+
<Text style={styles.btn2} onPress={sendmsg}>
346+
SEND TEXT
347+
</Text>
348+
</View>
349+
<View>
350+
<Text style={styles.logText} multiline={true}>
351+
{logText}
352+
</Text>
353+
</View>
335354
<View>
336-
<Text onPress={sendmsg}>SEND TEXT</Text>
355+
<Text style={styles.logText}>{}</Text>
337356
</View>
338357
<View>
339-
<Text multiline={true}>{logText}</Text>
358+
<Text style={styles.logText}>{}</Text>
340359
</View>
341360
</ScrollView>
342361
</SafeAreaView>
343362
);
344363
};
345364

365+
// 设置样式
366+
const styles = StyleSheet.create({
367+
titleContainer: {
368+
height: 60,
369+
backgroundColor: "#6200ED",
370+
},
371+
title: {
372+
lineHeight: 60,
373+
paddingLeft: 15,
374+
color: "#fff",
375+
fontSize: 20,
376+
fontWeight: "700",
377+
},
378+
inputCon: {
379+
marginLeft: "5%",
380+
width: "90%",
381+
height: 60,
382+
paddingBottom: 6,
383+
borderBottomWidth: 1,
384+
borderBottomColor: "#ccc",
385+
},
386+
inputBox: {
387+
marginTop: 15,
388+
width: "100%",
389+
fontSize: 14,
390+
fontWeight: "bold",
391+
},
392+
buttonCon: {
393+
marginLeft: "2%",
394+
width: "96%",
395+
flexDirection: "row",
396+
marginTop: 20,
397+
height: 26,
398+
justifyContent: "space-around",
399+
alignItems: "center",
400+
},
401+
eachBtn: {
402+
height: 40,
403+
width: "28%",
404+
lineHeight: 40,
405+
textAlign: "center",
406+
color: "#fff",
407+
fontSize: 16,
408+
backgroundColor: "#6200ED",
409+
borderRadius: 5,
410+
},
411+
btn2: {
412+
height: 40,
413+
width: "45%",
414+
lineHeight: 40,
415+
textAlign: "center",
416+
color: "#fff",
417+
fontSize: 16,
418+
backgroundColor: "#6200ED",
419+
borderRadius: 5,
420+
},
421+
logText: {
422+
padding: 10,
423+
marginTop: 10,
424+
color: "#ccc",
425+
fontSize: 14,
426+
lineHeight: 20,
427+
},
428+
});
429+
346430
export default App;
347431
```
348432

349433
## 编译和运行项目
350434

351435
现在你可以开始在目标平台创建和运行项目。
352436

353-
编译并在 iOS 真机运行:
354-
355-
1. 连接苹果手机,设置为开发者模式;
356-
2. 打开 `simple_demo/ios`,使用 `xcode` 打开 `simple_demo.xcworkspace`
357-
3. 依次点击 **Targets** > **simple_demo** > **Signing & Capabilities** 在签名选项下设置应用签名;
358-
4. 点击 `Build` 构建并运行项目。程序构建完成后,自动安装和运行,并显示应用界面。
359-
360-
![img](/images/react-native/ios-1.png)
361-
362-
编译并在 iOS 模拟器中运行:
363-
364-
1. 打开 `simple_demo/ios`,使用 `xcode` 打开 `simple_demo.xcworkspace`
365-
2.`xcode` 中,选择模拟器 `iphone13`
366-
3. 点击 `Build` 构建并运行项目。程序构建完成后,自动安装和运行,并显示应用界面。
367-
368-
![img](/images/react-native/ios-2.png)
369-
370-
编译并在 Android 真机运行:
371-
372-
1. 在 Android Studio 中打开 `simple_demo/android`
373-
2. 连接 Android 系统手机,设置为开发者模式,并且设置 USB 可调式;
374-
3. 设置数据转发:在终端命令行输入 `adb reverse tcp:8081 tcp:8081`
375-
4. 启动服务:执行 `package.json` 里面的命令:`"start": "react-native start"`,在终端中运行命令 `yarn start`
437+
编译运行 ios 设备:
376438

377439
```sh
378-
yarn start
440+
yarn run ios
379441
```
380442

381-
5. 程序构建完成后,自动安装和运行,并显示应用界面。
443+
编译运行 android 设备:
382444

383-
![img](/images/react-native/android-1.png)
445+
```sh
446+
yarn run android
447+
```
384448

385-
demo 的界面:
449+
运行本地服务
386450

387-
![img](/images/react-native/main.png)
451+
```sh
452+
yarn run start
453+
```
388454

389455
## 测试你的 app
390456

0 commit comments

Comments
 (0)