-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathPullToRefreshScrollView.ios.js
More file actions
executable file
·96 lines (92 loc) · 3.67 KB
/
PullToRefreshScrollView.ios.js
File metadata and controls
executable file
·96 lines (92 loc) · 3.67 KB
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
'use strict'
import React, { Component} from 'react'
import {DeviceEventEmitter, NativeModules, findNodeHandle, ScrollView, processColor} from 'react-native'
const {DWRefreshManager} = NativeModules
const REF_PTR = "ptr_ref"
const DROP_VIEW_DID_BEGIN_REFRESHING_EVENT = 'dropViewDidBeginRefreshing'
let callbacks = {}
export default class PullToRefreshScrollView extends Component {
static defaultProps = {
type: '1', // 刷新指示器的样式0、1
incremental:80,//刷新动画高度,type=0时建议高度小于60
activityIndicatorViewColor: '#A9A9A9',
refreshing:false,
tintColor:"#05A5D1",//仅用于type = 0
//以下仅用于type = 1
durationToCloseHeader: 500,//刷新完成延迟收起
refreshableTitlePull: '下拉刷新',
refreshableTitleRefreshing: '加载中...',
refreshableTitleRelease: '松手开始刷新',
refreshableTitleComplete: '刷新完成',
isShowLastTime: true,
titleColor:"#696969",
timeColor:"#A9A9A9",
titleWidth:90,//固定title的宽度,默认是自动计算宽度
titleHiddenType:0,//titlelabel显示类型,0,默认类型,显示,1,不显示,2,刷新完成时不显示,3,下拉过程不显示,完成时显示
isShowCompleteImage: true,//是否显示刷新完成的图标
}
constructor (props) {
super(props)
this._onRefresh = this._onRefresh.bind(this)
this.subscription = DeviceEventEmitter.addListener(
DROP_VIEW_DID_BEGIN_REFRESHING_EVENT,
(reactTag) => {
callbacks[reactTag]()
setTimeout(()=>{
this.onRefreshEnd();
},2000)
})
}
componentDidMount () {
}
componentWillUnmount() {
this.subscription && this.subscription.remove()
}
componentWillReceiveProps(nextProps) {
if(nextProps.refreshing === false && nextProps.refreshing !== this.props.refreshing){
this.onRefreshEnd()
}
}
_onRefresh() {
if (!this.props.onRefresh) {
return
}
this.props.onRefresh()
}
// 刷新完成
onRefreshEnd () {
let nodeHandle = findNodeHandle(this.refs[REF_PTR])
DWRefreshManager.endRefreshing(nodeHandle)
}
render () {
return (
<ScrollView onLayout={(e)=>{
var options = {
type:this.props.type,
incremental:this.props.incremental,
activityIndicatorViewColor: processColor(this.props.activityIndicatorViewColor),
strTitlePull:this.props.refreshableTitlePull,
strTitleRelease:this.props.refreshableTitleRelease,
strTitleRefreshing:this.props.refreshableTitleRefreshing,
strTitleComplete:this.props.refreshableTitleComplete,
durationToCloseHeader:this.props.durationToCloseHeader,
isShowLastTime:this.props.isShowLastTime,
titleColor:processColor(this.props.titleColor),
timeColor:processColor(this.props.timeColor),
tintColor: processColor(this.props.tintColor),
titleWidth:this.props.titleWidth,
titleHiddenType:this.props.titleHiddenType,
isShowCompleteImage:this.props.isShowCompleteImage
}
let nodeHandle = findNodeHandle(this.refs[REF_PTR])
DWRefreshManager.configure(nodeHandle, options, (error) => {
if (!error) {
callbacks[nodeHandle] = this._onRefresh
}
})
}} ref={REF_PTR}>
{this.props.children}
</ScrollView>
);
}
}