最近心血来潮开始学习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 仿天猫物流跟踪时间轴的更多相关文章

  1. [RN] React Native 仿美团下拉筛选菜单控件

    React Native 仿美团下拉筛选菜单控件 演示效果如下: 使用方法如下: 1.安装 npm install react-native-dropdownmenus --save react-na ...

  2. React Native仿京东客户端实现(首页 分类 发现 购物车 我的)五个Tab导航页面

    1.首先创建  这几个文件 myths-Mac:JdApp myth$ yarn add react-native-tab-navigator 2.各个文件完整代码 1)CartPage.js imp ...

  3. 带你从零学ReactNative开发跨平台App开发-[react native 仿boss直聘](十三)

    ReactNative跨平台开发系列教程: 带你从零学ReactNative开发跨平台App开发(一) 带你从零学ReactNative开发跨平台App开发(二) 带你从零学ReactNative开发 ...

  4. react native仿微信性别选择-自定义弹出框

    简述 要实现微信性别选择需要使用两部分的技术: 第一.是自定义弹出框: 第二.单选框控件使用: 效果 实现 一.配置弹出框 弹出框用的是:react-native-popup-dialog(Git地址 ...

  5. React Native专题-江清清

    本React Native讲解专题:主要讲解了React Native开发,由基础环境搭建配置入门,基础,进阶相关讲解. 刚创建的React Native交流8群:533435865  欢迎各位大牛, ...

  6. React Native 常用插件案例

    (二).基础入门: 1.React Native For Android环境配置以及第一个实例 2.React Native开发IDE安装及配置 3.React Native应用设备运行(Runnin ...

  7. React Native专题

    转载注明出处:地址:http://www.lcode.org本文出自:[江清清的技术专栏]本React Native讲解专题:主要讲解了React Native开发,由基础环境搭建配置入门,基础,进阶 ...

  8. React Native 二维码扫描组件

    学rn得朋友们,你们知道rn开源项目吗?来吧看这里:http://www.marno.cn/(rn开源项目) React Native学习之路(9) - 注册登录验证的实现 + (用Fetch实现po ...

  9. react-native —— 在Windows下搭建React Native Android开发环境

    在Windows下搭建React Native Android开发环境 前段时间在开发者头条收藏了 @天地之灵_邓鋆 分享的<在Windows下搭建React Native Android开发环 ...

随机推荐

  1. Collection的迭代器Iterator

    Collection -- 迭代的方法 toArray() iterator() 迭代器的作用:抓取集合中的元素 迭代器的方法有  hasNext()  next() remove() public ...

  2. cgroup原理简析:vfs文件系统

    要了解cgroup实现原理,必须先了解下vfs(虚拟文件系统).因为cgroup通过vfs向用户层提供接口,用户层通过挂载,创建目录,读写文件的方式与cgroup交互.因为是介绍cgroup的文章,因 ...

  3. Jdk1.6 JUC源码解析(12)-ArrayBlockingQueue

    功能简介: ArrayBlockingQueue是一种基于数组实现的有界的阻塞队列.队列中的元素遵循先入先出(FIFO)的规则.新元素插入到队列的尾部,从队列头部取出元素. 和普通队列有所不同,该队列 ...

  4. CI 图片上传路径问题的解决

    很久没有用CI了,新公司需要用ci ,图片上传的功能,我都搞半天,伤心 1. 要看源码,upload.php里do_upload()是上传的主要函数. public function do_uploa ...

  5. Charles Proxy代理使用简要说明

    1.去官网下载免费试用版: http://www.charlesproxy.com/ (需要机器有Java运行时)或下载破解注册版:http://charles.iiilab.com/,安装后开启默认 ...

  6. 【JAVAWEB学习笔记】16_session&cookie

    会话技术Cookie&Session 学习目标 案例一.记录用户的上次访问时间---cookie 案例二.实现验证码的校验----session 一.会话技术简介 1.存储客户端的状态 由一个 ...

  7. POJ2524并查集水题

    Description There are so many different religions in the world today that it is difficult to keep tr ...

  8. 【JAVAWEB学习笔记】27_Redis:在Linux上的安装、Jedis和常用命令

    一.Redis简介 1.关于关系型数据库和nosql数据库 关系型数据库是基于关系表的数据库,最终会将数据持久化到磁盘上,而nosql数据     库是基于特殊的结构,并将数据存储到内存的数据库.从性 ...

  9. 关于bootstrap table 的可编辑列表的实例

    最近被安排到一个新的项目里,首先被分配了一个成果管理的模块,虽然是简单的增删改查,但是也费了不少功夫. 其中耽误最长的时间就是form中嵌套了两个可编辑列表的子表.废话不说上干货 = = 参考资料 1 ...

  10. 在JBoss AS7中进行项目部署

    http://developer.51cto.com/art/201111/305178.htm