reactnative(1) - RefreshControl 使用案例
'use strict';
import React, { Component } from 'react';
import {
AppRegistry,
ScrollView,
StyleSheet,
Text,
View,
RefreshControl,
} from 'react-native'; class ListRowComponent extends React.Component{
render(){
return (
<View style={styles.row}>
<Text style={styles.text}>
{this.props.data.text}
</Text>
</View>
);
}
};
class MyProject extends Component {
constructor(props) {
super(props);
this.state = {
isRefreshing: false,
loaded: 0,
rowData: Array.from(new Array(10)).map(
(val, i) => ({text: '初次加载的数据行 ' + i})),
};
} render() {
var rows = this.state.rowData.map((row, indexKey) => {
return <ListRowComponent key={indexKey} data={row}/>;
});
return (
<ScrollView style={styles.scrollview} refreshControl={
<RefreshControl
refreshing={this.state.isRefreshing}
onRefresh={this.onRefresh.bind(this)} //(()=>this.onRefresh)或者通过bind来绑定this引用来调用方法
tintColor='red'
title= {this.state.isRefreshing? '刷新中....':'下拉刷新'}
/>
}>
{rows}
</ScrollView>
);
}
onRefresh() {
this.setState({isRefreshing: true});
setTimeout(() => {
// 准备下拉刷新的5条数据
var rowNewData = Array.from(new Array(5))
.map((val, i) => ({
text: '下拉刷新增加的数据行 ' + (+this.state.loaded + i)
}))
.concat(this.state.rowData);
this.setState({
loaded: this.state.loaded + 5,
isRefreshing: false,
rowData: rowNewData,
});
}, 2000);
} } const styles = StyleSheet.create({
row: {
borderColor:'green',
borderWidth:5,
padding:20,
backgroundColor:'#3a5795',
margin:5,
},
text:{
alignSelf:'center',
color:'white',
},
scrollerview:{
flex:1,
}
}); AppRegistry.registerComponent('MyProject', () => MyProject);
效果演示图:
参考案例
http://www.lcode.org/%E3%80%90react-native%E5%BC%80%E5%8F%91%E3%80%91react-native%E6%8E%A7%E4%BB%B6%E4%B9%8Brefreshcontrol%E7%BB%84%E4%BB%B6%E8%AF%A6%E8%A7%A321/
reactnative(1) - RefreshControl 使用案例的更多相关文章
- reactnative(2) - Navigator 使用案例
'use strict'; import React, { Component } from 'react'; import { AppRegistry, ScrollView, StyleSheet ...
- echars配置案例-reactnative
option = { backgroundColor:'#fff', grid: { left: '3%', right: '4%', top:, bottom: '6%', containLabel ...
- React-Native 之 ScrollView介绍和使用
前言 学习本系列内容需要具备一定 HTML 开发基础,没有基础的朋友可以先转至 HTML快速入门(一) 学习 本人接触 React Native 时间并不是特别长,所以对其中的内容和性质了解可能会有所 ...
- ReactNative 根据scrollView/listview滑动距离动态修改NavBar颜色
我们常见某些APP上滑的时候,NavBar颜色会从透明渐变为某种颜色 原理非常简单,根据scrollView的回调动态修改NavBar的透明度即可. 在RN中,尤其是ListView中这个回调不是很好 ...
- ReactNative官方中文文档0.21
整理了一份ReactNative0.21中文文档,提供给需要的reactnative爱好者.ReactNative0.21中文文档.chm 百度盘下载:ReactNative0.21中文文档 来源: ...
- React-Native的基本控件属性方法
对React-Native的学习,从熟悉基本控件开始. View 属性方法 序号 名称 属性Or方法 类型 说明 1 accessibilityLabel 属性 string 2 accessib ...
- React-Native 之 项目实战(四)
前言 本文有配套视频,可以酌情观看. 文中内容因各人理解不同,可能会有所偏差,欢迎朋友们联系我. 文中所有内容仅供学习交流之用,不可用于商业用途,如因此引起的相关法律法规责任,与我无关. 如文中内容对 ...
- 史上最易懂——ReactNative分组列表SectionList使用详情及示例详解
React Native系列 <逻辑性最强的React Native环境搭建与调试> <ReactNative开发工具有这一篇足矣> <解决React Native un ...
- react-native导航器 react navigation 介绍
开发环境搭建好之后,想要进一步了解react-native,可以先从react-native官网上的电影列表案例入手: https://reactnative.cn/docs/0.51/sample- ...
随机推荐
- 洛谷—— P1657 选书
https://www.luogu.org/problem/show?pid=1657 题目描述 学校放寒假时,信息学奥赛辅导老师有1,2,3……x本书,要分给参加培训的x个人,每人只能选一本书,但是 ...
- [BZOJ1045][HAOI2008]糖果传递(数学分析)
题目:http://www.lydsy.com:808/JudgeOnline/problem.php?id=1045 分析:均分纸牌的环状版本. 先看线性的版本: 设f[i]表示第I位从第i+1位得 ...
- js禁止滚动条滚动,并且滚动条不消失,页面大小不变
//禁止滚动条滚动 function unScroll() { var top = $(document).scrollTop(); $(document).on('scroll.unable',fu ...
- Android: 帮助找出内存泄漏的工具
1. Intellij Idea的Memory Monitor 通过Memory Monitor,我们可以知道哪个页面哪些操作会占用比较多的内存.如果需要更详细的信息,可以导出heap,通过MAT来分 ...
- V Server Ubuntu
Ubuntu下代理伺服器通常使用squid 安裝 sudo apt-get install squid 修改squid.conf配置 sudo vim /etc/squid/squid.conf 公司 ...
- MyBatis參数格式化异常解决方式:MyBatisSystemException:
MyBatis參数格式化异常解决方式:MyBatisSystemException: 问题:今天使用MyBatis开发查询功能时,前台传入查询条件明明是String类型,到后台就报错,提示格式化数值错 ...
- Hibernate插入错误:GenericJDBCException: could not insert:
数据库中一般不能建立user(表名为User)表,将User类改名,又一次建立映射,问题就能够解决 当然,还有还有一种情况.就是类中id类型错误.要设置为Integer型才干够设置自己主动增长,否则也 ...
- 并发与并行(concurrency vs parallesim)
最近对计算机中并发(concurrency)和并行(parallesim)这两个词的区别很迷惑,将搜索到的相关内容整理如下. http://www.vaikan.com/docs/Concurrenc ...
- AD、DNS、DHCP、IIS、WINS的形象定义及关系
AD-实际是就是一个包括所有信息的数据库,和现实生活中就将其比作派出所,所有的信息都要进入他那的数据库当中(包括人员姓名(计算机名.账号.密码等) DNS就是建立起关联起好记忆的名称,比如你家的位置用 ...
- tflearn alexnet iter 10
他会自己下载数据: # -*- coding: utf-8 -*- """ AlexNet. Applying 'Alexnet' to Oxford's 17 Cate ...