'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 使用案例的更多相关文章

  1. reactnative(2) - Navigator 使用案例

    'use strict'; import React, { Component } from 'react'; import { AppRegistry, ScrollView, StyleSheet ...

  2. echars配置案例-reactnative

    option = { backgroundColor:'#fff', grid: { left: '3%', right: '4%', top:, bottom: '6%', containLabel ...

  3. React-Native 之 ScrollView介绍和使用

    前言 学习本系列内容需要具备一定 HTML 开发基础,没有基础的朋友可以先转至 HTML快速入门(一) 学习 本人接触 React Native 时间并不是特别长,所以对其中的内容和性质了解可能会有所 ...

  4. ReactNative 根据scrollView/listview滑动距离动态修改NavBar颜色

    我们常见某些APP上滑的时候,NavBar颜色会从透明渐变为某种颜色 原理非常简单,根据scrollView的回调动态修改NavBar的透明度即可. 在RN中,尤其是ListView中这个回调不是很好 ...

  5. ReactNative官方中文文档0.21

    整理了一份ReactNative0.21中文文档,提供给需要的reactnative爱好者.ReactNative0.21中文文档.chm  百度盘下载:ReactNative0.21中文文档 来源: ...

  6. React-Native的基本控件属性方法

    对React-Native的学习,从熟悉基本控件开始. View 属性方法 序号 名称 属性Or方法 类型 说明 1 accessibilityLabel 属性 string   2 accessib ...

  7. React-Native 之 项目实战(四)

    前言 本文有配套视频,可以酌情观看. 文中内容因各人理解不同,可能会有所偏差,欢迎朋友们联系我. 文中所有内容仅供学习交流之用,不可用于商业用途,如因此引起的相关法律法规责任,与我无关. 如文中内容对 ...

  8. 史上最易懂——ReactNative分组列表SectionList使用详情及示例详解

    React Native系列 <逻辑性最强的React Native环境搭建与调试> <ReactNative开发工具有这一篇足矣> <解决React Native un ...

  9. react-native导航器 react navigation 介绍

    开发环境搭建好之后,想要进一步了解react-native,可以先从react-native官网上的电影列表案例入手: https://reactnative.cn/docs/0.51/sample- ...

随机推荐

  1. 【16】AngularJS API

    AngularJS API API 意为 Application Programming Interface(应用程序编程接口). AngularJS 全局 API AngularJS 全局 API ...

  2. spring boot & JsonParser

    spring boot https://stackoverflow.com/questions/29313687/trying-to-use-spring-boot-rest-to-read-json ...

  3. Codeforces 158B (数学)

    B. Mushroom Scientists time limit per test 2 seconds memory limit per test 256 megabytes input stand ...

  4. C++标准库:bitset 用法整理&&zoj 3812

    转载: http://happyboy200032.blog.163.com/blog/static/46903113201291252033712/ 头文件:#include <bits/st ...

  5. codevs 1296 营业额统计 (splay 点操作)

    题目大意 每次加入一个值,并且询问之前加入的数中与该数相差最小的值. 答案输出所有相差值的总和. 解题分析 = = 参考程序 #include <bits/stdc++.h> using ...

  6. Bellman_ford 算法 Currency Exchange POJ1860

    Bellman_ford算法用于寻找正环或者负环! 算法导论: 24.1 The Bellman-Ford algorithm The Bellman-Ford algorithm solves th ...

  7. 最小生成树 C - Building a Space Station

    You are a member of the space station engineering team, and are assigned a task in the construction ...

  8. bzoj1072【SCOI2007】排列perm

    1072: [SCOI2007]排列perm Time Limit: 10 Sec  Memory Limit: 162 MB Submit: 1479  Solved: 928 [id=1072&q ...

  9. Open Flash Chart图表的JSON格式基本属性详解

    http://blog.csdn.net/wangwenhui11/article/details/4283571 数据文件必须是JSON格式.JSON对象的基本格式: {} 把所有对象都编写在{}里 ...

  10. What are Unix swap (.swp) files?

    原文: http://www.networkworld.com/article/2931534/it-management/what-are-unix-swap-swp-files.html ---- ...