fix(modal): swipeToClose property is now reactive (#21073)

fixes #21072
This commit is contained in:
Liam DeBeasi
2020-04-27 11:27:18 -04:00
committed by GitHub
parent 1b11ff7fb9
commit 4bd9134473

View File

@ -1,4 +1,4 @@
import { Component, ComponentInterface, Element, Event, EventEmitter, Host, Method, Prop, h, writeTask } from '@stencil/core';
import { Component, ComponentInterface, Element, Event, EventEmitter, Host, Method, Prop, Watch, h, writeTask } from '@stencil/core';
import { config } from '../../global/config';
import { getIonMode } from '../../global/ionic-global';
@ -121,6 +121,15 @@ export class Modal implements ComponentInterface, OverlayInterface {
*/
@Event({ eventName: 'ionModalDidDismiss' }) didDismiss!: EventEmitter<OverlayEventDetail>;
@Watch('swipeToClose')
swipeToCloseChanged(enable: boolean) {
if (this.gesture) {
this.gesture.enable(enable);
} else if (enable) {
this.initSwipeToClose();
}
}
constructor() {
prepareOverlay(this.el);
}
@ -148,8 +157,14 @@ export class Modal implements ComponentInterface, OverlayInterface {
await present(this, 'modalEnter', iosEnterAnimation, mdEnterAnimation, this.presentingElement);
const mode = getIonMode(this);
if (this.swipeToClose && mode === 'ios') {
if (this.swipeToClose) {
this.initSwipeToClose();
}
}
private initSwipeToClose() {
if (getIonMode(this) !== 'ios') { return; }
// All of the elements needed for the swipe gesture
// should be in the DOM and referenced by now, except
// for the presenting el
@ -178,7 +193,6 @@ export class Modal implements ComponentInterface, OverlayInterface {
);
this.gesture.enable(true);
}
}
/**
* Dismiss the modal overlay after it has been presented.