项目初始化
Have a good day
萌兔猛进
项目初始化 资源准备
初始化工程和安装
完成基础项目配置:名字,图标,应用id
核对设计稿,准备资源图片,导入图片
项目配置TypeScript
安装 TypeScript
1
npm install --save-dev typescript
生成tsconfig.json
tsc --init
1
1
2
3
3. 安装类型申明(众多)npm i –save-dev @types/react @types/react-native
1
2
3
4
5
### AsyncStorage :数据存储
1. 集成async-storage@react-native-async-storage/async-storage
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
2. 保存数据:AsyncStorage.setItem\(\)
3. 读取数据:AsyncStorage.getItem\(\)
### 前期重点:路由管理
1. 集成react-navigation
1. ```
npm i @react-navigation/bottom-tabs
npm i @react-navigation/native
npm i @react-navigation/stack
npm i react-native-gesture-handler
npm i react-native-safe-area-context
npm i react-native-screens1
页面跳转
页面替换
页面回退
构建导航栈
在App.tsx根节点构建导航栈
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40import React, { Component } from 'react';
import type {PropsWithChildren} from 'react';
import {
SafeAreaView,
StatusBar
} from 'react-native';
import { SafeAreaProvider } from 'react-native-safe-area-context';
import axios from 'axios';
import { Button } from '@rneui/base';
import { NavigationContainer } from '@react-navigation/native';
import { createStackNavigator } from '@react-navigation/stack';
import PageA from './src/modules/PageA';
import PageB from './src/modules/PageB';
const Stack = createStackNavigator();
function App() : JSX.Element{
return (
<SafeAreaProvider>
<StatusBar
barStyle={'dark-content'}
backgroundColor={'white'}
/>
<NavigationContainer>
<Stack.Navigator initialRouteName='PageA'>
<Stack.Screen
name="PageA"
component={PageA}
options={{
}}
/>
<Stack.Screen
name="PageB"
component={PageB}
options={{
}}
/>
</Stack.Navigator>
);
}
export default App;
1 |
|
本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明来自 fortunate!
评论