-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathscrollable.js
45 lines (35 loc) · 1.06 KB
/
scrollable.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
'use strict';
let React = require('react-native');
function scrollable(DecoratedComponent) {
return class extends React.Component {
static displayName = `Scrollable(${getDisplayName(DecoratedComponent)})`;
static DecoratedComponent = DecoratedComponent;
setNativeProps(nativeProps) {
this._root.setNativeProps(nativeProps);
}
getScrollResponder() {
return this._root.getScrollResponder();
}
getInnerViewNode() {
return this.getScrollResponder().getInnerViewNode();
}
scrollTo(destY?: number, destX?: number) {
this.getScrollResponder().scrollTo(destY, destX);
}
scrollWithoutAnimationTo(destY?: number, destX?: number) {
this.getScrollResponder().scrollWithoutAnimationTo(destY, destX);
}
render() {
return (
<DecoratedComponent
{...this.props}
ref={component => { this._root = component; }}
/>
);
}
}
}
function getDisplayName(Component) {
return Component.displayName || Component.name || 'Component';
}
module.exports = scrollable;