Merge pull request #8 from ikhilko/master

Expose underlaying ScrollView methods to NavigationAwareScrollable
This commit is contained in:
Brent Vatne
2018-12-03 16:01:29 -08:00
parent c02f1e978c
commit 3e4af09528

View File

@@ -3,14 +3,17 @@ import hoistStatics from 'hoist-non-react-statics';
import { withNavigation } from '@react-navigation/core';
export default function createNavigationAwareScrollable(Component: any) {
class ComponentWithNavigationScrolling extends React.PureComponent<any> {
static displayName = `NavigationAwareScrollable(${Component.displayName ||
const ComponentWithNavigationScrolling = withNavigation(
class extends React.PureComponent<any> {
static displayName = `withNavigationScrollable(${Component.displayName ||
Component.name})`;
_subscription: any;
componentDidMount() {
this._subscription = this.props.navigation.addListener('refocus', () => {
this._subscription = this.props.navigation.addListener(
'refocus',
() => {
const scrollableNode = this.getNode();
if (this.props.navigation.isFocused() && scrollableNode !== null) {
if (scrollableNode.scrollToTop != null) {
@@ -19,40 +22,9 @@ export default function createNavigationAwareScrollable(Component: any) {
scrollableNode.scrollTo({ y: 0 });
}
}
});
}
setNativeProps = (...args) => {
return this.getNode().setNativeProps(...args);
};
getScrollResponder = (...args) => {
return this.getNode().getScrollResponder(...args);
};
getScrollableNode = (...args) => {
return this.getNode().getScrollableNode(...args);
};
getInnerViewNode = (...args) => {
return this.getNode().getInnerViewNode(...args);
};
scrollTo = (...args) => {
return this.getNode().scrollTo(...args);
};
scrollToEnd = (...args) => {
return this.getNode().scrollToEnd(...args);
};
scrollWithoutAnimationTo = (...args) => {
return this.getNode().scrollWithoutAnimationTo(...args);
};
flashScrollIndicators = (...args) => {
return this.getNode().flashScrollIndicators(...args);
};
);
}
getNode() {
if (this._scrollRef === null) {
@@ -85,9 +57,58 @@ export default function createNavigationAwareScrollable(Component: any) {
);
}
}
return hoistStatics(
withNavigation(ComponentWithNavigationScrolling),
Component
);
class NavigationAwareScrollable extends React.PureComponent<any> {
static displayName = `NavigationAwareScrollable(${Component.displayName ||
Component.name})`;
_captureRef = view => {
this._innerRef = view;
this.props.onRef && this.props.onRef(view);
};
setNativeProps = (...args) => {
return this._innerRef.getNode().setNativeProps(...args);
};
getScrollResponder = (...args) => {
return this._innerRef.getNode().getScrollResponder(...args);
};
getScrollableNode = (...args) => {
return this._innerRef.getNode().getScrollableNode(...args);
};
getInnerViewNode = (...args) => {
return this._innerRef.getNode().getInnerViewNode(...args);
};
scrollTo = (...args) => {
return this._innerRef.getNode().scrollTo(...args);
};
scrollToEnd = (...args) => {
return this._innerRef.getNode().scrollToEnd(...args);
};
scrollWithoutAnimationTo = (...args) => {
return this._innerRef.getNode().scrollWithoutAnimationTo(...args);
};
flashScrollIndicators = (...args) => {
return this._innerRef.getNode().flashScrollIndicators(...args);
};
render() {
return (
<ComponentWithNavigationScrolling
{...this.props}
onRef={this._captureRef}
/>
);
}
}
return hoistStatics(NavigationAwareScrollable, Component);
}