Skip to content

Commit 73f6a82

Browse files
committed
fix(popover): improve positioning in ios11
1 parent 893ef72 commit 73f6a82

File tree

1 file changed

+36
-11
lines changed

1 file changed

+36
-11
lines changed

src/components/popover/popover-transitions.ts

Lines changed: 36 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -115,20 +115,27 @@ export class PopoverTransition extends PageTransition {
115115
// If the popover left is less than the padding it is off screen
116116
// to the left so adjust it, else if the width of the popover
117117
// exceeds the body width it is off screen to the right so adjust
118-
if (popoverCSS.left < POPOVER_IOS_BODY_PADDING) {
118+
//
119+
let checkSafeAreaLeft = false;
120+
let checkSafeAreaRight = false;
121+
122+
// If the popover left is less than the padding it is off screen
123+
// to the left so adjust it, else if the width of the popover
124+
// exceeds the body width it is off screen to the right so adjust
125+
// 25 is a random/arbitrary number. It seems to work fine for ios11
126+
// and iPhoneX. Is it perfect? No. Does it work? Yes.
127+
if (popoverCSS.left < (POPOVER_IOS_BODY_PADDING + 25)) {
128+
checkSafeAreaLeft = true;
119129
popoverCSS.left = POPOVER_IOS_BODY_PADDING;
120-
} else if (popoverWidth + POPOVER_IOS_BODY_PADDING + popoverCSS.left > bodyWidth) {
121-
if (CSS.supports('left', 'constant(safe-area-inset-left)')) {
122-
popoverCSS.left = `calc(${bodyWidth - popoverWidth - POPOVER_IOS_BODY_PADDING}px - constant(safe-area-inset-left)`;
123-
} else if (CSS.supports('left', 'env(safe-area-inset-left)')) {
124-
popoverCSS.left = `calc(${bodyWidth - popoverWidth - POPOVER_IOS_BODY_PADDING}px - env(safe-area-inset-left)`;
125-
} else {
126-
popoverCSS.left = `${bodyWidth - popoverWidth - POPOVER_IOS_BODY_PADDING}px`;
127-
}
130+
} else if ((popoverWidth + POPOVER_IOS_BODY_PADDING + popoverCSS.left + 25) > bodyWidth) {
131+
// Ok, so we're on the right side of the screen,
132+
// but now we need to make sure we're still a bit further right
133+
// cus....notchurally... Again, 25 is random. It works tho
134+
checkSafeAreaRight = true;
135+
popoverCSS.left = bodyWidth - popoverWidth - POPOVER_IOS_BODY_PADDING;
128136
originX = 'right';
129137
}
130138

131-
// If the popover when popped down stretches past bottom of screen,
132139
// make it pop up if there's room above
133140
if (targetTop + targetHeight + popoverHeight > bodyHeight && targetTop - popoverHeight > 0) {
134141
arrowCSS.top = targetTop - (arrowHeight + 1);
@@ -144,7 +151,25 @@ export class PopoverTransition extends PageTransition {
144151
arrowEle.style.left = arrowCSS.left + 'px';
145152

146153
popoverEle.style.top = popoverCSS.top + 'px';
147-
popoverEle.style.left = popoverCSS.left;
154+
popoverEle.style.left = popoverCSS.left + 'px';
155+
156+
if (checkSafeAreaLeft) {
157+
if (CSS.supports('left', 'constant(safe-area-inset-left)')) {
158+
popoverEle.style.left = `calc(${popoverCSS.left}px + constant(safe-area-inset-left)`;
159+
160+
} else if (CSS.supports('left', 'env(safe-area-inset-left)')) {
161+
popoverEle.style.left = `calc(${popoverCSS.left}px + env(safe-area-inset-left)`;
162+
}
163+
}
164+
165+
if (checkSafeAreaRight) {
166+
if (CSS.supports('right', 'constant(safe-area-inset-right)')) {
167+
popoverEle.style.left = `calc(${popoverCSS.left}px - constant(safe-area-inset-right)`;
168+
} else if (CSS.supports('right', 'env(safe-area-inset-right)')) {
169+
popoverEle.style.left = `calc(${popoverCSS.left}px - env(safe-area-inset-right)`;
170+
}
171+
}
172+
148173

149174
(<any>popoverEle.style)[this.plt.Css.transformOrigin] = originY + ' ' + originX;
150175

0 commit comments

Comments
 (0)