React Native 小记
最近在写 React Native,把遇到的东西小记一下。后面遇到的再在这里补充。
babel 插件
babel-plugin-root-import
配合tsconfig
给文件夹起别名。安装 babel-plugin-root-import
yarn add -D babel-plugin-root-import
配置
babel.config.js
// babel.config.js module.exports = function (api) { api.cache(true); return { //... 其他配置 plugins: [ // 其他插件 // ---start--- [ 'babel-plugin-root-import', { paths: [ { rootPathSuffix: './src', rootPathPrefix: '@/', }, // 其他别名 ], }, ], // ---end--- ], }; };
配置
tsconfig.json
// tsconfig.json { // 其他配置 "compilerOptions": { // 其他配置 // ---start--- "paths": { "@/*": [ "src/*" ], // 其他别名 } // ---end--- }, }
React Native 组件
组件库:
React Native Elements: Elements 组件库 RN 版。组件相对较全
React Native Paper: 浓重 Material 风格,组件相对少一些
Ant Design Mobile RN: Ant Design RN 版,更新比较缓慢
NativeBase: 官网现在推荐使用 Gluestack 作为新项目框架
组件:
react-native-fast-image: 支持缓存的图片组件,加载快速
lottie-react-native: LottieFiles 动画库
react-native-htmlview: 渲染 HTML
react-native-pager-view: 允许组件以 swiper 的方式滚动展示(适合产品展示介绍页面)
react-native-webview: 使用 Webview 展现网页
reanimated-bottom-sheet: 动画丝滑的 Bottom Sheet
react-native-paper-dates: 日期选择组件
其他工具
Drizzle: TypeScript ORM。支持 Expo SQLite。
react-native-mmkv-storage: 数据本地储存(提供了hooks使用)
react-native-image-picker: 选择图片(可以调用系统相机拍照)
react-hook-form: 表单 hook