2020年React Native使用Ant Design Mobile RN组件
Ant Design Mobile RN是一个很优秀的React Native 界面库,可以帮助我们简单方便的开发出漂亮的界面。我在基于0.63版本使用的过程中遇到一些小波折,比如字体无法正常,各种红屏,缺少各种组件之类的。这里分享一下使用过程。
图文不直观?来看视频吧
https://www.bilibili.com/video/bv1Mf4y1X7ir
新手教程之React Native 0.63版本使用Ant Design Mobile RN组件
新建RN项目
npx react-native init AntDesignDemo
换国内清华大学的提高速度(非必须)
ios/Podfile文件头部增加下面
source 'https://mirrors.tuna.tsinghua.edu.cn/git/CocoaPods/Specs.git'
安装组件
npm install @ant-design/react-native --save
配置按需加载
安装babel-plugin-import组件
npm install babel-plugin-import --save-dev
babel.config.js配置文件增加如下配置:
plugins: [['import', {libraryName: '@ant-design/react-native'}], // 与 Web 平台的区别是不需要设置 style],
修改完成后的如下:
module.exports = {presets: ['module:metro-react-native-babel-preset'],plugins: [['import', {libraryName: '@ant-design/react-native'}], // 与 Web 平台的区别是不需要设置 style],
};
增加ant design依赖的组件(RN0.63)
实测到上面的步骤0.61版本的RN已经可以运行了,但是的0.63版本会报各种红屏。下面开始增加依赖解决红屏问题。
红屏如下:
npm install @react-native-community/cameraroll @react-native-community/picker @react-native-community/segmented-control @react-native-community/slider @react-native-community/viewpager @react-native-community/async-storage --save
或yarn
yarn add @react-native-community/cameraroll @react-native-community/picker @react-native-community/segmented-control @react-native-community/slider @react-native-community/viewpager @react-native-community/async-storage
执行上面命令执行缺失的组件(RN0.63版本),非0.63版本的按需增加组件。
2020年11月10日更新
最近有小伙伴遇到个问题,在使用RN0.63.3版本时无法正常安装npm install @react-native-community/cameraroll组件,大概会提示 安装的RN版本要《=0.62,Ant又依赖此组件导致无法在0.63版本中,使用Ant。
经检测,他的node版本是最新的,确实无法正常安装。
解决办法:
node版本降级到14试试,我的node版本是:
itkey@MacBook-Pro ~ % node -v
v14.2.0
降级方法:
sudo npm install n -g
sudo n 14.2.0
这两个命令就可以完成降级了,关于node降级详细讲解请参照:https://blog.csdn.net/xiasohuai/article/details/92995717
组件安装完成后,要执行下pod install
cd ios && pod install && cd ..
此时运行ios版本yarn ios ,如果使用到使用字体图标的页面会出现如下红屏错误,
Unrecognized font family 'antoutline'
报错分析:找不到相应的字体。
官方文档的解决办法是:
链接字体图标#
react-native link @ant-design/icons-react-native
根据我实测,没有用。懂的小伙伴请留言告知原因。
(IOS)解决字体缺失问题
使用xcode打开ios目录下的.xcworkspace文件,打开ios项目。
用访达打开/node_modules/@ant-design/icons-react-native/fonts目录并拖拽到xcode中,操作如下:
字体文件已经增加了,现在还需要,修改Info.plist配置文件。
修改Info.plist配置文件
xcode中可以在Info.plist文件中右击,“Open As”=>"Source Code",在配置中增加如下内容:
<key>UIAppFonts</key>
<array><string>antfill.ttf</string><string>antoutline.ttf</string>
</array>
修改完成后的内容如下:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict><key>UIAppFonts</key><array><string>antfill.ttf</string><string>antoutline.ttf</string></array><key>CFBundleDevelopmentRegion</key><string>en</string><key>CFBundleDisplayName</key><string>pomegranate</string><key>CFBundleExecutable</key><string>$(EXECUTABLE_NAME)</string><key>CFBundleIdentifier</key><string>$(PRODUCT_BUNDLE_IDENTIFIER)</string><key>CFBundleInfoDictionaryVersion</key><string>6.0</string><key>CFBundleName</key><string>$(PRODUCT_NAME)</string><key>CFBundlePackageType</key><string>APPL</string><key>CFBundleShortVersionString</key><string>1.0</string><key>CFBundleSignature</key><string>????</string><key>CFBundleVersion</key><string>1</string><key>LSRequiresIPhoneOS</key><true/><key>NSAppTransportSecurity</key><dict><key>NSAllowsArbitraryLoads</key><true/><key>NSExceptionDomains</key><dict><key>localhost</key><dict><key>NSExceptionAllowsInsecureHTTPLoads</key><true/></dict></dict></dict><key>NSLocationWhenInUseUsageDescription</key><string></string><key>UILaunchStoryboardName</key><string>LaunchScreen</string><key>UIRequiredDeviceCapabilities</key><array><string>armv7</string></array><key>UISupportedInterfaceOrientations</key><array><string>UIInterfaceOrientationPortrait</string><string>UIInterfaceOrientationLandscapeLeft</string><string>UIInterfaceOrientationLandscapeRight</string></array><key>UIViewControllerBasedStatusBarAppearance</key><false/>
</dict>
</plist>
至此字体添加完成。
来看下效果吧。
安卓版本配置
把字体文件复制到/android/app/src/main/assets/fonts这个目录即可。
看下安卓的最终运行效果。
教程至此就结束了,有疑问请留言。
参考:Ant Design Mobile RN of React官方文档
2020年React Native使用Ant Design Mobile RN组件相关推荐
- Ant Design Mobile是什么?
Ant Design Mobile简称antd-mobile,是Ant Design的移动规范的React实现,是一个基于Preact/React/React Native的UI组件库:UI样式高度可 ...
- Ant Design Mobile 5.6.0版本来了
一.Ant Design Mobile介绍 Ant Design Mobile( 官网地址:Ant Design Mobile - Ant Design Mobile ) 是由支付宝设计团队基于蚂蚁集 ...
- react-hooks+Ant Design Mobile中的自定义表单验证
Ant Design Mobile中的表单校验 将validator放在 rules 对象中 <Form.Itemname='uName'label='姓名'requiredrules={[{r ...
- 如何修改ant design mobile或者其他UI组件的全局样式
问题描述: 有时候你可能会遇到一些前端CSS实现上的问题,因为美工的画图与你的项目使用的UI框架的样式大有出入,所以在写页面样式的时候多多少少会让你有些头疼,那么该类问题应该如何解决呢? 原因分析: ...
- 基于React、Ant Design的ButtonGroup组件
目录 介绍 使用方式 安装 使用 API Props children 介绍 本组件基于React.Ant Design,适用于React + Ant Design项目 本组件设计为超过一定数量的按钮 ...
- React Native按钮详解|Touchable系列组件使用详解
转载自:http://www.devio.org/2017/01/10/React-Native按钮详解-Touchable系列组件使用详解/ 在做App开发过程中离不了的需要用户交互,说到交互,我们 ...
- Ant Design中Form组件重置验证条件resetFields()方法
Ant Design中Form组件重置验证条件resetFields()方法 需求, 实际完成时间(与任务生成日期联动,若任务生成日期选上,实际完成时间禁选) 却发现在验证完之后填写实际完成时间后任务 ...
- Ant Design Vue Table 组件合并单元格
Ant Design Vue Table 组件合并单元格 项目开发中,有时候需要实现单元格合并的需求,这里记录一下在Ant Design Vue的实现. <template><div ...
- 标题Ant Design of Vue 组件库中Modal“确认“按钮和“取消“按钮成英文状态
标题Ant Design of Vue 组件库中Modal"确认"按钮和"取消"按钮成英文状态 因为是国际化的原因,造成确定按钮和取消按钮变成英文,需要设置 o ...
最新文章
- mysql 表引擎无法更新_Mysql安装archive引擎更新表引擎
- 没有对“C:/WINDOWS/Microsoft.NET/Framework/v2.0.50727/Temporary ASP.NET Files”的写访问权限...
- vue 动态路由_Vue.js应用性能优化三
- 他山之石可以攻玉, 不可不读的阿里云原生中间件行业案例与实践集锦
- Flink 状态管理:算子状态、键值分区状态、状态后端、有状态算子的扩缩容
- 一 WebService 简介
- 【2018.3.17】模拟赛之三-ssl1863jzoj1367 俄罗斯方块【模拟】
- emacs shell插件_Windows 下 Emacs 中的 zsh shell 使用方法
- pyqt5 qscrollarea到达_pyqt5 QScrollArea设置在自定义侧(任何位置)
- 基础计算机构,基础计算与设计
- 《微信生活白皮书》发布微信用户数据
- php camp,Byte Camp
- [paper reading] DenseNet
- UML类图关系大全【转】
- 优动漫PAINT安装教程
- 将linux系统制作成iso镜像文件
- 计算机职高会考知识,高职考试语文基础知识
- 派工单系统 源码_青鸟报修云酒店设备报修管理系统
- Cannot commit, transaction is already closed
- 马云泄露:2019年两大赚钱趋势,会成就普通人赚千万财富!