Skip to content

Commit

Permalink
feat: add onOverlayPress #142
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremybarbet committed Mar 19, 2020
1 parent b30eff3 commit 748c3e7
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 9 deletions.
14 changes: 10 additions & 4 deletions docs/PROPSMETHODS.md
Original file line number Diff line number Diff line change
Expand Up @@ -256,11 +256,17 @@ Callback function when the modal reaches the `top` (modal/screen height) or `ini

?> Not to be conflicted with `onOpened` which is triggered when the modal opens for the first time.

| Type | Required |
| --------------------------------------- | -------- |
| Type | Required |
| ---------------------------------------- | -------- |
| function: (position: 'top' \| 'initial') | No |

### `onOverlayPress`

Callback used when you press the overlay.

| Type | Required |
| -------- | -------- |
| function | No |

<br/>
<br/>
Expand All @@ -283,8 +289,8 @@ The method to close the modal. You don't need to call it to dismiss the modal, s

?> If you are using `alwaysOpen` props, you can supply a `dest` argument to the `close` method to reset it to the intial position `close('alwaysOpen')`, and avoiding to close it completely.

| Type | Required |
| ------------------------------------------ | -------- |
| Type | Required |
| ------------------------------------------- | -------- |
| function: (dest: 'alwaysOpen' \| 'default') | No |

### `scrollTo()`
Expand Down
6 changes: 6 additions & 0 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -489,7 +489,13 @@ export class Modalize<FlatListItem = any, SectionListItem = any> extends React.C
};

private onHandleOverlay = ({ nativeEvent }: TapGestureHandlerStateChangeEvent): void => {
const { onOverlayPress } = this.props;

if (nativeEvent.oldState === State.ACTIVE && !this.willCloseModalize) {
if (onOverlayPress) {
onOverlayPress();
}

this.close();
}
};
Expand Down
15 changes: 10 additions & 5 deletions src/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,36 +195,41 @@ export interface IProps<FlatListItem = any, SectionListItem = any> {
/**
* Callback function when the `open` method is triggered.
*/
onOpen?: () => void;
onOpen?(): void;

/**
* Callback function when the modal is opened.
*/
onOpened?: () => void;
onOpened?(): void;

/**
* Callback function when the `close` method is triggered.
*/
onClose?: () => void;
onClose?(): void;

/**
* Callback function when the modal is closed.
*/
onClosed?: () => void;
onClosed?(): void;

/**
* onBackButtonPress is called when the user taps the hardware back button on
* Android or the menu button on Apple TV. You can any function you want,
* but you will have to close the modal by yourself.
*/
onBackButtonPress?: () => boolean;
onBackButtonPress?(): boolean;

/**
* Callback function which determines if the modal has reached the top
* i.e. completely opened to modal/screen height, or is at the initial
* point (snapPoint or alwaysOpened height)
*/
onPositionChange?: (position: 'top' | 'initial') => void;

/**
* Callback used when you press the overlay.
*/
onOverlayPress?(): void;
}

export interface IState {
Expand Down

0 comments on commit 748c3e7

Please sign in to comment.