forked from react-native-studio/react-native-MJRefresh
-
Notifications
You must be signed in to change notification settings - Fork 0
/
MJRefresh.js
84 lines (83 loc) · 2.51 KB
/
MJRefresh.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
import React, {Component} from 'react';
import {
StyleSheet,
View,
Text,
requireNativeComponent,
ViewPropTypes as RNViewPropTypes,
findNodeHandle,
UIManager,
Platform,
} from 'react-native';
import PropTypes from 'prop-types'
import MJScrollView from './MJScrollView'
import MJListView from './MJListView'
import MJFlatlist from './MJFlatList'
const ViewPropTypes = RNViewPropTypes || View.propTypes;
const UnimplementedView = require('react-native/Libraries/Components/UnimplementedViews/UnimplementedView')
//Android平台未实现RCTMJRefreshView
const RCTMJRefreshView = Platform.OS === 'ios' ? requireNativeComponent('RCTMJRefreshView', MJRefresh) : UnimplementedView;
class MJRefresh extends Component {
_onMJRefresh=()=>{
let {onRefresh} = this.props;
onRefresh && onRefresh();
}
_onMJPulling=(e)=>{
let {onPulling} = this.props;
onPulling && onPulling(e);
}
_onMJReleaseToRefresh=()=>{
let {onReleaseToRefresh} = this.props;
onReleaseToRefresh && onReleaseToRefresh();
}
_onMJRefreshIdle=()=>{
let {onRefreshIdle} = this.props;
onRefreshIdle && onRefreshIdle();
}
finishRefresh=()=>{
this.dispatchCommand('finishRefresh');
}
beginRefresh=()=>{
this.dispatchCommand('beginRefresh')
}
dispatchCommand (commandName, params) {
UIManager.dispatchViewManagerCommand(this.findNode(), UIManager.RCTMJRefreshView.Commands[commandName], params)
}
findNode=()=>{
return findNodeHandle(this.refs.refreshView);
}
render() {
let {style} = this.props;
return (
<RCTMJRefreshView
ref='refreshView'
{...this.props}
onMJRefresh={this._onMJRefresh}
onMJRefreshIdle={this._onMJRefreshIdle}
onMJReleaseToRefresh={this._onMJReleaseToRefresh}
onMJPulling={this._onMJPulling}
style={[
{
backgroundColor:'transparent'
},
style,
{
position:'absolute',
left:0,
right:0,
}
]}
/>)
}
}
MJRefresh.propTypes={
onRefresh:PropTypes.func,
onRefreshIdle:PropTypes.func,
onReleaseToRefresh:PropTypes.func,
onPulling:PropTypes.func,
...ViewPropTypes
}
export const ScrollView = MJScrollView;
export const ListView = MJListView;
export const FlatList = MJFlatlist;
export default MJRefresh;