Skip to content

Commit

Permalink
feat: add onLayout props #49
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremybarbet committed Mar 19, 2020
1 parent 748c3e7 commit 598d548
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
8 changes: 8 additions & 0 deletions docs/PROPSMETHODS.md
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,14 @@ Callback used when you press the overlay.
| -------- | -------- |
| function | No |

### `onLayout`

Callback to subscribe to layout changes. Return the `LayoutRectangle` object from react-native.

| Type | Required |
| -------------------------------------------------------------------------------------------- | -------- |
| function: (nativeEvent: { layout: { height: number, width: number, x: number, y: number } }) | No |

<br/>
<br/>
<br/>
Expand Down
6 changes: 5 additions & 1 deletion src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,11 @@ export class Modalize<FlatListItem = any, SectionListItem = any> extends React.C
};

private onContentViewLayout = ({ nativeEvent }: LayoutChangeEvent): void => {
const { adjustToContentHeight, disableScrollIfPossible } = this.props;
const { adjustToContentHeight, disableScrollIfPossible, onLayout } = this.props;

if (onLayout) {
onLayout(nativeEvent);
}

if (!adjustToContentHeight) {
return;
Expand Down
6 changes: 6 additions & 0 deletions src/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
FlatListProps,
SectionListProps,
EasingFunction,
LayoutRectangle,
} from 'react-native';

export interface ITimingProps {
Expand Down Expand Up @@ -230,6 +231,11 @@ export interface IProps<FlatListItem = any, SectionListItem = any> {
* Callback used when you press the overlay.
*/
onOverlayPress?(): void;

/**
* Callback used when you press the overlay.
*/
onLayout?(nativeEvent: { layout: LayoutRectangle }): void;
}

export interface IState {
Expand Down

0 comments on commit 598d548

Please sign in to comment.