Skip to content

Commit

Permalink
fix: avoid onScrollBeginDrag overriding default behavior (#180)
Browse files Browse the repository at this point in the history
* fix: overriding props needed to work and calling onScrollBeginDrag method passed via scroll props

* fix: simpified handling scrollBeginDrag

* fix: moved back Animated.event for handling onScrollBeginDrag

* fix: simplified onScrollBeginDrag event listener

* fix: removed unnecessary line break and run prettier
  • Loading branch information
xxsnakerxx authored Apr 25, 2020
1 parent c94bbc6 commit 14f20cb
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ import {
Platform,
StatusBar,
KeyboardEvent,
NativeSyntheticEvent,
NativeScrollEvent,
} from 'react-native';
import {
PanGestureHandler,
Expand Down Expand Up @@ -584,12 +586,16 @@ const ModalizeBase = (

const renderContent = (): JSX.Element => {
const keyboardDismissMode = isIos ? 'interactive' : 'on-drag';
const passedOnScrollBeginDrag = (flatListProps ?? sectionListProps ?? scrollViewProps)
?.onScrollBeginDrag;

const opts = {
ref: contentView,
bounces: enableBounces,
onScrollBeginDrag: Animated.event([{ nativeEvent: { contentOffset: { y: beginScrollY } } }], {
useNativeDriver: USE_NATIVE_DRIVER,
// @ts-ignore
listener: e => passedOnScrollBeginDrag?.(e),
}),
scrollEventThrottle: 16,
onLayout: handleContentViewLayout,
Expand All @@ -598,19 +604,19 @@ const ModalizeBase = (
};

if (flatListProps) {
return <AnimatedFlatList {...opts} {...flatListProps} />;
return <AnimatedFlatList {...flatListProps} {...opts} />;
}

if (sectionListProps) {
return <AnimatedSectionList {...opts} {...sectionListProps} />;
return <AnimatedSectionList {...sectionListProps} {...opts} />;
}

if (customRenderer) {
return cloneElement(customRenderer, { ...opts });
}

return (
<Animated.ScrollView {...opts} {...scrollViewProps}>
<Animated.ScrollView {...scrollViewProps} {...opts}>
{children}
</Animated.ScrollView>
);
Expand Down

0 comments on commit 14f20cb

Please sign in to comment.