@@ -93,13 +93,9 @@ @interface OSInAppMessageViewController ()
9393// BOOL to track if the message content has loaded before tags have finished loading for liquid templating
9494@property (nonatomic , nullable ) NSString *pendingHTMLContent;
9595
96- @property (nonatomic ) double leftMarginModifier ;
96+ @property (nonatomic ) BOOL useHeightMargin ;
9797
98- @property (nonatomic ) double rightMarginModifier;
99-
100- @property (nonatomic ) double topMarginModifier;
101-
102- @property (nonatomic ) double bottomMarginModifier;
98+ @property (nonatomic ) BOOL useWidthMargin;
10399
104100@end
105101
@@ -109,10 +105,8 @@ - (instancetype _Nonnull)initWithMessage:(OSInAppMessage *)inAppMessage delegate
109105 if (self = [super init ]) {
110106 self.message = inAppMessage;
111107 self.delegate = delegate;
112- self.topMarginModifier = 1.0 ;
113- self.bottomMarginModifier = 1.0 ;
114- self.leftMarginModifier = 1.0 ;
115- self.rightMarginModifier = 1.0 ;
108+ self.useHeightMargin = YES ;
109+ self.useWidthMargin = YES ;
116110 }
117111
118112 return self;
@@ -260,17 +254,11 @@ - (void)parseContentData:(NSDictionary *)data {
260254 if (styles) {
261255 // We are currently only allowing default margin or no margin.
262256 // If we receive a number that isn't 0 we want to use default margin for now.
263- if (styles[@" top_margin" ]) {
264- self.topMarginModifier = [styles[@" top_margin" ] doubleValue ] == 0 ? 0 : 1.0 ;
265- }
266- if (styles[@" bottom_margin" ]) {
267- self.bottomMarginModifier = [styles[@" bottom_margin" ] doubleValue ] == 0 ? 0 : 1.0 ;
268- }
269- if (styles[@" left_margin" ]) {
270- self.leftMarginModifier = [styles[@" left_margin" ] doubleValue ] == 0 ? 0 : 1.0 ;
257+ if (styles[@" remove_height_margin" ]) {
258+ self.useHeightMargin = ![styles[@" remove_height_margin" ] boolValue ];
271259 }
272- if (styles[@" right_margin " ]) {
273- self.rightMarginModifier = [styles[@" right_margin " ] doubleValue ] == 0 ? 0 : 1.0 ;
260+ if (styles[@" remove_width_margin " ]) {
261+ self.useWidthMargin = ! [styles[@" remove_width_margin " ] boolValue ] ;
274262 }
275263 }
276264}
@@ -349,18 +337,18 @@ - (void)addConstraintsForMessage {
349337 // Height constraint based on the IAM being full screen or any others with a specific height
350338 // NOTE: full screen IAM payload has no height, so match screen height minus margins
351339 if (self.message .position == OSInAppMessageDisplayPositionFullScreen)
352- self.heightConstraint = [self .messageView.heightAnchor constraintEqualToAnchor: height multiplier: 1.0 constant: (self .topMarginModifier * -marginSpacing) + ( self .bottomMarginModifier * -marginSpacing )];
340+ self.heightConstraint = [self .messageView.heightAnchor constraintEqualToAnchor: height multiplier: 1.0 constant: (self .useHeightMargin ? ( 2 * -marginSpacing) : 0 )];
353341 else
354342 self.heightConstraint = [self .messageView.heightAnchor constraintEqualToConstant: self .message.height.doubleValue];
355343
356344 // The aspect ratio for each type (ie. Banner) determines the height normally
357345 // However the actual height of the HTML content takes priority.
358346 // Makes sure our webview is never taller than our screen.
359- [self .messageView.heightAnchor constraintLessThanOrEqualToAnchor: height multiplier: 1.0 constant: (self .topMarginModifier * -marginSpacing) + ( self .bottomMarginModifier * -marginSpacing )].active = true ;
347+ [self .messageView.heightAnchor constraintLessThanOrEqualToAnchor: height multiplier: 1.0 constant: (self .useHeightMargin ? ( 2 * -marginSpacing) : 0 )].active = true ;
360348
361349 // Pins the message view to the left & right
362- let leftConstraint = [self .messageView.leadingAnchor constraintEqualToAnchor: leading constant: marginSpacing * self .leftMarginModifier ];
363- let rightConstraint = [self .messageView.trailingAnchor constraintEqualToAnchor: trailing constant: -marginSpacing * self .rightMarginModifier ];
350+ let leftConstraint = [self .messageView.leadingAnchor constraintEqualToAnchor: leading constant: ( self .useWidthMargin ? marginSpacing : 0 ) ];
351+ let rightConstraint = [self .messageView.trailingAnchor constraintEqualToAnchor: trailing constant: ( self .useWidthMargin ? -marginSpacing : 0 ) ];
364352
365353 // Ensure the message view is always centered horizontally
366354 [self .messageView.centerXAnchor constraintEqualToAnchor: center].active = true ;
@@ -384,9 +372,9 @@ - (void)addConstraintsForMessage {
384372
385373 self.initialYConstraint = [self .messageView.bottomAnchor constraintEqualToAnchor: self .view.topAnchor constant: -8 .0f ];
386374 self.finalYConstraint = [self .messageView.topAnchor constraintEqualToAnchor: top
387- constant: marginSpacing * self .topMarginModifier ];
375+ constant: ( self .useHeightMargin ? marginSpacing : 0 ) ];
388376 self.panVerticalConstraint = [self .messageView.topAnchor constraintEqualToAnchor: top
389- constant: marginSpacing * self .topMarginModifier ];
377+ constant: ( self .useHeightMargin ? marginSpacing : 0 ) ];
390378 break ;
391379 case OSInAppMessageDisplayPositionBottom:
392380 if (@available (iOS 11 , *)) {
@@ -398,9 +386,9 @@ - (void)addConstraintsForMessage {
398386
399387 self.initialYConstraint = [self .messageView.topAnchor constraintEqualToAnchor: self .view.bottomAnchor constant: 8 .0f ];
400388 self.finalYConstraint = [self .messageView.bottomAnchor constraintEqualToAnchor: bottom
401- constant: -marginSpacing * self .bottomMarginModifier ];
389+ constant: ( self .useHeightMargin ? -marginSpacing : 0 ) ];
402390 self.panVerticalConstraint = [self .messageView.bottomAnchor constraintEqualToAnchor: bottom
403- constant: -marginSpacing * self .bottomMarginModifier ];
391+ constant: ( self .useHeightMargin ? -marginSpacing : 0 ) ];
404392 break ;
405393 case OSInAppMessageDisplayPositionFullScreen:
406394 case OSInAppMessageDisplayPositionCenterModal:
0 commit comments