|
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,14 @@ 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 | + const targetEl = findClosestIonContent(detail.event.target! as HTMLElement); |
| 243 | + cachedScrollEl = targetEl && isIonContent(targetEl) ? getElementRoot(targetEl).querySelector('.inner-scroll') : targetEl; |
| 244 | + |
236 | 245 | /** |
237 | 246 | * If expandToScroll is disabled, we need to swap |
238 | 247 | * the footer visibility to the original, so if the modal |
@@ -267,13 +276,8 @@ export const createSheetGesture = ( |
267 | 276 | * If `expandToScroll` is disabled, and an upwards swipe gesture is done within |
268 | 277 | * the scrollable content, we should not allow the swipe gesture to continue. |
269 | 278 | */ |
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 | | - } |
| 279 | + if (!expandToScroll && detail.deltaY <= 0 && cachedScrollEl) { |
| 280 | + return; |
277 | 281 | } |
278 | 282 |
|
279 | 283 | /** |
@@ -334,12 +338,8 @@ export const createSheetGesture = ( |
334 | 338 | * function to be called if the user is trying to swipe content upwards and the content |
335 | 339 | * is not scrolled to the top. |
336 | 340 | */ |
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 | | - } |
| 341 | + if (!expandToScroll && detail.deltaY <= 0 && cachedScrollEl && cachedScrollEl.scrollTop > 0) { |
| 342 | + return; |
343 | 343 | } |
344 | 344 |
|
345 | 345 | /** |
|
0 commit comments