|
| 1 | +import { createAnimation } from '@utils/animation/animation'; |
| 2 | +import { getElementRoot } from '@utils/helpers'; |
| 3 | + |
| 4 | +import type { Animation } from '../../../interface'; |
| 5 | +import type { ModalAnimationOptions } from '../modal-interface'; |
| 6 | + |
| 7 | +import { createSheetEnterAnimation } from './sheet'; |
| 8 | + |
| 9 | +const createEnterAnimation = () => { |
| 10 | + const backdropAnimation = createAnimation() |
| 11 | + .fromTo('opacity', 0.01, 'var(--backdrop-opacity)') |
| 12 | + .beforeStyles({ |
| 13 | + 'pointer-events': 'none', |
| 14 | + }) |
| 15 | + .afterClearStyles(['pointer-events']); |
| 16 | + |
| 17 | + const wrapperAnimation = createAnimation().keyframes([ |
| 18 | + { offset: 0, opacity: 0.01, transform: 'translateY(40px)' }, |
| 19 | + { offset: 1, opacity: 1, transform: `translateY(0px)` }, |
| 20 | + ]); |
| 21 | + |
| 22 | + return { backdropAnimation, wrapperAnimation, contentAnimation: undefined }; |
| 23 | +}; |
| 24 | + |
| 25 | +/** |
| 26 | + * Ionic Modal Enter Animation |
| 27 | + */ |
| 28 | +export const ionicEnterAnimation = (baseEl: HTMLElement, opts: ModalAnimationOptions): Animation => { |
| 29 | + const { currentBreakpoint, expandToScroll } = opts; |
| 30 | + const root = getElementRoot(baseEl); |
| 31 | + const { wrapperAnimation, backdropAnimation, contentAnimation } = |
| 32 | + currentBreakpoint !== undefined ? createSheetEnterAnimation(opts) : createEnterAnimation(); |
| 33 | + |
| 34 | + backdropAnimation.addElement(root.querySelector('ion-backdrop')!); |
| 35 | + |
| 36 | + wrapperAnimation.addElement(root.querySelector('.modal-wrapper')!); |
| 37 | + |
| 38 | + // The content animation is only added if scrolling is enabled for |
| 39 | + // all the breakpoints. |
| 40 | + !expandToScroll && contentAnimation?.addElement(baseEl.querySelector('.ion-page')!); |
| 41 | + |
| 42 | + backdropAnimation.duration(300).easing('ease-out'); |
| 43 | + wrapperAnimation.duration(400).easing('cubic-bezier(0.32, 0.68, 0, 1)'); |
| 44 | + contentAnimation?.duration(400).easing('cubic-bezier(0.32, 0.68, 0, 1)'); |
| 45 | + |
| 46 | + const baseAnimation = createAnimation().addElement(baseEl).addAnimation([backdropAnimation, wrapperAnimation]); |
| 47 | + |
| 48 | + if (contentAnimation) { |
| 49 | + baseAnimation.addAnimation(contentAnimation); |
| 50 | + } |
| 51 | + |
| 52 | + return baseAnimation; |
| 53 | +}; |
0 commit comments