-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathPullToRefreshScrollView.android.js
executable file
·104 lines (97 loc) · 3.36 KB
/
PullToRefreshScrollView.android.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
/**
* Created by dowin on 2017/11/28.
*/
'use strict'
import React, {Component} from 'react'
import {requireNativeComponent, ScrollView, View} from 'react-native'
import PropTypes from 'prop-types'
const UIManager = require('react-native/lib/UIManager')
const ReactNative = require('react-native')
const REF_PTR = "ptr_ref"
export default class PullToRefreshScrollView extends Component {
static defaultProps = {
durationToCloseHeader: 300,//关闭延时
durationToClose: 200,//向上关闭的时间
resistance: 2,
pinContent: false,
ratioOfHeaderHeightToRefresh: 1.2,
pullToRefresh: false,
keepHeaderWhenRefresh: true,
refreshing: false,//设置false结束否刷新
refreshableTitlePull: '下拉刷新',
refreshableTitleRefreshing: '加载中...',
refreshableTitleRelease: '松手开始刷新',
refreshableTitleComplete: '刷新完成.',
dateTitle: '最后更新时间: ',
titleColor:"#666666",//刷新文字颜色
lastUpdateColor:"#999999",//更新时间文字颜色
progressDrawable:"rotate_d",//刷新时动画drawable名字
arrowDrawable: 'ptr_rotate_arrow'//箭头图片drawable名字
}
constructor (props) {
super(props)
this._onRefresh = this._onRefresh.bind(this)
}
componentWillReceiveProps (nextProps) {
if (nextProps.refreshing === false && nextProps.refreshing !== this.props.refreshing) {
this.onRefreshEnd()
}
}
_onRefresh () {
if (!this.props.onRefresh) {
return
}
this.props.onRefresh()
}
autoRefresh () {
let self = this
UIManager.dispatchViewManagerCommand(
ReactNative.findNodeHandle(self.refs[REF_PTR]),
1,
null
)
}
onRefreshEnd () {
UIManager.dispatchViewManagerCommand(
ReactNative.findNodeHandle(this.refs[REF_PTR]),
0,
null
)
}
render () {
// onPtrRefresh 事件对应原生的ptrRefresh事件
return (
<RCTPtrAndroid
ref={REF_PTR}
{...this.props}
style={{flex:1}}
onPtrRefresh={() => this._onRefresh()}>
<ScrollView>
{this.props.children}
</ScrollView>
</RCTPtrAndroid>
)
}
}
// PullToRefreshScrollView.name = "RCTPtrAndroid"; // 便于调试时显示(可以设置为任意字符串)
PullToRefreshScrollView.propTypes = {
onPtrRefresh: PropTypes.func,
resistance: PropTypes.number,
durationToCloseHeader: PropTypes.number,
durationToClose: PropTypes.number,
ratioOfHeaderHeightToRefresh: PropTypes.number,
pullToRefresh: PropTypes.bool,
keepHeaderWhenRefresh: PropTypes.bool,
pinContent: PropTypes.bool,
refreshableTitlePull: PropTypes.string,
refreshableTitleRefreshing: PropTypes.string,
refreshableTitleRelease: PropTypes.string,
refreshableTitleComplete: PropTypes.string,
dateTitle: PropTypes.string,
titleColor: PropTypes.string,
lastUpdateColor: PropTypes.string,
progressDrawable: PropTypes.string,
arrowDrawable: PropTypes.string,
...View.propTypes,
};
const RCTPtrAndroid = requireNativeComponent('RCTPtrAndroid', PullToRefreshScrollView, {nativeOnly: {onPtrRefresh: true}});