From cf0be59ad58377f55481a17c4e0ecb705624e37d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Barbet?= Date: Fri, 10 Apr 2020 09:08:15 +0000 Subject: [PATCH] feat: add threshold props made by @adrianso --- docs/PROPSMETHODS.md | 8 ++++++++ src/index.tsx | 5 +++-- src/options.ts | 6 ++++++ 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/docs/PROPSMETHODS.md b/docs/PROPSMETHODS.md index f093c64e..75681d77 100644 --- a/docs/PROPSMETHODS.md +++ b/docs/PROPSMETHODS.md @@ -124,6 +124,14 @@ A number that determines the momentum of the scroll required. | -------- | -------- | ------- | | number | No | `0.05` | +### `threshold` + +Number of pixels that the user must drag the modal before snapping to another position. + +| Type | Required | Default | +| -------- | -------- | ------- | +| number | No | `150` | + ### `adjustToContentHeight` Shrink the modal to your content's height. diff --git a/src/index.tsx b/src/index.tsx index 85a741c2..ba990fe6 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -38,7 +38,6 @@ const AnimatedKeyboardAvoidingView = Animated.createAnimatedComponent(KeyboardAv const AnimatedFlatList = Animated.createAnimatedComponent(FlatList); const AnimatedSectionList = Animated.createAnimatedComponent(SectionList); const GestureHandlerWrapper = GestureHandlerRootView ?? View; -const THRESHOLD = 150; const ACTIVATED = 20; const PAN_DURATION = 150; @@ -73,6 +72,7 @@ export class Modalize extends React.C timing: { duration: 280, easing: Easing.ease }, }, dragToss: 0.05, + threshold: 150, }; private snaps: number[] = []; @@ -460,6 +460,7 @@ export class Modalize extends React.C dragToss, onPositionChange, panGestureAnimatedValue, + threshold, } = this.props; const { timing } = closeAnimationConfig!; const { lastSnap, modalHeight, overlay } = this.state; @@ -492,7 +493,7 @@ export class Modalize extends React.C } }); } else if ( - translationY > (adjustToContentHeight ? (modalHeight || 0) / 3 : THRESHOLD) && + translationY > (adjustToContentHeight ? (modalHeight || 0) / 3 : threshold) && this.beginScrollYValue === 0 && !alwaysOpen ) { diff --git a/src/options.ts b/src/options.ts index 06fd02e5..1a4ea66a 100644 --- a/src/options.ts +++ b/src/options.ts @@ -122,6 +122,12 @@ export interface IProps { */ dragToss: number; + /** + * Number of pixels that the user must drag the modal before snapping to another position. + * @default 150 + */ + threshold: number; + /** * Shrink the modal to your content's height. * @default false