|
1 | 1 | import type { Animation } from '../../interface'; |
2 | 2 | import { createAnimation } from '../animation/animation'; |
3 | 3 | import type { TransitionOptions } from '../transition'; |
4 | | -import { getIonPageElement } from '../transition'; |
5 | 4 |
|
6 | | -export const mdTransitionAnimation = (_: HTMLElement, opts: TransitionOptions): Animation => { |
7 | | - const OFF_BOTTOM = '40px'; |
8 | | - const CENTER = '0px'; |
9 | | - |
10 | | - const backDirection = opts.direction === 'back'; |
11 | | - const enteringEl = opts.enteringEl; |
12 | | - const leavingEl = opts.leavingEl; |
13 | | - |
14 | | - const ionPageElement = getIonPageElement(enteringEl); |
15 | | - const enteringToolbarEle = ionPageElement.querySelector('ion-toolbar'); |
16 | | - const rootTransition = createAnimation(); |
17 | | - |
18 | | - rootTransition.addElement(ionPageElement).fill('both').beforeRemoveClass('ion-page-invisible'); |
19 | | - |
20 | | - // animate the component itself |
21 | | - if (backDirection) { |
22 | | - rootTransition.duration((opts.duration ?? 0) || 200).easing('cubic-bezier(0.47,0,0.745,0.715)'); |
23 | | - } else { |
24 | | - rootTransition |
25 | | - .duration((opts.duration ?? 0) || 280) |
26 | | - .easing('cubic-bezier(0.36,0.66,0.04,1)') |
27 | | - .fromTo('transform', `translateY(${OFF_BOTTOM})`, `translateY(${CENTER})`) |
28 | | - .fromTo('opacity', 0.01, 1); |
29 | | - } |
30 | | - |
31 | | - // Animate toolbar if it's there |
32 | | - if (enteringToolbarEle) { |
33 | | - const enteringToolBar = createAnimation(); |
34 | | - enteringToolBar.addElement(enteringToolbarEle); |
35 | | - rootTransition.addAnimation(enteringToolBar); |
36 | | - } |
37 | | - |
38 | | - // setup leaving view |
39 | | - if (leavingEl && backDirection) { |
40 | | - // leaving content |
41 | | - rootTransition.duration((opts.duration ?? 0) || 200).easing('cubic-bezier(0.47,0,0.745,0.715)'); |
42 | | - |
43 | | - const leavingPage = createAnimation(); |
44 | | - leavingPage |
45 | | - .addElement(getIonPageElement(leavingEl)) |
46 | | - .onFinish((currentStep) => { |
47 | | - if (currentStep === 1 && leavingPage.elements.length > 0) { |
48 | | - leavingPage.elements[0].style.setProperty('display', 'none'); |
49 | | - } |
50 | | - }) |
51 | | - .fromTo('transform', `translateY(${CENTER})`, `translateY(${OFF_BOTTOM})`) |
52 | | - .fromTo('opacity', 1, 0); |
53 | | - |
54 | | - rootTransition.addAnimation(leavingPage); |
55 | | - } |
56 | | - |
57 | | - return rootTransition; |
58 | | -}; |
59 | 5 |
|
60 | 6 |
|
61 | 7 | const dpToPx = (n: number) => window.devicePixelRatio * n; |
62 | 8 |
|
63 | | -export const mdTransitionAnimation2 = (_: HTMLElement, opts: TransitionOptions): Animation => { |
| 9 | +export const mdTransitionAnimation = (_: HTMLElement, opts: TransitionOptions): Animation => { |
64 | 10 | const enteringEl = opts.enteringEl; |
65 | 11 | const leavingEl = opts.leavingEl; |
66 | 12 |
|
|
0 commit comments