From 8f395b65f609bb04e0e7e8f1800a565e48ebe209 Mon Sep 17 00:00:00 2001 From: Wesley de Faveri Date: Thu, 19 Mar 2020 19:04:16 -0300 Subject: [PATCH] feat: add prop to open full with snap state #150 --- src/index.tsx | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/src/index.tsx b/src/index.tsx index 5d6be891..0d3232a7 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -161,14 +161,14 @@ export class Modalize extends React.C Keyboard.removeListener('keyboardDidHide', this.onKeyboardHide); } - public open = (): void => { - const { onOpen } = this.props; + public open = (dest: string): void => { + const { onOpen, alwaysOpen } = this.props; if (onOpen) { onOpen(); } - this.onAnimateOpen(); + this.onAnimateOpen(alwaysOpen, dest); }; public close = (dest: 'alwaysOpen' | 'default' = 'default'): void => { @@ -236,7 +236,7 @@ export class Modalize extends React.C }; } - private onAnimateOpen = (alwaysOpen?: number): void => { + private onAnimateOpen = (alwaysOpen?: number, dest?: string): void => { const { onOpened, snapPoint, @@ -247,11 +247,16 @@ export class Modalize extends React.C const { timing, spring } = openAnimationConfig!; const { overlay, modalHeight } = this.state; - const toValue = alwaysOpen - ? (modalHeight || 0) - alwaysOpen - : snapPoint - ? (modalHeight || 0) - snapPoint - : 0; + + let toValue = 0; + + if (dest === 'fullHeight') { + toValue = 0; + } else if (alwaysOpen) { + toValue = (modalHeight || 0) - alwaysOpen; + } else if (snapPoint) { + toValue = (modalHeight || 0) - snapPoint; + } BackHandler.addEventListener('hardwareBackPress', this.onBackPress); @@ -286,7 +291,7 @@ export class Modalize extends React.C } if (onPositionChange) { - if (alwaysOpen || snapPoint) { + if (alwaysOpen || (snapPoint && dest === 'default')) { this.modalPosition = 'initial'; } else { this.modalPosition = 'top';