|
1 |
| -import { isIonContent, findClosestIonContent } from '@utils/content'; |
| 1 | +import { findClosestIonContent, isIonContent } from '@utils/content'; |
2 | 2 | import { createGesture } from '@utils/gesture';
|
3 |
| -import { clamp, raf, getElementRoot } from '@utils/helpers'; |
| 3 | +import { clamp, getElementRoot, raf } from '@utils/helpers'; |
4 | 4 | import { FOCUS_TRAP_DISABLE_CLASS } from '@utils/overlays';
|
5 | 5 |
|
6 | 6 | import type { Animation } from '../../../interface';
|
@@ -83,6 +83,7 @@ export const createSheetGesture = (
|
83 | 83 | let currentBreakpoint = initialBreakpoint;
|
84 | 84 | let offset = 0;
|
85 | 85 | let canDismissBlocksGesture = false;
|
| 86 | + let cachedScrollEl: HTMLElement | null = null; |
86 | 87 | const canDismissMaxStep = 0.95;
|
87 | 88 | const maxBreakpoint = breakpoints[breakpoints.length - 1];
|
88 | 89 | const minBreakpoint = breakpoints[0];
|
@@ -233,6 +234,17 @@ export const createSheetGesture = (
|
233 | 234 | */
|
234 | 235 | canDismissBlocksGesture = baseEl.canDismiss !== undefined && baseEl.canDismiss !== true && minBreakpoint === 0;
|
235 | 236 |
|
| 237 | + /** |
| 238 | + * Cache the scroll element reference when the gesture starts, |
| 239 | + * this allows us to avoid querying the DOM for the target in onMove, |
| 240 | + * which would impact performance significantly. |
| 241 | + */ |
| 242 | + if (!expandToScroll) { |
| 243 | + const targetEl = findClosestIonContent(detail.event.target! as HTMLElement); |
| 244 | + cachedScrollEl = |
| 245 | + targetEl && isIonContent(targetEl) ? getElementRoot(targetEl).querySelector('.inner-scroll') : targetEl; |
| 246 | + } |
| 247 | + |
236 | 248 | /**
|
237 | 249 | * If expandToScroll is disabled, we need to swap
|
238 | 250 | * the footer visibility to the original, so if the modal
|
@@ -267,13 +279,8 @@ export const createSheetGesture = (
|
267 | 279 | * If `expandToScroll` is disabled, and an upwards swipe gesture is done within
|
268 | 280 | * the scrollable content, we should not allow the swipe gesture to continue.
|
269 | 281 | */
|
270 |
| - if (!expandToScroll && detail.deltaY <= 0) { |
271 |
| - const contentEl = findClosestIonContent(detail.event.target! as HTMLElement); |
272 |
| - const scrollEl = |
273 |
| - contentEl && isIonContent(contentEl) ? getElementRoot(contentEl).querySelector('.inner-scroll') : contentEl; |
274 |
| - if (scrollEl) { |
275 |
| - return; |
276 |
| - } |
| 282 | + if (!expandToScroll && detail.deltaY <= 0 && cachedScrollEl) { |
| 283 | + return; |
277 | 284 | }
|
278 | 285 |
|
279 | 286 | /**
|
@@ -334,12 +341,8 @@ export const createSheetGesture = (
|
334 | 341 | * function to be called if the user is trying to swipe content upwards and the content
|
335 | 342 | * is not scrolled to the top.
|
336 | 343 | */
|
337 |
| - if (!expandToScroll && detail.deltaY <= 0 && findClosestIonContent(detail.event.target! as HTMLElement)) { |
338 |
| - const contentEl = findClosestIonContent(detail.event.target! as HTMLElement)!; |
339 |
| - const scrollEl = isIonContent(contentEl) ? getElementRoot(contentEl).querySelector('.inner-scroll') : contentEl; |
340 |
| - if (scrollEl!.scrollTop > 0) { |
341 |
| - return; |
342 |
| - } |
| 344 | + if (!expandToScroll && detail.deltaY <= 0 && cachedScrollEl && cachedScrollEl.scrollTop > 0) { |
| 345 | + return; |
343 | 346 | }
|
344 | 347 |
|
345 | 348 | /**
|
|
0 commit comments