Start knocking on the blackboard! !
Whether you are a novice or a veteran of RN, follow the process, the RN project is not a problem at all!
1. Website collection
Expo configuration URL: https://blog.expo.io/building-a-react-native-app-using-expo-and-typescript-part-1-a81b6970bb82
Tabbar URL: https://github.com/ptomasroos/react-native-tab-navigator
Tabbar style settings: https://www.npmjs.com/package/react-native-navigator
swiper URL: https://github.com/leecade/react-native-swiper
navigation URL: https://reactnavigation.org/docs/en/2.x/headers.html
camera URL: https://docs.expo.io/versions/v31.0.0/sdk/camera
switch URL: https://reactnavigation.cn/docs/ switch/
Two, installation
yarn global add create-react-native-app
create-react-native-app cookbooks
? Choose a template: blank
Yarn add typescript tslint --dev can expose ts errors
yarn add @types/react @types/react-native @types/react-dom --dev After installing react-dom, you can use ts based on the browser
yarn add concurrently rimraf react-native-scripts --dev can switch the environment () automatic allocation of port numbers
yarn add ts-jest @types/jest @types/react-test-renderer --dev
tsc --init initialization, you can create tsconfig.json file manually without this command
If you use this command, a tsconfig.js file will be automatically generated, delete all the contents, and copy the following configuration information completely
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 40 41 42 43 |
|
Configure the npm expo-cli script scripts in the package.json file
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
|
1 2 |
|
1 2 |
|
Delete the content of the App.js file and paste the following content:
1 2 3 |
|
Create a src folder directory, and then drag the babel.config.js file to the src file directory!
After the configuration is complete, you can run directly.
yarn buildAndStart
At this time, a build file will be automatically generated, but there is only the babel.config.js file, but we need to have the App.js file in the build
So you need to create an App.tsx file under src, at this time you can write whatever you want, of course, you can also use the following code to try the effect.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
|
Three, tabbar introduction
yarn add react-native-tab-navigator 这个这个可能用到,可能用不到,如果找不到navigation,可以两个都装一下,非常靠谱!
yarn add @types/react-native-tab-navigator
四、Swiper引入
yarn add react-native-swiper
注意:引入Swipper的时候,你可能会发现swiper小点点不动了?
1 2 |
|
五、MobX引入
yarn add mobx
yarn add mobx-react 需要在App.tsx中引入provider、store
1 |
|
六、路由引入
yarn add [email protected] 有版本限制,需要注意
yarn add @types/[email protected]
1 |
|
七、WebView
1 |
|
采用原生的方法把H5页面嵌入进去
注意:react-native是用前端技术开发原生APP,它不是混合式开发
八、camera引入(引入第三方包都需要提供ts支持)
yarn add @types/expo
1 2 |
|
Flip:镜头反转
点击拍照可以拿到图片的url,其实图片已经存入本地
react-native可以将所有的硬件设备挂起
九、switch引入
1 |
|
十、AsyncStorage引入
异步、持久的Key-Value存储系统
1 |
|
1 |
|
1 |
|
十一、上拉刷新、下拉加载 -- FlatList引入
1 |
|