-
Notifications
You must be signed in to change notification settings - Fork 805
/
Copy pathSwipeRereshLayout.js
92 lines (77 loc) · 2.08 KB
/
SwipeRereshLayout.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
'use strict';
var React = require('react-native');
var {
requireNativeComponent,
PropTypes,
StyleSheet,
View,
} = React;
var createReactNativeComponentClass = require('createReactNativeComponentClass');
var ReactNativeViewAttributes = require('ReactNativeViewAttributes');
var RCTUIManager = require('NativeModules').UIManager;
var NativeMethodsMixin = require('NativeMethodsMixin');
var RK_SWIPE_REF = 'swiperefreshlayout';
var INNERVIEW_REF = 'innerView';
var SwipeRefreshLayoutAndroid = React.createClass({
propTypes: {
onRefresh: PropTypes.func,
},
mixins: [NativeMethodsMixin],
getInnerViewNode: function() {
return this.refs[INNERVIEW_REF].getInnerViewNode();
},
render: function() {
var childrenWrapper =
<View ref={INNERVIEW_REF} style={styles.mainSubview} collapsable={false}>
{this.props.children}
</View>;
return (
<AndroidSwipeRefreshLayout
{...this.props}
ref={RK_SWIPE_REF}
style={styles.base}
onRefresh={this._onRefresh}>
{childrenWrapper}
</AndroidSwipeRefreshLayout>
);
},
_onRefresh: function() {
if (this.props.onRefresh) {
this.props.onRefresh();
}
},
startRefresh: function() {
RCTUIManager.dispatchViewManagerCommand(
this._getSwipeRefreshLayoutHandle(),
RCTUIManager.AndroidSwipeRefreshLayout.Commands.startRefresh,
null
);
},
finishRefresh: function() {
RCTUIManager.dispatchViewManagerCommand(
this._getSwipeRefreshLayoutHandle(),
RCTUIManager.AndroidSwipeRefreshLayout.Commands.finishRefresh,
null
);
},
_getSwipeRefreshLayoutHandle: function() {
return React.findNodeHandle(this.refs[RK_SWIPE_REF]);
},
});
var styles = StyleSheet.create({
base: {
flex: 1,
},
mainSubview: {
position: 'absolute',
top: 0,
left: 0,
right: 0,
bottom: 0,
},
});
var AndroidSwipeRefreshLayout = createReactNativeComponentClass({
validAttributes: ReactNativeViewAttributes.UIView,
uiViewClassName: 'AndroidSwipeRefreshLayout',
});
module.exports = SwipeRefreshLayoutAndroid;