@@ -93,6 +93,10 @@ @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 ) BOOL useHeightMargin;
97+
98+ @property (nonatomic ) BOOL useWidthMargin;
99+
96100@end
97101
98102@implementation OSInAppMessageViewController
@@ -101,6 +105,8 @@ - (instancetype _Nonnull)initWithMessage:(OSInAppMessageInternal *)inAppMessage
101105 if (self = [super init ]) {
102106 self.message = inAppMessage;
103107 self.delegate = delegate;
108+ self.useHeightMargin = YES ;
109+ self.useWidthMargin = YES ;
104110 }
105111
106112 return self;
@@ -231,8 +237,7 @@ - (OSResultSuccessBlock)messageContentOnSuccess {
231237 [[OneSignal sessionManager ] onInAppMessageReceived: self .message.messageId];
232238
233239 let baseUrl = [NSURL URLWithString: OS_IAM_WEBVIEW_BASE_URL];
234- self.pendingHTMLContent = data[@" html" ];
235- self.maxDisplayTime = [data[@" display_duration" ] doubleValue ];
240+ [self parseContentData: data];
236241 if (self.waitForTags ) {
237242 return ;
238243 }
@@ -242,6 +247,22 @@ - (OSResultSuccessBlock)messageContentOnSuccess {
242247 };
243248}
244249
250+ - (void )parseContentData : (NSDictionary *)data {
251+ self.pendingHTMLContent = data[@" html" ];
252+ self.maxDisplayTime = [data[@" display_duration" ] doubleValue ];
253+ NSDictionary *styles = data[@" styles" ];
254+ if (styles) {
255+ // We are currently only allowing default margin or no margin.
256+ // If we receive a number that isn't 0 we want to use default margin for now.
257+ if (styles[@" remove_height_margin" ]) {
258+ self.useHeightMargin = ![styles[@" remove_height_margin" ] boolValue ];
259+ }
260+ if (styles[@" remove_width_margin" ]) {
261+ self.useWidthMargin = ![styles[@" remove_width_margin" ] boolValue ];
262+ }
263+ }
264+ }
265+
245266- (void )setWaitForTags : (BOOL )waitForTags {
246267 _waitForTags = waitForTags;
247268 if (!waitForTags && self.pendingHTMLContent ) {
@@ -321,18 +342,18 @@ - (void)addConstraintsForMessage {
321342 // Height constraint based on the IAM being full screen or any others with a specific height
322343 // NOTE: full screen IAM payload has no height, so match screen height minus margins
323344 if (self.message .position == OSInAppMessageDisplayPositionFullScreen)
324- self.heightConstraint = [self .messageView.heightAnchor constraintEqualToAnchor: height multiplier: 1.0 constant: - 2 . 0f * marginSpacing];
345+ self.heightConstraint = [self .messageView.heightAnchor constraintEqualToAnchor: height multiplier: 1.0 constant: ( self .useHeightMargin ? ( 2 *- marginSpacing) : 0 ) ];
325346 else
326347 self.heightConstraint = [self .messageView.heightAnchor constraintEqualToConstant: self .message.height.doubleValue];
327348
328349 // The aspect ratio for each type (ie. Banner) determines the height normally
329350 // However the actual height of the HTML content takes priority.
330351 // Makes sure our webview is never taller than our screen.
331- [self .messageView.heightAnchor constraintLessThanOrEqualToAnchor: height multiplier: 1.0 constant: - 2 . 0f * marginSpacing].active = true ;
352+ [self .messageView.heightAnchor constraintLessThanOrEqualToAnchor: height multiplier: 1.0 constant: ( self .useHeightMargin ? ( 2 *- marginSpacing) : 0 ) ].active = true ;
332353
333354 // Pins the message view to the left & right
334- let leftConstraint = [self .messageView.leadingAnchor constraintEqualToAnchor: leading constant: marginSpacing];
335- let rightConstraint = [self .messageView.trailingAnchor constraintEqualToAnchor: trailing constant: -marginSpacing];
355+ let leftConstraint = [self .messageView.leadingAnchor constraintEqualToAnchor: leading constant: ( self .useWidthMargin ? marginSpacing : 0 ) ];
356+ let rightConstraint = [self .messageView.trailingAnchor constraintEqualToAnchor: trailing constant: ( self .useWidthMargin ? -marginSpacing : 0 ) ];
336357
337358 // Ensure the message view is always centered horizontally
338359 [self .messageView.centerXAnchor constraintEqualToAnchor: center].active = true ;
@@ -355,8 +376,10 @@ - (void)addConstraintsForMessage {
355376 self.view .window .frame = CGRectMake (0 , 0 , bannerWidth, bannerHeight);
356377
357378 self.initialYConstraint = [self .messageView.bottomAnchor constraintEqualToAnchor: self .view.topAnchor constant: -8 .0f ];
358- self.finalYConstraint = [self .messageView.topAnchor constraintEqualToAnchor: top constant: marginSpacing];
359- self.panVerticalConstraint = [self .messageView.topAnchor constraintEqualToAnchor: top constant: marginSpacing];
379+ self.finalYConstraint = [self .messageView.topAnchor constraintEqualToAnchor: top
380+ constant: (self .useHeightMargin ? marginSpacing : 0 )];
381+ self.panVerticalConstraint = [self .messageView.topAnchor constraintEqualToAnchor: top
382+ constant: (self .useHeightMargin ? marginSpacing : 0 )];
360383 break ;
361384 case OSInAppMessageDisplayPositionBottom:
362385 if (@available (iOS 11 , *)) {
@@ -367,16 +390,23 @@ - (void)addConstraintsForMessage {
367390 self.view .window .frame = CGRectMake (0 , bannerMessageY, bannerWidth, bannerHeight);
368391
369392 self.initialYConstraint = [self .messageView.topAnchor constraintEqualToAnchor: self .view.bottomAnchor constant: 8 .0f ];
370- self.finalYConstraint = [self .messageView.bottomAnchor constraintEqualToAnchor: bottom constant: -marginSpacing];
371- self.panVerticalConstraint = [self .messageView.bottomAnchor constraintEqualToAnchor: bottom constant: -marginSpacing];
393+ self.finalYConstraint = [self .messageView.bottomAnchor constraintEqualToAnchor: bottom
394+ constant: (self .useHeightMargin ? -marginSpacing : 0 )];
395+ self.panVerticalConstraint = [self .messageView.bottomAnchor constraintEqualToAnchor: bottom
396+ constant: (self .useHeightMargin ? -marginSpacing : 0 )];
372397 break ;
373398 case OSInAppMessageDisplayPositionFullScreen:
374399 case OSInAppMessageDisplayPositionCenterModal:
375400 self.view .window .frame = mainBounds;
401+ NSLayoutAnchor *centerYanchor = self.view .centerYAnchor ;
402+ if (@available (iOS 11 , *)) {
403+ let safeArea = self.view .safeAreaLayoutGuide ;
404+ centerYanchor = safeArea.centerYAnchor ;
405+ }
376406
377- self.initialYConstraint = [self .messageView.centerYAnchor constraintEqualToAnchor: self .view.centerYAnchor constant: 0 .0f ];
378- self.finalYConstraint = [self .messageView.centerYAnchor constraintEqualToAnchor: self .view.centerYAnchor constant: 0 .0f ];
379- self.panVerticalConstraint = [self .messageView.centerYAnchor constraintEqualToAnchor: self .view.centerYAnchor constant: 0 .0f ];
407+ self.initialYConstraint = [self .messageView.centerYAnchor constraintEqualToAnchor: centerYanchor constant: 0 .0f ];
408+ self.finalYConstraint = [self .messageView.centerYAnchor constraintEqualToAnchor: centerYanchor constant: 0 .0f ];
409+ self.panVerticalConstraint = [self .messageView.centerYAnchor constraintEqualToAnchor: centerYanchor constant: 0 .0f ];
380410 self.messageView .transform = CGAffineTransformMakeScale (0 , 0 );
381411 break ;
382412 }
0 commit comments