Skip to content

Commit

Permalink
feat: recalculate when toggle adjustToContentHeight prop
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremybarbet committed Mar 29, 2020
1 parent 7de03c2 commit 6fc762d
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
18 changes: 15 additions & 3 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ export class Modalize<FlatListItem = any, SectionListItem = any> extends React.C
keyboardToggle: false,
keyboardHeight: 0,
disableScroll: props.alwaysOpen ? true : undefined,
adjust: props.adjustToContentHeight,
};

this.beginScrollY.addListener(({ value }) => (this.beginScrollYValue = value));
Expand All @@ -161,6 +162,17 @@ export class Modalize<FlatListItem = any, SectionListItem = any> extends React.C
Keyboard.addListener('keyboardDidHide', this.onKeyboardHide);
}

componentDidUpdate({ adjustToContentHeight }: IProps) {
const { adjustToContentHeight: nextAdjust } = this.props;

if (nextAdjust !== adjustToContentHeight) {
this.setState({
modalHeight: nextAdjust ? undefined : this.initialComputedModalHeight,
adjust: nextAdjust,
});
}
}

componentWillUnmount() {
BackHandler.removeEventListener('hardwareBackPress', this.onBackPress);
Keyboard.removeListener('keyboardDidShow', this.onKeyboardShow);
Expand Down Expand Up @@ -705,6 +717,8 @@ export class Modalize<FlatListItem = any, SectionListItem = any> extends React.C

private renderChildren = (): React.ReactNode => {
const { adjustToContentHeight, panGestureEnabled } = this.props;
const { adjust } = this.state;
const style = !adjustToContentHeight && adjust ? s.content__container : s.content__adjustHeight;

return (
<PanGestureHandler
Expand All @@ -718,9 +732,7 @@ export class Modalize<FlatListItem = any, SectionListItem = any> extends React.C
activeOffsetX={ACTIVATED}
onHandlerStateChange={this.onHandleChildren}
>
<Animated.View
style={!adjustToContentHeight ? s.content__container : s.content__adjustHeight}
>
<Animated.View style={style}>
<NativeViewGestureHandler
ref={this.modalContentView}
waitFor={this.modal}
Expand Down
5 changes: 5 additions & 0 deletions src/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -306,4 +306,9 @@ export interface IState {
* Store height of the keyboard.
*/
keyboardHeight: number;

/**
* Store if the modal is using adjustToContentHeight props
*/
adjust: boolean | undefined;
}

0 comments on commit 6fc762d

Please sign in to comment.