Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 16 commits into from
May 31, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 13 additions & 30 deletions core/src/components/modal/gestures/swipe-to-close.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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);
Expand All @@ -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);
}

/**
Expand Down Expand Up @@ -245,7 +226,9 @@ export const createSwipeToCloseGesture = (el: HTMLIonModalElement, animation: An

gesture.enable(false);

resetContentScroll();
if (contentEl) {
resetContentScrollY(contentEl, initialScrollY);
}

animation
.onFinish(() => {
Expand Down