refactor(modal): use new content scroll utils for swipe to close (#25344)

This commit is contained in:
Liam DeBeasi
2022-05-31 11:51:06 -04:00
committed by GitHub
parent 0b92dffa92
commit d5cde5e5c0

View File

@ -1,6 +1,11 @@
import type { Animation } from '../../../interface'; import type { Animation } from '../../../interface';
import { getTimeGivenProgression } from '../../../utils/animation/cubic-bezier'; import { getTimeGivenProgression } from '../../../utils/animation/cubic-bezier';
import { isIonContent, findClosestIonContent } from '../../../utils/content'; import {
isIonContent,
findClosestIonContent,
disableContentScrollY,
resetContentScrollY,
} from '../../../utils/content';
import type { GestureDetail } from '../../../utils/gesture'; import type { GestureDetail } from '../../../utils/gesture';
import { createGesture } from '../../../utils/gesture'; import { createGesture } from '../../../utils/gesture';
import { clamp, getElementRoot } from '../../../utils/helpers'; import { clamp, getElementRoot } from '../../../utils/helpers';
@ -33,30 +38,6 @@ export const createSwipeToCloseGesture = (el: HTMLIonModalElement, animation: An
} }
}; };
const disableContentScroll = () => {
if (!contentEl) {
return;
}
if (isIonContent(contentEl)) {
(contentEl as HTMLIonContentElement).scrollY = false;
} else {
contentEl.style.setProperty('overflow', 'hidden');
}
};
const resetContentScroll = () => {
if (!contentEl) {
return;
}
if (isIonContent(contentEl)) {
(contentEl as HTMLIonContentElement).scrollY = initialScrollY;
} else {
contentEl.style.removeProperty('overflow');
}
};
const canStart = (detail: GestureDetail) => { const canStart = (detail: GestureDetail) => {
const target = detail.event.target as HTMLElement | null; const target = detail.event.target as HTMLElement | null;
@ -145,8 +126,8 @@ export const createSwipeToCloseGesture = (el: HTMLIonModalElement, animation: An
* content. We do not want scrolling to * content. We do not want scrolling to
* happen at the same time as the gesture. * happen at the same time as the gesture.
*/ */
if (deltaY > 0) { if (deltaY > 0 && contentEl) {
disableContentScroll(); disableContentScrollY(contentEl);
} }
animation.progressStart(true, isOpen ? 1 : 0); animation.progressStart(true, isOpen ? 1 : 0);
@ -161,8 +142,8 @@ export const createSwipeToCloseGesture = (el: HTMLIonModalElement, animation: An
* content. We do not want scrolling to * content. We do not want scrolling to
* happen at the same time as the gesture. * happen at the same time as the gesture.
*/ */
if (deltaY > 0) { if (deltaY > 0 && contentEl) {
disableContentScroll(); disableContentScrollY(contentEl);
} }
/** /**
@ -245,7 +226,9 @@ export const createSwipeToCloseGesture = (el: HTMLIonModalElement, animation: An
gesture.enable(false); gesture.enable(false);
resetContentScroll(); if (contentEl) {
resetContentScrollY(contentEl, initialScrollY);
}
animation animation
.onFinish(() => { .onFinish(() => {