Skip to content

Commit f933edf

Browse files
authored
fix(message): HTML Y inconsistency with iPhoneX on bottom aligned (#136) E2-69
1 parent e903a8b commit f933edf

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

Leanplum-SDK/Classes/LPMessageTemplates.m

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1035,6 +1035,11 @@ - (void)updateHtmlLayoutWithContext:(LPActionContext *)context
10351035
// Calculate the height. Fullscreen by default.
10361036
CGFloat htmlHeight = [[context numberNamed:LPMT_ARG_HTML_HEIGHT] doubleValue];
10371037
BOOL isFullscreen = htmlHeight < 1;
1038+
BOOL isIPhoneX = statusBarHeight > 40;
1039+
CGFloat bottomSafeAreaHeight = 0;
1040+
if (@available(iOS 11.0, *)) {
1041+
bottomSafeAreaHeight = [UIApplication sharedApplication].keyWindow.safeAreaInsets.bottom;
1042+
}
10381043

10391044
// Banner logic.
10401045
if (!isFullscreen) {
@@ -1050,7 +1055,7 @@ - (void)updateHtmlLayoutWithContext:(LPActionContext *)context
10501055
CGFloat htmlY = yOffset + statusBarHeight;
10511056
NSString *htmlAlign = [context stringNamed:LPMT_ARG_HTML_ALIGN];
10521057
if ([htmlAlign isEqualToString:LPMT_ARG_HTML_ALIGN_BOTTOM]) {
1053-
htmlY = screenHeight - htmlHeight - yOffset - statusBarHeight;
1058+
htmlY = screenHeight - htmlHeight - yOffset;
10541059
}
10551060

10561061
// Calculate HTML width by percentage or px (it parses any suffix for extra protection).
@@ -1072,9 +1077,17 @@ - (void)updateHtmlLayoutWithContext:(LPActionContext *)context
10721077
}
10731078

10741079
CGFloat htmlX = (screenWidth - htmlWidth) / 2.;
1080+
// Offset iPhoneX's safe area.
1081+
if (isIPhoneX) {
1082+
CGFloat bottomDistance = screenHeight - (htmlY + htmlHeight);
1083+
if (bottomDistance < bottomSafeAreaHeight) {
1084+
htmlHeight += bottomSafeAreaHeight;
1085+
}
1086+
}
10751087
_popupGroup.frame = CGRectMake(htmlX, htmlY, htmlWidth, htmlHeight);
1076-
} else if (statusBarHeight > 40) { // iPhone X
1077-
_popupGroup.frame = CGRectMake(0, -statusBarHeight, screenWidth, screenHeight+2*statusBarHeight);
1088+
1089+
} else if (isIPhoneX) {
1090+
_popupGroup.frame = CGRectMake(0, -statusBarHeight, screenWidth, screenHeight+statusBarHeight+bottomSafeAreaHeight);
10781091
}
10791092

10801093
_popupView.frame = _popupGroup.bounds;

0 commit comments

Comments
 (0)