Skip to content

Commit

Permalink
fix: rework initial open/close states
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremybarbet committed Mar 20, 2020
1 parent 9680403 commit 534dc69
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 11 deletions.
25 changes: 14 additions & 11 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import {
TapGestureHandlerStateChangeEvent,
} from 'react-native-gesture-handler';

import { IProps, IState } from './options';
import { IProps, IState, TOpen, TClose } from './options';
import { getSpringConfig } from './utils/get-spring-config';
import { isIphoneX, isIos } from './utils/devices';
import { hasAbsoluteStyle } from './utils/has-absolute-style';
Expand Down Expand Up @@ -147,8 +147,10 @@ export class Modalize<FlatListItem = any, SectionListItem = any> extends React.C
}

componentDidMount() {
if (this.props.alwaysOpen) {
this.onAnimateOpen(this.props.alwaysOpen);
const { alwaysOpen } = this.props;

if (alwaysOpen) {
this.onAnimateOpen(alwaysOpen);
}

Keyboard.addListener('keyboardDidShow', this.onKeyboardShow);
Expand All @@ -161,17 +163,17 @@ export class Modalize<FlatListItem = any, SectionListItem = any> extends React.C
Keyboard.removeListener('keyboardDidHide', this.onKeyboardHide);
}

public open = (dest: string): void => {
const { onOpen, alwaysOpen } = this.props;
public open = (dest: TOpen): void => {
const { onOpen } = this.props;

if (onOpen) {
onOpen();
}

this.onAnimateOpen(alwaysOpen, dest);
this.onAnimateOpen(undefined, dest);
};

public close = (dest: 'alwaysOpen' | 'default' = 'default'): void => {
public close = (dest: TClose = 'default'): void => {
const { onClose } = this.props;

if (onClose) {
Expand Down Expand Up @@ -236,7 +238,7 @@ export class Modalize<FlatListItem = any, SectionListItem = any> extends React.C
};
}

private onAnimateOpen = (alwaysOpen?: number, dest?: string): void => {
private onAnimateOpen = (alwaysOpen: number | undefined, dest: TOpen = 'default'): void => {
const {
onOpened,
snapPoint,
Expand All @@ -250,7 +252,7 @@ export class Modalize<FlatListItem = any, SectionListItem = any> extends React.C

let toValue = 0;

if (dest === 'fullHeight') {
if (dest === 'top') {
toValue = 0;
} else if (alwaysOpen) {
toValue = (modalHeight || 0) - alwaysOpen;
Expand Down Expand Up @@ -302,7 +304,7 @@ export class Modalize<FlatListItem = any, SectionListItem = any> extends React.C
});
};

private onAnimateClose = (dest: 'alwaysOpen' | 'default' = 'default'): void => {
private onAnimateClose = (dest: TClose = 'default'): void => {
const {
onClosed,
useNativeDriver,
Expand Down Expand Up @@ -693,7 +695,8 @@ export class Modalize<FlatListItem = any, SectionListItem = any> extends React.C
closeOnOverlayTap,
} = this.props;
const { showContent } = this.state;
const pointerEvents = alwaysOpen && this.modalPosition === 'initial' ? 'box-none' : 'auto';
const pointerEvents =
alwaysOpen && (this.modalPosition === 'initial' || !this.modalPosition) ? 'box-none' : 'auto';

return (
<PanGestureHandler
Expand Down
3 changes: 3 additions & 0 deletions src/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ import {
LayoutRectangle,
} from 'react-native';

export type TOpen = 'default' | 'top';
export type TClose = 'default' | 'alwaysOpen';

export interface ITimingProps {
duration: number;
easing?: EasingFunction;
Expand Down

0 comments on commit 534dc69

Please sign in to comment.