Skip to content

Commit

Permalink
feat: add prop to open full with snap state #150 (#153)
Browse files Browse the repository at this point in the history
  • Loading branch information
WesleyFaveri authored Mar 20, 2020
1 parent 92db47b commit dfd56fb
Showing 1 changed file with 15 additions and 10 deletions.
25 changes: 15 additions & 10 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -161,14 +161,14 @@ export class Modalize<FlatListItem = any, SectionListItem = any> 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 => {
Expand Down Expand Up @@ -236,7 +236,7 @@ export class Modalize<FlatListItem = any, SectionListItem = any> extends React.C
};
}

private onAnimateOpen = (alwaysOpen?: number): void => {
private onAnimateOpen = (alwaysOpen?: number, dest?: string): void => {
const {
onOpened,
snapPoint,
Expand All @@ -247,11 +247,16 @@ export class Modalize<FlatListItem = any, SectionListItem = any> 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);

Expand Down Expand Up @@ -286,7 +291,7 @@ export class Modalize<FlatListItem = any, SectionListItem = any> extends React.C
}

if (onPositionChange) {
if (alwaysOpen || snapPoint) {
if (alwaysOpen || (snapPoint && dest === 'default')) {
this.modalPosition = 'initial';
} else {
this.modalPosition = 'top';
Expand Down

0 comments on commit dfd56fb

Please sign in to comment.