-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Expand file tree
/
Copy pathmd.enter.ts
More file actions
160 lines (141 loc) · 4.51 KB
/
md.enter.ts
File metadata and controls
160 lines (141 loc) · 4.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
import { createAnimation } from '@utils/animation/animation';
import { getElementRoot } from '@utils/helpers';
import type { Animation } from '../../../interface';
import {
calculateWindowAdjustment,
getDocumentZoom,
getPopoverDimensions,
getPopoverPosition,
getSafeAreaInsets,
} from '../utils';
const POPOVER_MD_BODY_PADDING = 12;
/**
* Md Popover Enter Animation
*/
// TODO(FW-2832): types
export const mdEnterAnimation = (baseEl: HTMLElement, opts?: any): Animation => {
const { event: ev, size, trigger, reference, side, align } = opts;
const doc = baseEl.ownerDocument as any;
const isRTL = doc.dir === 'rtl';
const zoom = getDocumentZoom(doc as Document);
const bodyWidth = doc.defaultView.innerWidth;
const bodyHeight = doc.defaultView.innerHeight;
const root = getElementRoot(baseEl);
const contentEl = root.querySelector('.popover-content') as HTMLElement;
const referenceSizeEl = trigger || ev?.detail?.ionShadowTarget || ev?.target;
const { contentWidth, contentHeight } = getPopoverDimensions(size, contentEl, referenceSizeEl, zoom);
const defaultPosition = {
top: bodyHeight / 2 - contentHeight / 2,
left: bodyWidth / 2 - contentWidth / 2,
originX: isRTL ? 'right' : 'left',
originY: 'top',
};
const results = getPopoverPosition(
isRTL,
contentWidth,
contentHeight,
0,
0,
reference,
side,
align,
defaultPosition,
trigger,
ev,
zoom
);
const padding = size === 'cover' ? 0 : POPOVER_MD_BODY_PADDING;
// MD mode now applies safe-area insets (previously passed 0, ignoring all safe areas).
// This is needed for Android edge-to-edge (API 36+) where system bars overlap content.
const rawSafeArea = getSafeAreaInsets(doc as Document);
const safeArea =
size === 'cover'
? { top: 0, bottom: 0, left: 0, right: 0 }
: {
top: rawSafeArea.top / zoom,
bottom: rawSafeArea.bottom / zoom,
left: rawSafeArea.left / zoom,
right: rawSafeArea.right / zoom,
};
const {
originX,
originY,
top,
left,
bottom,
checkSafeAreaLeft,
checkSafeAreaRight,
checkSafeAreaTop,
checkSafeAreaBottom,
addPopoverBottomClass,
} = calculateWindowAdjustment(
side,
results.top,
results.left,
padding,
bodyWidth,
bodyHeight,
contentWidth,
contentHeight,
safeArea,
results.originX,
results.originY,
results.referenceCoordinates
);
const safeAreaLeftCalc = ' + var(--ion-safe-area-left, 0px)';
const safeAreaRightCalc = ' - var(--ion-safe-area-right, 0px)';
let leftValue = `${left}px`;
if (checkSafeAreaLeft) {
leftValue = `${left}px${safeAreaLeftCalc}`;
}
if (checkSafeAreaRight) {
leftValue = `${left}px${safeAreaRightCalc}`;
}
let topValue = `${top}px`;
if (checkSafeAreaTop) {
topValue = `${top}px + var(--ion-safe-area-top, 0px)`;
}
const baseAnimation = createAnimation();
const backdropAnimation = createAnimation();
const wrapperAnimation = createAnimation();
const contentAnimation = createAnimation();
const viewportAnimation = createAnimation();
backdropAnimation
.addElement(root.querySelector('ion-backdrop')!)
.fromTo('opacity', 0.01, 'var(--backdrop-opacity)')
.beforeStyles({
'pointer-events': 'none',
})
.afterClearStyles(['pointer-events']);
wrapperAnimation.addElement(root.querySelector('.popover-wrapper')!).duration(150).fromTo('opacity', 0.01, 1);
contentAnimation
.addElement(contentEl)
.beforeStyles({
top: `calc(${topValue} + var(--offset-y, 0px))`,
left: `calc(${leftValue} + var(--offset-x, 0px))`,
'transform-origin': `${originY} ${originX}`,
})
.beforeAddWrite(() => {
if (bottom !== undefined) {
let bottomValue = `${bottom}px`;
if (checkSafeAreaBottom) {
bottomValue = `${bottom}px + var(--ion-safe-area-bottom, 0px)`;
}
contentEl.style.setProperty('bottom', `calc(${bottomValue})`);
}
})
.fromTo('transform', 'scale(0.8)', 'scale(1)');
viewportAnimation.addElement(root.querySelector('.popover-viewport')!).fromTo('opacity', 0.01, 1);
return baseAnimation
.easing('cubic-bezier(0.36,0.66,0.04,1)')
.duration(300)
.beforeAddWrite(() => {
if (size === 'cover') {
baseEl.style.setProperty('--width', `${contentWidth}px`);
}
if (addPopoverBottomClass) {
baseEl.classList.add('popover-bottom');
}
})
.addAnimation([backdropAnimation, wrapperAnimation, contentAnimation, viewportAnimation]);
};