react-native-gifted-listview(一)
来源:互联网 发布:天球仪软件 编辑:程序博客网 时间:2024/06/08 14:48
for
use gifted-listview 显示列表
step
- list.js
/* use react-native-gifted-listview for ijoy list show*/import React,{Component} from 'react';import { View, Text, ListView, StyleSheet, Dimensions, TouchableHighlight} from 'react-native';import DataRepository from './DataRepository';import GiftedListView from 'react-native-gifted-listview';const repository=new DataRepository();const height=Dimensions.get("window").height;const toobarHeight=59;const sectionHeight=height-toobarHeight;export default class List extends Component{ constructor(){ super(); const ds=new ListView.DataSource({rowHasChanged:(r1,r2)=>r1!==r2}); this.state={ DS:ds.cloneWithRows([]), loaded:false, dataArray:[] } } fetchHospital(){ repository.fetchHospital() .then((dataArray)=>{ console.log(dataArray); this.setState({ DS:this.state.DS.cloneWithRows(dataArray), loaded:true, dataArray:dataArray }) }) .catch((error)=>{ console.error(error); }) .done();} componentDidMount(){ const tt=this.fetchHospital(); console.log('----------------'); console.log(tt); } _onFetch=(page = 1, callback, options)=> { setTimeout(() => { var rows =this.state.dataArray; if (page === 3) { callback(rows, { allLoaded: true, // the end of the list is reached }); } else { callback(rows); } }, 1000); // simulating network fetching } _renderRowView=(rowData)=> { return ( <TouchableHighlight style={styles.row} underlayColor='#c8c7cc' > <Text>{rowData.name}</Text> </TouchableHighlight> ); } render(){ if(this.state.loaded===false)return (<View><Text>正在加载</Text></View>) return( <View style={styles.container}> <View style={styles.navBar} /> <GiftedListView rowView={this._renderRowView} onFetch={this._onFetch} firstLoader={true} // display a loader for the first fetching pagination={true} // enable infinite scrolling using touch to load more refreshable={true} // enable pull-to-refresh for iOS and touch-to-refresh for Android withSections={false} // enable sections enableEmptySections={true} customStyles={{ paginationView: { backgroundColor: '#eee', }, }} refreshableTintColor="blue" /> </View> ); }}const styles=StyleSheet.create({ container: { flex: 1, backgroundColor: '#FFF', }, navBar: { height: 64, backgroundColor: '#CCC' }, row: { padding: 10, height: 44, }})
- DataRepository.js
'use strict';const API_HOSPITAL_LIST="http://www.tngou.net/api/hospital/list";function DataRepository() { // Singleton pattern if (typeof DataRepository.instance === 'object') { return DataRepository.instance; } DataRepository.instance = this;}DataRepository.prototype.fetchHospital=function(callback?:?(error:?Error,result:?Object)=>void){ const reqUrl=API_HOSPITAL_LIST; const networking=this._safeFetch(reqUrl); const merged=new Promise((resolve,reject)=>{ Promise.all([networking]) .then((values)=>{ console.log('-------------resulte---------------'); console.log(values); resolve(values[0]); }) }); return merged;}DataRepository.prototype._safeFetch=function(reqUrl:string){ console.log(reqUrl); return new Promise((resolve,reject)=>{ fetch(reqUrl) .then((response)=>response.json()) .then((responseData)=>{ console.log(responseData); let result=[]; result=responseData.tngou; resolve(result); }) .catch((error)=>{ console.error(error); resolve(null); }) } );}module.exports=DataRepository;
last update 2016-08-31
0 1
- react-native-gifted-listview(一)
- React-native 常见问题:Warning 当使用组件 react-native-gifted-listview
- react-native listView 分节
- React-Native 中的ListView
- React-native listview换行
- react-native 水平ListView
- React-Native ListView学习
- React-Native ListView
- React native ListView初识
- React-Native 之ListView
- react-native listview使用
- React Native 组件 ListView
- 初识react-native ListView
- React Native (一) --React 入门
- React-native ListView不滚动
- react-native listview remove item
- React-Native ListView简单使用
- React Native控件之Listview
- 堆栈
- 39. Combination Sum
- PHP常用的三种设计模式学习总结
- sed 和 grep 命令修改当前目录下所有文件
- Java运算符>、>>、>>>
- react-native-gifted-listview(一)
- Android事件分发
- 重启nginx载入配置
- Unity脚本的生命周期
- redis浅谈教你使用redis(一)
- 面试中如何剔除“鱼目混珠”程序员?
- 查找透明图片
- Spark的日志配置
- PullToRrefresh自定义下拉刷新动画