mirror of
https://github.com/expo/react-native-scrollable-decorator.git
synced 2026-11-22 22:38:53 -10:00
46 lines
1.1 KiB
JavaScript
46 lines
1.1 KiB
JavaScript
'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;
|