mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2025-08-19 19:57:22 +08:00
refactor(modal): use new content scroll utils for swipe to close (#25344)
This commit is contained in:
@ -1,6 +1,11 @@
|
||||
import type { Animation } from '../../../interface';
|
||||
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 { createGesture } from '../../../utils/gesture';
|
||||
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 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
|
||||
* happen at the same time as the gesture.
|
||||
*/
|
||||
if (deltaY > 0) {
|
||||
disableContentScroll();
|
||||
if (deltaY > 0 && contentEl) {
|
||||
disableContentScrollY(contentEl);
|
||||
}
|
||||
|
||||
animation.progressStart(true, isOpen ? 1 : 0);
|
||||
@ -161,8 +142,8 @@ export const createSwipeToCloseGesture = (el: HTMLIonModalElement, animation: An
|
||||
* content. We do not want scrolling to
|
||||
* happen at the same time as the gesture.
|
||||
*/
|
||||
if (deltaY > 0) {
|
||||
disableContentScroll();
|
||||
if (deltaY > 0 && contentEl) {
|
||||
disableContentScrollY(contentEl);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -245,7 +226,9 @@ export const createSwipeToCloseGesture = (el: HTMLIonModalElement, animation: An
|
||||
|
||||
gesture.enable(false);
|
||||
|
||||
resetContentScroll();
|
||||
if (contentEl) {
|
||||
resetContentScrollY(contentEl, initialScrollY);
|
||||
}
|
||||
|
||||
animation
|
||||
.onFinish(() => {
|
||||
|
Reference in New Issue
Block a user