Skip to content

Commit 225ab8b

Browse files
authored
Fix/html inapp iphonex landscape/e2 162 (#146)
1 parent fbeffc9 commit 225ab8b

File tree

1 file changed

+24
-4
lines changed

1 file changed

+24
-4
lines changed

Leanplum-SDK/Classes/LPMessageTemplates.m

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -671,10 +671,13 @@ - (void)showPopup
671671
[self->_popupGroup setAlpha:1.0];
672672
}];
673673

674+
#if LP_NOT_TV
674675
[[NSNotificationCenter defaultCenter] addObserver:self
675676
selector:@selector(orientationDidChange:)
676-
name:UIApplicationDidChangeStatusBarOrientationNotification
677+
name:UIDeviceOrientationDidChangeNotification
677678
object:nil];
679+
#endif
680+
678681
}
679682

680683
- (void)setupPopupLayout:(BOOL)isFullscreen isPushAskToAsk:(BOOL)isPushAskToAsk
@@ -1036,8 +1039,9 @@ - (void)updateHtmlLayoutWithContext:(LPActionContext *)context
10361039
// Calculate the height. Fullscreen by default.
10371040
CGFloat htmlHeight = [[context numberNamed:LPMT_ARG_HTML_HEIGHT] doubleValue];
10381041
BOOL isFullscreen = htmlHeight < 1;
1039-
BOOL isIPhoneX = statusBarHeight > 40;
1040-
CGFloat bottomSafeAreaHeight = [self safeAreaInsets].bottom;
1042+
UIEdgeInsets safeAreaInsets = [self safeAreaInsets];
1043+
CGFloat bottomSafeAreaHeight = safeAreaInsets.bottom;
1044+
BOOL isIPhoneX = statusBarHeight > 40 || safeAreaInsets.left > 40 || safeAreaInsets.right > 40;
10411045

10421046
// Banner logic.
10431047
if (!isFullscreen) {
@@ -1085,7 +1089,23 @@ - (void)updateHtmlLayoutWithContext:(LPActionContext *)context
10851089
_popupGroup.frame = CGRectMake(htmlX, htmlY, htmlWidth, htmlHeight);
10861090

10871091
} else if (isIPhoneX) {
1088-
_popupGroup.frame = CGRectMake(0, -statusBarHeight, screenWidth, screenHeight+statusBarHeight+bottomSafeAreaHeight);
1092+
// Do not offset the bottom safe area (control panel) on landscape.
1093+
// Safe area is present on left and right on landscape.
1094+
CGFloat leftSafeAreaHeight = safeAreaInsets.left;
1095+
#if LP_NOT_TV
1096+
UIInterfaceOrientation orientation = [UIApplication sharedApplication].statusBarOrientation;
1097+
if (orientation == UIInterfaceOrientationLandscapeRight ||
1098+
orientation == UIInterfaceOrientationLandscapeLeft) {
1099+
bottomSafeAreaHeight = 0;
1100+
leftSafeAreaHeight += safeAreaInsets.right;
1101+
}
1102+
#endif
1103+
_popupGroup.frame = CGRectMake(-leftSafeAreaHeight, -safeAreaInsets.top,
1104+
screenWidth+safeAreaInsets.left+safeAreaInsets.right,
1105+
screenHeight+safeAreaInsets.top+bottomSafeAreaHeight);
1106+
NSLog( @"%@", NSStringFromCGRect(_popupGroup.frame) );
1107+
NSLog(@"%f, %f", screenWidth, screenHeight);
1108+
NSLog(@"%@", NSStringFromUIEdgeInsets(safeAreaInsets));
10891109
}
10901110

10911111
_popupView.frame = _popupGroup.bounds;

0 commit comments

Comments
 (0)