From d3f623e4633c5e8e2027e7580aa1c4d09e4be491 Mon Sep 17 00:00:00 2001 From: OmranElmasry Date: Tue, 16 Feb 2021 11:28:02 +0200 Subject: [PATCH] [ADD] onScrollListener callback --- src/ScrollViewIndicator.js | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/src/ScrollViewIndicator.js b/src/ScrollViewIndicator.js index 078ef0e..c6e8a91 100644 --- a/src/ScrollViewIndicator.js +++ b/src/ScrollViewIndicator.js @@ -14,7 +14,6 @@ export default ({ scrollIndicatorStyle = {}, ...props }) => { - const { onScroll, ...propsToSpread } = props; const [fadeAnim] = useState( new Animated.Value(shouldIndicatorHide ? 0 : 1), ); @@ -33,14 +32,7 @@ export default ({ setScrollIndicatorContainerHeight, ] = useState(1); - const handleScroll = (value) => { - const {nativeEvent: { contentOffset }} = value; - /** - * Propagating onScroll event upwards in case onScroll prop is provided - */ - if (onScroll && typeof onScroll === 'function') { - onScroll(value); - } + const handleScroll = ({ contentOffset }) => { //Calculation scroll indicator position based on child height and scrollView view height) const movePercent = contentOffset.y / @@ -99,12 +91,15 @@ export default ({ onLayout={e => setVisibleScrollPartHeight(e.nativeEvent.layout.height) } - onScroll={handleScroll} + onScroll={(e) => { + props.onScrollListener(e) + handleScroll(e.nativeEvent) + }} scrollEventThrottle={16} onMomentumScrollEnd={() => runHideTimer()} onScrollBeginDrag={() => showIndicator()} showsVerticalScrollIndicator={false} - {...propsToSpread} + {...props} > {children}