React Native预设占位placeholder的使用
网络编程 2021-07-04 17:32www.168986.cn编程入门
本篇文章主要介绍了React Native预设占位placeholder的使用,长沙网络推广觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随长沙网络推广过来看看吧
当我们首次打开一个app的时候会请求接口获取数据,那么获取数据的这段时间展示什么给用户呢?国内很多app都是千篇一律的用一个菊花代替(俗称loading),或者更有心一点的做一个好看一点的loading,但是这样当拿到数据渲染页面的时候会很生硬的切换,总感觉很low。
facebook首页列表是用一个接近真实布局的骨架动画来代替loading,这东西可以称之为skeleton screen或者placeholder,但是翻译过来真不知道该翻译成什么合适,这么做的好处就是在内容加载完成后可以做到流畅无缝切换真实布局,细节决定产品的质量,我觉得facebook对用户体验,交互的细节做的挺不错。先上一张我的fb截图。
rn-placeholder是rn版本的placeholder,我在次基础上做了对flastlist,listview,SectionList的适配封装。先看一下在我的开源项目中的效果:
看完上面的效果是不是感觉比传统的loading要舒服多了,狼蚁网站SEO优化是example:
一:flastlist,listview,SectionList使用demo
import { ListItem, ListParagraph } from 'ponents'; export default class Zi extends Component { render() { const { loading } = this.props; return ( <ListParagraph ParagraphLength={4} // 要渲染的条数 isLoading={loading} // loading状态 hasTitle // 是否需要title list={this.sectionList} // 这就是SectionList的函数 /> ); } }
注:ListParagraph组件目前在我开源项目中,还没有添加到npm,有需要的到我项目中拿,项目地址在文章末尾
二:左图右内容布局
import Placeholder from 'rn-placeholder'; export default class Cheng extends Component { render() { return <Placeholder.ImageContent hasRadius //左边的方块是否需要圆角 size={60} // 大小 animate="fade" // 动画方式 lineNumber={4} // 右边的线显示的数量 lineSpacing={5} // 行间距的距离 firstLineWidth=90% // 第一行的宽度 lastLineWidth="70%" // 最后一行的宽度 onReady={this.state.isReady} // 内容是否加载完毕,如果加载完毕会切换到你的真实内容布局 > <Text>左图右内容布局</Text> </Placeholder.ImageContent> } }
三:段落布局
import Placeholder from 'rn-placeholder'; export default class Cheng extends Component { render() { return <Placeholder.Paragraph size={60} animate="fade" lineNumber={4} lineSpacing={5} lastLineWidth="30%" onReady={this.state.isReady} > <Text>段落布局</Text> </Placeholder.Paragraph> } }
四:还有Line(行布局),Media(图片布局),使用方法跟 三 一样。
完美收官!
项目demo地址:
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持狼蚁SEO。
编程语言
- 机械手焊接机器人编程 机械手焊接设备编程
- vb数据库编程实例,vb做数据库
- tiobe世界编程语言排行榜,全球编程语言排行
- 成都java编程培训 成都it编程培训中心
- 编程基础培训,编程基础知识培训
- flash游戏编程基础教程,flash游戏开发教程
- 不会英语能学编程吗 不会英语可以学程序员吗
- 爱心代码编程C语言 爱心代码编程c语言公式
- c语言编程学习入门 c语言编程快速入门
- 西门子plc编程培训 西门子plc编程培训班
- 哪里可以学编程 台州哪里可以学编程
- 少儿编程哪个好 少儿编程哪个品牌好
- 编程是什么意思,图形编程是什么意思
- c语言编程软件下载,c语言编程软件在哪下载
- java编程软件下载,java编程下载手机版
- ug编程培训学校,ug编程培训教程