@@ -955,7 +955,7 @@ - (void)updatePopupLayout
955955 BOOL isWeb = [context.actionName isEqualToString: LPMT_WEB_INTERSTITIAL_NAME] ||
956956 [context.actionName isEqualToString: LPMT_HTML_NAME];
957957
958- int statusBarHeight = ([[UIApplication sharedApplication ] isStatusBarHidden ] || !fullscreen) ? 0
958+ CGFloat statusBarHeight = ([[UIApplication sharedApplication ] isStatusBarHidden ] || !fullscreen) ? 0
959959 : MIN ([UIApplication sharedApplication ].statusBarFrame .size .height ,
960960 [UIApplication sharedApplication ].statusBarFrame .size .width );
961961
@@ -990,57 +990,67 @@ - (void)updatePopupLayout
990990 CGSize screenSize = window.screen .bounds .size ;
991991 _popupGroup.frame = CGRectMake (0 , 0 , screenSize.width , screenSize.height );
992992
993- int screenWidth;
994- int screenHeight;
993+ CGFloat screenWidth = screenSize. width ;
994+ CGFloat screenHeight = screenSize. height ;
995995 if (orientation == UIDeviceOrientationLandscapeLeft ||
996996 orientation == UIDeviceOrientationLandscapeRight) {
997997 screenWidth = screenSize.height ;
998998 screenHeight = screenSize.width ;
999- } else {
1000- screenWidth = screenSize.width ;
1001- screenHeight = screenSize.height ;
1002999 }
1003- CGRect popupFrame;
1004- if (fullscreen) {
1005- popupFrame = CGRectMake (0 , 0 , screenWidth, screenHeight);
1006- } else {
1007- popupFrame = CGRectMake (0 , 0 ,
1008- [[context numberNamed: LPMT_ARG_LAYOUT_WIDTH] doubleValue ],
1009- [[context numberNamed: LPMT_ARG_LAYOUT_HEIGHT] doubleValue ]);
1000+
1001+ _popupView.frame = CGRectMake (0 , 0 , screenWidth, screenHeight);
1002+ if (!fullscreen) {
1003+ _popupView.frame = CGRectMake (0 , 0 , [[context numberNamed: LPMT_ARG_LAYOUT_WIDTH] doubleValue ],
1004+ [[context numberNamed: LPMT_ARG_LAYOUT_HEIGHT] doubleValue ]);
10101005 }
1011- _popupView.frame = popupFrame;
10121006 _popupView.center = CGPointMake (screenWidth / 2.0 , screenHeight / 2.0 );
10131007
10141008 if ([context.actionName isEqualToString: LPMT_HTML_NAME]) {
1015- // Calculate the height. Fullscreen by default.
1016- CGFloat contextArgHeight = [[context numberNamed: LPMT_ARG_HTML_HEIGHT] doubleValue ];
1017- CGFloat htmlHeight = contextArgHeight;
1018- if (htmlHeight < 1 ) {
1019- htmlHeight = screenHeight;
1020- }
1021-
1022- // Status bar offset.
1023- CGFloat statusBarOffset = 0 ;
1024- #if LP_NOT_TV
1025- UIApplication *app = [UIApplication sharedApplication ];
1026- if (!app.statusBarHidden ) {
1027- statusBarOffset = app.statusBarFrame .size .height ;
1028- }
1029- #endif
1030-
1009+ [self updateHtmlLayoutWithContext: context
1010+ statusBarHeight: statusBarHeight
1011+ screenWidth: screenWidth
1012+ screenHeight: screenHeight];
1013+ }
1014+
1015+ if (!isWeb) {
1016+ [self updateNonWebPopupLayout: statusBarHeight];
1017+ _overlayView.frame = CGRectMake (0 , 0 , screenWidth, screenHeight);
1018+ }
1019+
1020+ CGFloat dismissButtonX = screenWidth - _dismissButton.frame .size .width - LPMT_ACCEPT_BUTTON_MARGIN / 2 ;
1021+ CGFloat dismissButtonY = statusBarHeight + LPMT_ACCEPT_BUTTON_MARGIN / 2 ;
1022+ if (!fullscreen) {
1023+ dismissButtonX = _popupView.frame .origin .x + _popupView.frame .size .width - 3 * _dismissButton.frame .size .width / 4 ;
1024+ dismissButtonY = _popupView.frame .origin .y - _dismissButton.frame .size .height / 4 ;
1025+ }
1026+ _dismissButton.frame = CGRectMake (dismissButtonX, dismissButtonY, _dismissButton.frame .size .width ,
1027+ _dismissButton.frame .size .height );
1028+ }
1029+
1030+ - (void )updateHtmlLayoutWithContext : (LPActionContext *)context
1031+ statusBarHeight : (CGFloat)statusBarHeight
1032+ screenWidth : (CGFloat)screenWidth
1033+ screenHeight : (CGFloat)screenHeight
1034+ {
1035+ // Calculate the height. Fullscreen by default.
1036+ CGFloat htmlHeight = [[context numberNamed: LPMT_ARG_HTML_HEIGHT] doubleValue ];
1037+ BOOL isFullscreen = htmlHeight < 1 ;
1038+
1039+ // Banner logic.
1040+ if (!isFullscreen) {
10311041 // Calculate Y Offset.
10321042 CGFloat yOffset = 0 ;
10331043 NSString *contextArgYOffset = [context stringNamed: LPMT_ARG_HTML_Y_OFFSET];
10341044 if (contextArgYOffset && [contextArgYOffset length ] > 0 ) {
1035- CGFloat percentRange = screenHeight - htmlHeight - statusBarOffset ;
1045+ CGFloat percentRange = screenHeight - htmlHeight - statusBarHeight ;
10361046 yOffset = [self valueFromHtmlString: contextArgYOffset percentRange: percentRange];
10371047 }
10381048
10391049 // HTML banner logic to support top/bottom alignment with dynamic size.
1040- CGFloat htmlY = yOffset + statusBarOffset ;
1050+ CGFloat htmlY = yOffset + statusBarHeight ;
10411051 NSString *htmlAlign = [context stringNamed: LPMT_ARG_HTML_ALIGN];
10421052 if ([htmlAlign isEqualToString: LPMT_ARG_HTML_ALIGN_BOTTOM]) {
1043- htmlY = screenHeight - htmlHeight - yOffset - statusBarOffset ;
1053+ htmlY = screenHeight - htmlHeight - yOffset - statusBarHeight ;
10441054 }
10451055
10461056 // Calculate HTML width by percentage or px (it parses any suffix for extra protection).
@@ -1056,35 +1066,18 @@ - (void)updatePopupLayout
10561066 [self dismiss ];
10571067 [_closePopupView removeFromSuperview ];
10581068 }];
1059- _closePopupView.frame = CGRectMake (0 , 0 , screenSize. width , screenSize. height );
1069+ _closePopupView.frame = CGRectMake (0 , 0 , screenWidth, screenHeight );
10601070 [[UIApplication sharedApplication ].keyWindow addSubview: _closePopupView];
10611071 [[UIApplication sharedApplication ].keyWindow bringSubviewToFront: _popupGroup];
10621072 }
1063-
1073+
10641074 CGFloat htmlX = (screenWidth - htmlWidth) / 2 .;
10651075 _popupGroup.frame = CGRectMake (htmlX, htmlY, htmlWidth, htmlHeight);
1066- _popupView.frame = _popupGroup.bounds ;
1067- }
1068-
1069- if (!isWeb) {
1070- [self updateNonWebPopupLayout: statusBarHeight];
1071- }
1072-
1073- if (fullscreen) {
1074- _dismissButton.frame = CGRectMake (screenWidth - _dismissButton.frame .size .width - LPMT_ACCEPT_BUTTON_MARGIN / 2 ,
1075- statusBarHeight + LPMT_ACCEPT_BUTTON_MARGIN / 2 ,
1076- _dismissButton.frame .size .width ,
1077- _dismissButton.frame .size .height );
1078- } else {
1079- _dismissButton.frame = CGRectMake (_popupView.frame .origin .x + _popupView.frame .size .width - 3 * _dismissButton.frame .size .width / 4 ,
1080- _popupView.frame .origin .y - _dismissButton.frame .size .height / 4 ,
1081- _dismissButton.frame .size .width ,
1082- _dismissButton.frame .size .height );
1076+ } else if (statusBarHeight > 40 ) { // iPhone X
1077+ _popupGroup.frame = CGRectMake (0 , -statusBarHeight, screenWidth, screenHeight+2 *statusBarHeight);
10831078 }
10841079
1085- if (!isWeb) {
1086- _overlayView.frame = CGRectMake (0 , 0 , screenWidth, screenHeight);
1087- }
1080+ _popupView.frame = _popupGroup.bounds ;
10881081}
10891082
10901083/* *
0 commit comments