React Native 仿天猫物流跟踪时间轴
最近心血来潮开始学习ReactNative,正好最近有一个项目可能会用到时间轴,页面原型类似于天猫的物流跟踪,如下图
分析之后决定使用ListView来实现,左边的时间轴则使用Art来绘制。
分析左边的时间轴,其实就是每一行都有一条竖线,第一行和最后一行稍微特殊些,第一行需要单独绘制一下,最后一行只显示轴结点上方的线。
为了方便使用,封装成组件,具体实现如下:
- import React, { Component } from 'react';
- import {
- View,
- Text,
- ListView,
- StyleSheet,
- ART
- } from 'react-native';
- const { Surface, Shape, Path } = ART;
- export default class TimeAxis extends React.Component {
- constructor(props) {
- super(props);
- this.state = {
- rowHeight: 60,
- dataSource: new ListView.DataSource({
- rowHasChanged: (row1, row2) => row1 !== row2,
- }),
- };
- }
- componentDidMount() {
- if (this.props.direction) {
- this.props.dataSource = this.props.dataSource.reverse();
- }
- this.setState({
- rowHeight: this.props.rowHeight ? this.props.rowHeight : this.state.rowHeight,
- dataSource: this.state.dataSource.cloneWithRows(this.props.dataSource ? this.props.dataSource : [])
- })
- }
- _renderRow = (rowData, sectionID, rowID) => {
- var item;
- if (this.props.row) {
- item = this.props.row(rowData, rowID, this.state.dataSource.getRowCount());
- } else {
- item = <Text>{rowData}</Text>
- }
- const line = new Path();
- const circle = new Path();
- let circleColor = "#e1e1e1";
- var back;
- if (rowID == 0) {
- line.moveTo(12, 27).lineTo(12, this.state.rowHeight).close();
- circle.moveTo(12, 9)
- .arc(0, 14, 7)
- .arc(0, -14, 7)
- .close();
- circleColor = "#59c93b";
- back = <ART.Shape style={{ zoom: 999, opacity: 0.1 }} d={new Path()
- .moveTo(12, 6)
- .arc(0, 20, 10)
- .arc(0, -20, 10)
- .close()} fill="#d3e2cf"></ART.Shape>
- }
- else {
- let y = this.state.rowHeight;
- if (rowID == this.state.dataSource.getRowCount() - 1) {
- y = this.state.rowHeight * 0.25;
- }
- line.moveTo(12, 0)
- .lineTo(12, y).close();
- circle.moveTo(12, this.state.rowHeight * 0.25)
- .arc(0, 10, 5)
- .arc(0, -10, 5)
- .close();
- }
- var itemStyles = this.props.itemStyle ? [styles.item_content, this.props.itemStyle] : styles.item_content;
- return (
- <View style={[styles.item, { height: this.state.rowHeight }]}>
- <View style={[styles.item_line]}>
- <ART.Surface width={24} height={this.state.rowHeight}>
- {back}
- <ART.Shape d={circle} fill={circleColor} stroke="#e1e1e1" strokeWidth={1}></ART.Shape>
- <ART.Shape d={line} stroke="#e1e1e1" strokeWidth={1}></ART.Shape>
- </ART.Surface>
- </View>
- <View style={itemStyles}>{item}</View>
- </View >
- );
- }
- render() {
- return (
- <ListView
- style={{ marginTop: 5, backgroundColor: '#fff' }}
- dataSource={this.state.dataSource}
- renderRow={this._renderRow.bind(this)}
- renderFooter={this.renderFooter}
- />
- );
- }
- }
- const styles = StyleSheet.create({
- item: {
- marginTop: 1,
- backgroundColor: '#fff',
- flexDirection: 'row'
- },
- item_line: {
- flex: 2,
- paddingLeft: 5,
- },
- item_content: {
- flex: 13,
- borderBottomWidth: 1,
- borderColor: '#b0b0b0'
- }
- });
使用就简单了,设置好dataSource
- var source = [
- { Text: "包裹等待揽收", Time: "2017-06-02 11:49:00" },
- { Text: "[北京市]XX快递 北京XX中心收件员XX已揽件", Time: "2017-06-02 15:49:05" },
- { Text: "[北京市]北京XX中心已发出", Time: "2017-06-02 16:20:11" },
- { Text: "[北京市]快件已到达XX站点", Time: "2017-06-02 20:15:04" },
- { Text: "[北京市]XX站点员:XXX正在派件", Time: "2017-06-03 07:35:18" },
- { Text: "[北京市]已完成", Time: "2017-06-03 08:21:48" }
- ];
设置行高(默认60),设置好每行的显示格式,就可以了。
- <TimeAxis
- itemStyle={{}}
- rowHeight={60}
- dataSource={source}
- row={(rowData, i, count) => {
- var fontColor = '#757575';
- if (i == 0) {
- fontColor = 'green';
- }
- return (
- <View style={{ height: '100%', padding: 5 }}>
- <Text style={{ color: fontColor, flex: 1 }}>{rowData.Text}</Text>
- <Text style={{ color: fontColor, alignItems: 'flex-end' }}>{rowData.Time}</Text>
- </View>
- );
- }}
- />
最张效果如图:
React Native 仿天猫物流跟踪时间轴的更多相关文章
- [RN] React Native 仿美团下拉筛选菜单控件
React Native 仿美团下拉筛选菜单控件 演示效果如下: 使用方法如下: 1.安装 npm install react-native-dropdownmenus --save react-na ...
- React Native仿京东客户端实现(首页 分类 发现 购物车 我的)五个Tab导航页面
1.首先创建 这几个文件 myths-Mac:JdApp myth$ yarn add react-native-tab-navigator 2.各个文件完整代码 1)CartPage.js imp ...
- 带你从零学ReactNative开发跨平台App开发-[react native 仿boss直聘](十三)
ReactNative跨平台开发系列教程: 带你从零学ReactNative开发跨平台App开发(一) 带你从零学ReactNative开发跨平台App开发(二) 带你从零学ReactNative开发 ...
- react native仿微信性别选择-自定义弹出框
简述 要实现微信性别选择需要使用两部分的技术: 第一.是自定义弹出框: 第二.单选框控件使用: 效果 实现 一.配置弹出框 弹出框用的是:react-native-popup-dialog(Git地址 ...
- React Native专题-江清清
本React Native讲解专题:主要讲解了React Native开发,由基础环境搭建配置入门,基础,进阶相关讲解. 刚创建的React Native交流8群:533435865 欢迎各位大牛, ...
- React Native 常用插件案例
(二).基础入门: 1.React Native For Android环境配置以及第一个实例 2.React Native开发IDE安装及配置 3.React Native应用设备运行(Runnin ...
- React Native专题
转载注明出处:地址:http://www.lcode.org本文出自:[江清清的技术专栏]本React Native讲解专题:主要讲解了React Native开发,由基础环境搭建配置入门,基础,进阶 ...
- React Native 二维码扫描组件
学rn得朋友们,你们知道rn开源项目吗?来吧看这里:http://www.marno.cn/(rn开源项目) React Native学习之路(9) - 注册登录验证的实现 + (用Fetch实现po ...
- react-native —— 在Windows下搭建React Native Android开发环境
在Windows下搭建React Native Android开发环境 前段时间在开发者头条收藏了 @天地之灵_邓鋆 分享的<在Windows下搭建React Native Android开发环 ...
随机推荐
- Android计时器 android.widget.Chronometer
说起做定时器,大家一般会想到Timer和Executors的定时器线程池,其实用这两个做都会有问题,在停止和重新计时时你回发现无法停止或者说计时加快(加快是因为多个线程在记录同一个变量),Androi ...
- Spring+SpringMVC+MyBatis+easyUI整合优化篇(十四)谈谈写博客的原因和项目优化
阶段总结 又到了优化篇的收尾阶段了,这其实是一篇阶段总结性的文章,今天是4月29号,距离第一次发布博客已经两个月零5天,这两个多月的时间,完成了第一个项目ssm-demo的更新,过程中也写了33篇博客 ...
- java文件的读写操作
java文件的读写操作主要是对输入流和输出流的操作,由于流的分类很多,所以概念很容易模糊,基于此,对于流的读写操作做一个小结. 1.根据数据的流向来分: 输出流:是用来写数据的,是由程序(内存)--- ...
- 搭建后台页面布局利用属性target 属性
HTML 5 <form> target 属性 HTML 5 <form> 标签 实例 提交一个在新窗口中打开的表单: <form action="demo_f ...
- ShadowBroker释放的NSA工具中Esteemaudit漏洞复现过程
没有时间测试呢,朋友们都成功复现,放上网盘地址:https://github.com/x0rz/EQGRP 近日臭名昭著的方程式组织工具包再次被公开,TheShadowBrokers在steemit. ...
- Linux Centos 6.5_x86安装Nginx
一.下载 二.编译安装 三.启动.停止.平滑重启 一.下载 地址:http://nginx.org/en/download.html 或者在linux上使用wget命令下载: wget http:// ...
- Zookeeper ZAB 协议分析
前言 ZAB 协议是为分布式协调服务 ZooKeeper 专门设计的一种支持崩溃恢复的原子广播协议.在 ZooKeeper 中,主要依赖 ZAB 协议来实现分布式数据一致性,基于该协议,ZooKeep ...
- 基于本地文件系统的LocalDB
零.前言 之前写一些小工具的时候,需要用到数据存储方面的技术,但是用数据库又觉得太大了,本地文件存储txt文件存储又不是很规范,于是乎想到了去编写一个简单的基于本地文件系统的数据存储库,暂且叫它loc ...
- 在 iOS 10.0 之后, App 要调用手机相机与相簿应注意的事项
iOS 的 SDK 每一年至少都会有一次大改版,从 2009 到 2016 年,版号已经到了第 10 版了,很轻易的就追上了 Mac OSX. 每一次的大改版都会有不少新的功能或新的规范,在 iOS ...
- hdu 1711---KMP
题目链接 Problem Description Given two sequences of numbers : a[1], a[2], ...... , a[N], and b[1], b[2], ...