Skip to content

Commit 52f0398

Browse files
fadi-georgeclaude
andcommitted
fix(iam): re-show message when JS height check fails on rotation
Also keep the message view's insets in sync on layout, log the chosen scene window and insets, and note that region frames include margins. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 7827c0a commit 52f0398

2 files changed

Lines changed: 14 additions & 2 deletions

File tree

‎iOS_SDK/OneSignalSDK/OneSignalInAppMessages/UI/OSInAppMessageView.m‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,9 @@ - (void)resetWebViewToMaxBoundsAndResizeHeight:(void (^) (NSNumber *newHeight))
155155
if (error) {
156156
NSString *errorMessage = [NSString stringWithFormat:@"Javascript Method: %@ Evaluated with Error: %@", OS_JS_GET_PAGE_META_DATA_METHOD, error];
157157
[OneSignalLog onesignalLog:ONE_S_LL_ERROR message:errorMessage];
158+
// Still complete so a rotation or fold re-shows the message at its previous height
159+
[self setupWebViewConstraints];
160+
completion(nil);
158161
return;
159162
}
160163
NSString *successMessage = [NSString stringWithFormat:@"Javascript Method: %@ Evaluated with Success: %@", OS_JS_GET_PAGE_META_DATA_METHOD, result];

‎iOS_SDK/OneSignalSDK/OneSignalInAppMessages/UI/OSInAppMessageViewController.m‎

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -420,6 +420,7 @@ - (UIView *)sceneView {
420420
// Each side uses the larger of the margin and its safe area inset, and on iOS 27.1+ keeps the margin
421421
// from hardware inside a side safe area (e.g. a foldable's camera), matching system notification banners.
422422
// Regions flush with the edge, like a status bar column, are already covered by the safe area.
423+
// Region frames already include UIKit's interactive margins; the message margin is added on top.
423424
- (UIEdgeInsets)horizontalInsets {
424425
UIView *sceneView = [self sceneView];
425426
CGFloat margin = self.useWidthMargin ? [OneSignalCoreHelper sizeToScale:MESSAGE_MARGIN] : 0;
@@ -451,6 +452,7 @@ - (void)updateHorizontalInsets {
451452
return;
452453
}
453454
UIEdgeInsets insets = [self horizontalInsets];
455+
self.messageView.horizontalInsets = insets;
454456
// Only assign changes, since this runs on every layout pass
455457
if (self.leftConstraint.constant != insets.left) {
456458
self.leftConstraint.constant = insets.left;
@@ -505,6 +507,11 @@ - (void)addConstraintsForMessage {
505507
[OneSignalLog onesignalLog:ONE_S_LL_VERBOSE message:screenScale];
506508
let heightMessage = [NSString stringWithFormat:@"In App Message Height: %f", self.message.height.doubleValue];
507509
[OneSignalLog onesignalLog:ONE_S_LL_VERBOSE message:heightMessage];
510+
UIView *sceneView = [self sceneView];
511+
let layoutMessage = [NSString stringWithFormat:@"In App Message layout: scene view %@ (level %.0f) bounds %@ safe area %@ horizontal insets %@",
512+
NSStringFromClass(sceneView.class), sceneView.window.windowLevel, NSStringFromCGRect(sceneView.bounds),
513+
NSStringFromUIEdgeInsets(sceneView.safeAreaInsets), NSStringFromUIEdgeInsets([self horizontalInsets])];
514+
[OneSignalLog onesignalLog:ONE_S_LL_VERBOSE message:layoutMessage];
508515

509516
// Height constraint based on the IAM being full screen or any others with a specific height
510517
// NOTE: full screen IAM payload has no height, so match screen height minus margins
@@ -984,8 +991,10 @@ - (void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id <UIV
984991
[self.messageView resetWebViewToMaxBoundsAndResizeHeight:^(NSNumber *newHeight) {
985992
[OneSignalLog onesignalLog:ONE_S_LL_VERBOSE message:@"Orientation Change Complete with New Height: Adding constraints again and showing IAM"];
986993

987-
// Assign new height to message
988-
self.message.height = newHeight;
994+
// Keep the previous height if JS couldn't measure the page
995+
if (newHeight) {
996+
self.message.height = newHeight;
997+
}
989998

990999
// Add all of the constraints using the new message height obtained from JS code
9911000
[self addConstraintsForMessage];

0 commit comments

Comments
 (0)