ReactNative-ListView
来源:互联网 发布:程序员人资面试题 编辑:程序博客网 时间:2024/06/12 23:00
这只是一个简单的listView的小demo
欢迎访问我的个人博客
初始化项目之后,index.ios.js代码如下
/** * Sample React Native App * https://github.com/facebook/react-native * @flow */import React, { Component } from 'react';import { AppRegistry, StyleSheet, Text, View, ListView} from 'react-native';import Request from './test/Request';import TestCell from './test/TestCell'const Dimensions = require('Dimensions');const {width, height, scale} = Dimensions.get('window');export default class DemoApp extends Component { constructor(props){ super(props); var ds = new ListView.DataSource({ rowHasChanged:(r1, r2) => r1 !== r2 }); this.state = { dataArr: new Array, dataSource: ds }; } render() { return ( <View style={styles.container}> <ListView dataSource={this.state.dataSource} renderRow={(rowData) => this._renderRow(rowData)} contentInset={{top: 44}} > </ListView> </View> ); } _renderRow(rowData){ return( <TestCell wine={rowData}></TestCell> ) }; componentDidMount() { var url_api = 'http://wifi.3wchina.net/index.php/mobile/mobile/appapi'; Request.get(url_api, (responseData)=>{ // 取出所有的数据 var data = responseData; this.setState({ dataArr: data, dataSource: this.state.dataSource.cloneWithRows(data) }); }, (error)=>{ alert(error); }); }}const styles = StyleSheet.create({ container: { flex:1, backgroundColor: '#e8e8e8' },});AppRegistry.registerComponent('DemoApp', () => DemoApp);
封装简单的get请求
module.exports = { /** * 基于fetch的get方法 * @method get * @param {string} url * @param {function} callback 请求成功回调 */ get: function(url, successCallback, failCallback){ fetch(url) .then((response) => response.json()) .then((responseText) => { successCallback(responseText); }) .catch(function(err){ failCallback(err); }); }};
cell代码如下
import React, { Component, PropTypes } from 'react';import { AppRegistry, StyleSheet, Text, View, TouchableOpacity, Image, ScrollView, InteractionManager, DeviceEventEmitter} from 'react-native';var Dimensions = require('Dimensions');var {width, height} = Dimensions.get('window');class TestCell extends Component{ // 构造 constructor(props){ super(props); this.state = { wine:this.props.wine }; } render(){ var wine = this.state.wine; return( <TouchableOpacity style={styles.viewStyle}> <TouchableOpacity style={styles.leftView}> <View style={{width:width * 0.7}}> <Text style={styles.titleStyle} numberOfLines={1} > {wine.title} </Text> </View> </TouchableOpacity> </TouchableOpacity> ) }}const styles = StyleSheet.create({ viewStyle:{ flexDirection: 'row', backgroundColor: '#fff', borderBottomWidth:1, borderBottomColor: '#ccc' }, leftView:{ width: width * 0.7, height:44, flexDirection:'row', overflow:'hidden', alignItems:'center' }});module.exports = TestCell;
运行效果如下:
阅读全文
0 0
- ReactNative-ListView
- ReactNative的ListView简述
- ReactNative列表ListView
- ReactNative ListView基础功能
- ReactNative ListView 组件
- ReactNative之ListView
- ReactNative的分组ListView-----SectionList
- ReactNative实现ListView分组,悬浮效果
- ReactNative中ListView的实现效果
- ReactNative 中 ListView实现GridView效果
- ReactNative ListView改变数据源,列表不刷新
- ReactNative入门之ListView使用透析
- reactnative 解决listview无法滚动的问题
- ReactNative ListView + 上拉加载更多
- 《ReactNative》之ListView上拉下拉刷新
- ReactNative Listview 中加载图片 OOM
- ReactNative学习第七天 项目fetch+ListView
- ReactNative之ListView学习总结(四)listview 属性
- Mindis HDU
- Delegation Token
- Notepad++使用scala语言高亮显示或语法作色
- 深度学习实践笔记2——分析BP
- smartctl命令详解
- ReactNative-ListView
- 语音传输 音频采集
- 实战:战狼2票房数据分析——(3)数据读取及分析
- HDU.2795 Billboard
- Common Subsequence (dp)
- WebView缩放后左边内容被遮盖的问题
- 互斥量和条件变量解决读者-写者问题
- mcp2515带spi的can驱动移植总结
- 1013. 数素数 (20)