|
79 | 79 | #define LPMT_ARG_HTML_HEIGHT @"HTML Height" |
80 | 80 | #define LPMT_ARG_HTML_WIDTH @"HTML Width" |
81 | 81 | #define LPMT_ARG_HTML_ALIGN @"HTML Align" |
| 82 | +#define LPMT_ARG_HTML_Y_OFFSET @"HTML Y Offset" |
82 | 83 | #define LPMT_ARG_HTML_ALIGN_TOP @"Top" |
83 | 84 | #define LPMT_ARG_HTML_ALIGN_BOTTOM @"Bottom" |
84 | 85 | #define LPMT_ARG_APP_ICON @"__iOSAppIcon" |
@@ -456,6 +457,7 @@ - (void)defineActions |
456 | 457 | [LPActionArg argNamed:LPMT_ARG_HTML_ALIGN withString:LPMT_ARG_HTML_ALIGN_TOP], |
457 | 458 | [LPActionArg argNamed:LPMT_ARG_HTML_HEIGHT withNumber:@0], |
458 | 459 | [LPActionArg argNamed:LPMT_ARG_HTML_WIDTH withString:@"100%"], |
| 460 | + [LPActionArg argNamed:LPMT_ARG_HTML_Y_OFFSET withString:@"0px"], |
459 | 461 | [LPActionArg argNamed:LPMT_HAS_DISMISS_BUTTON withBool:NO], |
460 | 462 | [LPActionArg argNamed:LPMT_ARG_HTML_TEMPLATE withFile:nil]] |
461 | 463 | withResponder:messageResponder]; |
@@ -964,39 +966,42 @@ - (void)updatePopupLayout |
964 | 966 | _popupView.center = CGPointMake(screenWidth / 2.0, screenHeight / 2.0); |
965 | 967 |
|
966 | 968 | if ([context.actionName isEqualToString:LPMT_HTML_NAME]) { |
967 | | - // HTML5 banner logic to support top/bottom alignment with dynamic size. |
| 969 | + // Calculate the height. Fullscreen by default. |
968 | 970 | CGFloat contextArgHeight = [[context numberNamed:LPMT_ARG_HTML_HEIGHT] doubleValue]; |
969 | 971 | CGFloat htmlHeight = contextArgHeight; |
970 | 972 | if (htmlHeight < 1) { |
971 | 973 | htmlHeight = screenHeight; |
972 | 974 | } |
973 | | - CGFloat htmlY = 0; |
974 | | - NSString *htmlAlign = [context stringNamed:LPMT_ARG_HTML_ALIGN]; |
975 | | - if ([htmlAlign isEqualToString:LPMT_ARG_HTML_ALIGN_BOTTOM]) { |
976 | | - htmlY = screenHeight - htmlHeight; |
977 | | - } |
| 975 | + |
| 976 | + // Status bar offset. |
| 977 | + CGFloat statusBarOffset = 0; |
978 | 978 | #if LP_NOT_TV |
979 | | - // Offset Banner if the status bar is present. |
980 | 979 | UIApplication *app = [UIApplication sharedApplication]; |
981 | | - if ([htmlAlign isEqualToString:LPMT_ARG_HTML_ALIGN_TOP] && |
982 | | - contextArgHeight > 1 && !app.statusBarHidden) { |
983 | | - htmlY += app.statusBarFrame.size.height; |
| 980 | + if (!app.statusBarHidden) { |
| 981 | + statusBarOffset = app.statusBarFrame.size.height; |
984 | 982 | } |
985 | 983 | #endif |
986 | 984 |
|
| 985 | + // Calculate Y Offset. |
| 986 | + CGFloat yOffset = 0; |
| 987 | + NSString *contextArgYOffset = [context stringNamed:LPMT_ARG_HTML_Y_OFFSET]; |
| 988 | + if (contextArgYOffset && [contextArgYOffset length] > 0) { |
| 989 | + CGFloat percentRange = screenHeight - htmlHeight - statusBarOffset; |
| 990 | + yOffset = [self valueFromHtmlString:contextArgYOffset percentRange:percentRange]; |
| 991 | + } |
| 992 | + |
| 993 | + // HTML banner logic to support top/bottom alignment with dynamic size. |
| 994 | + CGFloat htmlY = yOffset + statusBarOffset; |
| 995 | + NSString *htmlAlign = [context stringNamed:LPMT_ARG_HTML_ALIGN]; |
| 996 | + if ([htmlAlign isEqualToString:LPMT_ARG_HTML_ALIGN_BOTTOM]) { |
| 997 | + htmlY = screenHeight - htmlHeight - yOffset - statusBarOffset; |
| 998 | + } |
| 999 | + |
987 | 1000 | // Calculate HTML width by percentage or px (it parses any suffix for extra protection). |
988 | 1001 | NSString *contextArgWidth = [context stringNamed:LPMT_ARG_HTML_WIDTH] ?: @"100%"; |
989 | 1002 | CGFloat htmlWidth = screenWidth; |
990 | 1003 | if (contextArgWidth && [contextArgWidth length] > 0) { |
991 | | - if ([contextArgWidth hasSuffix:@"%"]) { |
992 | | - NSString *percentageValue = [contextArgWidth stringByReplacingOccurrencesOfString:@"%" |
993 | | - withString:@""]; |
994 | | - htmlWidth = screenWidth * [percentageValue floatValue] / 100.; |
995 | | - } else { |
996 | | - NSCharacterSet *letterSet = [NSCharacterSet letterCharacterSet]; |
997 | | - NSArray *components = [contextArgWidth componentsSeparatedByCharactersInSet:letterSet]; |
998 | | - htmlWidth = [[components componentsJoinedByString:@""] floatValue]; |
999 | | - } |
| 1004 | + htmlWidth = [self valueFromHtmlString:contextArgWidth percentRange:screenWidth]; |
1000 | 1005 | } |
1001 | 1006 |
|
1002 | 1007 | CGFloat htmlX = (screenWidth - htmlWidth) / 2.; |
@@ -1025,6 +1030,26 @@ - (void)updatePopupLayout |
1025 | 1030 | } |
1026 | 1031 | } |
1027 | 1032 |
|
| 1033 | +/** |
| 1034 | + * Get float value by parsing the html string that can have either % or px as a suffix. |
| 1035 | + */ |
| 1036 | +- (CGFloat)valueFromHtmlString:(NSString *)htmlString percentRange:(CGFloat)percentRange |
| 1037 | +{ |
| 1038 | + if (!htmlString || [htmlString length] == 0) { |
| 1039 | + return 0; |
| 1040 | + } |
| 1041 | + |
| 1042 | + if ([htmlString hasSuffix:@"%"]) { |
| 1043 | + NSString *percentageValue = [htmlString stringByReplacingOccurrencesOfString:@"%" |
| 1044 | + withString:@""]; |
| 1045 | + return percentRange * [percentageValue floatValue] / 100.; |
| 1046 | + } |
| 1047 | + |
| 1048 | + NSCharacterSet *letterSet = [NSCharacterSet letterCharacterSet]; |
| 1049 | + NSArray *components = [htmlString componentsSeparatedByCharactersInSet:letterSet]; |
| 1050 | + return [[components componentsJoinedByString:@""] floatValue]; |
| 1051 | +} |
| 1052 | + |
1028 | 1053 | - (CGSize)getTextSizeFromButton:(UIButton *)button |
1029 | 1054 | { |
1030 | 1055 | UIFont* font = button.titleLabel.font; |
|
0 commit comments