Skip to content

Commit 534dc69

Browse files
committed
fix: rework initial open/close states
1 parent 9680403 commit 534dc69

File tree

2 files changed

+17
-11
lines changed

2 files changed

+17
-11
lines changed

src/index.tsx

+14-11
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import {
2626
TapGestureHandlerStateChangeEvent,
2727
} from 'react-native-gesture-handler';
2828

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

149149
componentDidMount() {
150-
if (this.props.alwaysOpen) {
151-
this.onAnimateOpen(this.props.alwaysOpen);
150+
const { alwaysOpen } = this.props;
151+
152+
if (alwaysOpen) {
153+
this.onAnimateOpen(alwaysOpen);
152154
}
153155

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

164-
public open = (dest: string): void => {
165-
const { onOpen, alwaysOpen } = this.props;
166+
public open = (dest: TOpen): void => {
167+
const { onOpen } = this.props;
166168

167169
if (onOpen) {
168170
onOpen();
169171
}
170172

171-
this.onAnimateOpen(alwaysOpen, dest);
173+
this.onAnimateOpen(undefined, dest);
172174
};
173175

174-
public close = (dest: 'alwaysOpen' | 'default' = 'default'): void => {
176+
public close = (dest: TClose = 'default'): void => {
175177
const { onClose } = this.props;
176178

177179
if (onClose) {
@@ -236,7 +238,7 @@ export class Modalize<FlatListItem = any, SectionListItem = any> extends React.C
236238
};
237239
}
238240

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

251253
let toValue = 0;
252254

253-
if (dest === 'fullHeight') {
255+
if (dest === 'top') {
254256
toValue = 0;
255257
} else if (alwaysOpen) {
256258
toValue = (modalHeight || 0) - alwaysOpen;
@@ -302,7 +304,7 @@ export class Modalize<FlatListItem = any, SectionListItem = any> extends React.C
302304
});
303305
};
304306

305-
private onAnimateClose = (dest: 'alwaysOpen' | 'default' = 'default'): void => {
307+
private onAnimateClose = (dest: TClose = 'default'): void => {
306308
const {
307309
onClosed,
308310
useNativeDriver,
@@ -693,7 +695,8 @@ export class Modalize<FlatListItem = any, SectionListItem = any> extends React.C
693695
closeOnOverlayTap,
694696
} = this.props;
695697
const { showContent } = this.state;
696-
const pointerEvents = alwaysOpen && this.modalPosition === 'initial' ? 'box-none' : 'auto';
698+
const pointerEvents =
699+
alwaysOpen && (this.modalPosition === 'initial' || !this.modalPosition) ? 'box-none' : 'auto';
697700

698701
return (
699702
<PanGestureHandler

src/options.ts

+3
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ import {
99
LayoutRectangle,
1010
} from 'react-native';
1111

12+
export type TOpen = 'default' | 'top';
13+
export type TClose = 'default' | 'alwaysOpen';
14+
1215
export interface ITimingProps {
1316
duration: number;
1417
easing?: EasingFunction;

0 commit comments

Comments
 (0)