react native ui框架,【React Native開發】React Native控件之RefreshControl組件具體解釋(21)

 2023-12-06 阅读 25 评论 0

摘要:轉載請標明出處:http://blog.csdn.net/developer_jiangqq/article/details/50672747本文出自:【江清清的博客】(一)前言?????????【好消息】個人站點已經上線執行,后面博客以及技術干貨等精彩文章會同步更新,請大家關注收藏:http://www.lcode.org???????? ? ?

轉載請標明出處:

http://blog.csdn.net/developer_jiangqq/article/details/50672747

本文出自:【江清清的博客】

()前言

?????????【好消息】個人站點已經上線執行,后面博客以及技術干貨等精彩文章會同步更新,請大家關注收藏:http://www.lcode.org???????

? ? ? ?今天我們一起來看一下RefreshControl下拉刷新組件解說以及使用實例

?????????剛創建的React Native技術交流3群(496508742),React Native技術交流4群(458982758),請不要反復加群!歡迎各位大牛,React Native技術愛好者加入交流!同一時候博客左側歡迎微信掃描關注訂閱號,移動技術干貨,精彩文章技術推送!

????????? 該組件和上一篇組將的PullToRefreshAndroidView組件相相似(點擊進入)。也是實現下拉刷新的功能。只是該組件是用在ScrollView的內部的,為ScrollView加入一個下拉刷新的功能。

當ScrollView的垂直方向的偏移量scrollY:0的時候,手指往下拖拽ScrollView就會觸發onRefresh事件方法。

()屬性方法

  1. onRefresh? function方法 當視圖開始刷新的時候調用
  2. refreshing? bool? 決定載入進去指示器是否為活躍狀態,也表名當前是否在刷新中
  3. colors [ColorPropType]?? android平臺適用? 進行設置載入進去指示器的顏色,至少設置一種。最好能夠設置4
  4. enabled? bool?? android平臺適用?? 用來設置下拉刷新功能是否可用
  5. progressBackgroundColor ColorPropType? 設置載入進度指示器的背景顏色
  6. size RefreshLayoutConsts.SIZE.DEFAULT? android平臺適用? 載入進度指示器的尺寸大小 ,詳細能夠查看RefreshControl.SIZE(詳細點擊進入)
  7. tintColor ColorPropType?? iOS平臺適用? 設置載入進度指示器的顏色
  8. title string iOS平臺適用? 設置載入進度指示器以下的標題文本信息

()使用實例

???????? 上面已經對于RefreshControl組件的基本介紹以及相關屬性做了說明,以下來進行實例使用一下。以下代碼在官方實例中進行改動而來,還是比較簡單的。

詳細代碼例如以下:

'use strict';const React =require('react-native');
const {AppRegistry,ScrollView,StyleSheet,RefreshControl,Text,View,
} = React;const styles =StyleSheet.create({row: {borderColor: 'red',borderWidth: 5,padding: 20,backgroundColor: '#3a5795',margin: 5,},text: {alignSelf: 'center',color: '#fff',},scrollview: {flex: 1,},
});const Row =React.createClass({_onClick: function() {this.props.onClick(this.props.data);},render: function() {return (<View style={styles.row}><Text style={styles.text}>{this.props.data.text}</Text></View>);},
});constRefreshControlDemo = React.createClass({getInitialState() {return {isRefreshing: false,loaded: 0,rowData: Array.from(new Array(20)).map((val, i) => ({text:'初始行 ' + i})),};},render() {const rows = this.state.rowData.map((row,ii) => {return <Row key={ii} data={row}/>;});return (<ScrollViewstyle={styles.scrollview}refreshControl={<RefreshControlrefreshing={this.state.isRefreshing}onRefresh={this._onRefresh}colors={['#ff0000', '#00ff00','#0000ff','#3ad564']}progressBackgroundColor="#ffffff"/>}>{rows}</ScrollView>);},_onRefresh() {this.setState({isRefreshing: true});setTimeout(() => {// 準備下拉刷新的5條數據const rowData = 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: rowData,});}, 5000);},
});AppRegistry.registerComponent('RefreshControlDemo',() => RefreshControlDemo);

react native ui框架,

詳細執行效果例如以下:


()最后總結

????????? 今天我們主要學習一下RefreshControl組件的基本介紹和實例演示使用,總體實現的功能還是和之前的PullToRefreshAndroidView一樣的。

大家有問題能夠加一下群React Native技術交流群(282693535)或者底下進行回復一下。?

? ? ? 尊重原創,轉載請注明:From Sky丶清(http://blog.csdn.net/developer_jiangqq) 侵權必究!

? ? ? ?關注我的訂閱號(codedev123),每天分享移動開發技術(Android/IOS),項目管理以及博客文章!(歡迎關注,第一時間推送精彩文章)

? ? ?關注我的微博,能夠獲得很多其它精彩內容

? ? ??

什么是控件。轉載于:https://www.cnblogs.com/wzzkaifa/p/7225908.html

版权声明:本站所有资料均为网友推荐收集整理而来,仅供学习和研究交流使用。

原文链接:https://hbdhgg.com/2/191591.html

发表评论:

本站为非赢利网站,部分文章来源或改编自互联网及其他公众平台,主要目的在于分享信息,版权归原作者所有,内容仅供读者参考,如有侵权请联系我们删除!

Copyright © 2022 匯編語言學習筆記 Inc. 保留所有权利。

底部版权信息