Skip to content

Commit 25b0c77

Browse files
authored
feat(message): Custom width for Banner LP-4381
1 parent 458baf5 commit 25b0c77

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

Leanplum-SDK/Classes/LPMessageTemplates.m

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@
7777
#define LPMT_ARG_LAYOUT_WIDTH @"Layout.Width"
7878
#define LPMT_ARG_LAYOUT_HEIGHT @"Layout.Height"
7979
#define LPMT_ARG_HTML_HEIGHT @"HTML Height"
80+
#define LPMT_ARG_HTML_WIDTH @"HTML Width"
8081
#define LPMT_ARG_HTML_ALIGN @"HTML Align"
8182
#define LPMT_ARG_HTML_ALIGN_TOP @"Top"
8283
#define LPMT_ARG_HTML_ALIGN_BOTTOM @"Bottom"
@@ -454,6 +455,7 @@ - (void)defineActions
454455
withString:LPMT_DEFAULT_TRACK_ACTION_URL],
455456
[LPActionArg argNamed:LPMT_ARG_HTML_ALIGN withString:LPMT_ARG_HTML_ALIGN_TOP],
456457
[LPActionArg argNamed:LPMT_ARG_HTML_HEIGHT withNumber:@0],
458+
[LPActionArg argNamed:LPMT_ARG_HTML_WIDTH withString:@"100%"],
457459
[LPActionArg argNamed:LPMT_HAS_DISMISS_BUTTON withBool:NO],
458460
[LPActionArg argNamed:LPMT_ARG_HTML_TEMPLATE withFile:nil]]
459461
withResponder:messageResponder];
@@ -981,8 +983,24 @@ - (void)updatePopupLayout
981983
htmlY += app.statusBarFrame.size.height;
982984
}
983985
#endif
986+
987+
// Calculate HTML width by percentage or px (it parses any suffix for extra protection).
988+
NSString *contextArgWidth = [context stringNamed:LPMT_ARG_HTML_WIDTH] ?: @"100%";
989+
CGFloat htmlWidth = screenWidth;
990+
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+
}
1000+
}
9841001

985-
_popupGroup.frame = CGRectMake(0, htmlY, screenWidth, htmlHeight);
1002+
CGFloat htmlX = (screenWidth - htmlWidth) / 2.;
1003+
_popupGroup.frame = CGRectMake(htmlX, htmlY, htmlWidth, htmlHeight);
9861004
_popupView.frame = _popupGroup.bounds;
9871005
}
9881006

0 commit comments

Comments
 (0)