Skip to content

Commit

Permalink
feat: add threshold props made by @adrianso
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremybarbet committed Apr 10, 2020
1 parent 1ebdab5 commit cf0be59
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
8 changes: 8 additions & 0 deletions docs/PROPSMETHODS.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
5 changes: 3 additions & 2 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -73,6 +72,7 @@ export class Modalize<FlatListItem = any, SectionListItem = any> extends React.C
timing: { duration: 280, easing: Easing.ease },
},
dragToss: 0.05,
threshold: 150,
};

private snaps: number[] = [];
Expand Down Expand Up @@ -460,6 +460,7 @@ export class Modalize<FlatListItem = any, SectionListItem = any> extends React.C
dragToss,
onPositionChange,
panGestureAnimatedValue,
threshold,
} = this.props;
const { timing } = closeAnimationConfig!;
const { lastSnap, modalHeight, overlay } = this.state;
Expand Down Expand Up @@ -492,7 +493,7 @@ export class Modalize<FlatListItem = any, SectionListItem = any> extends React.C
}
});
} else if (
translationY > (adjustToContentHeight ? (modalHeight || 0) / 3 : THRESHOLD) &&
translationY > (adjustToContentHeight ? (modalHeight || 0) / 3 : threshold) &&
this.beginScrollYValue === 0 &&
!alwaysOpen
) {
Expand Down
6 changes: 6 additions & 0 deletions src/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,12 @@ export interface IProps<FlatListItem = any, SectionListItem = any> {
*/
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
Expand Down

0 comments on commit cf0be59

Please sign in to comment.