Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/demo/App/Views/Components/LogView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ struct LogView: View {
entryList
}
.frame(maxWidth: .infinity)
.background(OS.Color.logBackground)
.background(OS.Color.logBackground, ignoresSafeAreaEdges: .horizontal)
.accessibilityElement(children: .contain)
.accessibilityIdentifier("log_view")
}
Expand Down
3 changes: 2 additions & 1 deletion examples/demo/App/Views/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@ struct ContentView: View {
// Android's `scrollIntoView` `scrollableElement` param.
.accessibilityIdentifier("main_scroll_view")
}
.background(OS.Color.lightBackground.ignoresSafeArea())
.background(OS.Color.lightBackground.ignoresSafeArea(edges: [.horizontal, .bottom]))
.background(OS.Color.primary.ignoresSafeArea())
.navigationBarTitleDisplayMode(.inline)
.toolbarBackground(OS.Color.primary, for: .navigationBar)
.toolbarBackground(.visible, for: .navigationBar)
Expand Down
24 changes: 24 additions & 0 deletions iOS_SDK/OneSignalSDK/OneSignal.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -634,6 +634,12 @@
DEBAAE552A42174A00BF2C1C /* OSInAppMessageView.h in Headers */ = {isa = PBXBuildFile; fileRef = DEBAAE512A42174A00BF2C1C /* OSInAppMessageView.h */; };
DEBAAE562A42174A00BF2C1C /* OSInAppMessageViewController.h in Headers */ = {isa = PBXBuildFile; fileRef = DEBAAE522A42174A00BF2C1C /* OSInAppMessageViewController.h */; };
DEBAAE572A42174A00BF2C1C /* OSInAppMessageView.m in Sources */ = {isa = PBXBuildFile; fileRef = DEBAAE532A42174A00BF2C1C /* OSInAppMessageView.m */; };
5C1A7E0D2FB0A00100AB0004 /* OSInAppMessageInsets.h in Headers */ = {isa = PBXBuildFile; fileRef = 5C1A7E0D2FB0A00100AB0001 /* OSInAppMessageInsets.h */; };
5C1A7E0D2FB0A00100AB0005 /* OSInAppMessageInsets.m in Sources */ = {isa = PBXBuildFile; fileRef = 5C1A7E0D2FB0A00100AB0002 /* OSInAppMessageInsets.m */; };
5C1A7E0D2FB0A00100AB0006 /* OSInAppMessageInsetsTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5C1A7E0D2FB0A00100AB0003 /* OSInAppMessageInsetsTests.swift */; };
5C1A7E0E2FB0A00100AB0004 /* OSInAppMessageScroll.h in Headers */ = {isa = PBXBuildFile; fileRef = 5C1A7E0E2FB0A00100AB0001 /* OSInAppMessageScroll.h */; };
5C1A7E0E2FB0A00100AB0005 /* OSInAppMessageScroll.m in Sources */ = {isa = PBXBuildFile; fileRef = 5C1A7E0E2FB0A00100AB0002 /* OSInAppMessageScroll.m */; };
5C1A7E0E2FB0A00100AB0006 /* OSInAppMessageScrollTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5C1A7E0E2FB0A00100AB0003 /* OSInAppMessageScrollTests.swift */; };
DEBAAE602A42175A00BF2C1C /* OSDynamicTriggerController.m in Sources */ = {isa = PBXBuildFile; fileRef = DEBAAE582A42175900BF2C1C /* OSDynamicTriggerController.m */; };
DEBAAE612A42175A00BF2C1C /* OSMessagingController.h in Headers */ = {isa = PBXBuildFile; fileRef = DEBAAE592A42175900BF2C1C /* OSMessagingController.h */; };
DEBAAE622A42175A00BF2C1C /* OSInAppMessageController.h in Headers */ = {isa = PBXBuildFile; fileRef = DEBAAE5A2A42175900BF2C1C /* OSInAppMessageController.h */; };
Expand Down Expand Up @@ -1860,6 +1866,12 @@
DEBAAE512A42174A00BF2C1C /* OSInAppMessageView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OSInAppMessageView.h; sourceTree = "<group>"; };
DEBAAE522A42174A00BF2C1C /* OSInAppMessageViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OSInAppMessageViewController.h; sourceTree = "<group>"; };
DEBAAE532A42174A00BF2C1C /* OSInAppMessageView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = OSInAppMessageView.m; sourceTree = "<group>"; };
5C1A7E0D2FB0A00100AB0001 /* OSInAppMessageInsets.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = OSInAppMessageInsets.h; sourceTree = "<group>"; };
5C1A7E0D2FB0A00100AB0002 /* OSInAppMessageInsets.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = OSInAppMessageInsets.m; sourceTree = "<group>"; };
5C1A7E0D2FB0A00100AB0003 /* OSInAppMessageInsetsTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OSInAppMessageInsetsTests.swift; sourceTree = "<group>"; };
5C1A7E0E2FB0A00100AB0001 /* OSInAppMessageScroll.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = OSInAppMessageScroll.h; sourceTree = "<group>"; };
5C1A7E0E2FB0A00100AB0002 /* OSInAppMessageScroll.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = OSInAppMessageScroll.m; sourceTree = "<group>"; };
5C1A7E0E2FB0A00100AB0003 /* OSInAppMessageScrollTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OSInAppMessageScrollTests.swift; sourceTree = "<group>"; };
DEBAAE582A42175900BF2C1C /* OSDynamicTriggerController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = OSDynamicTriggerController.m; sourceTree = "<group>"; };
DEBAAE592A42175900BF2C1C /* OSMessagingController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OSMessagingController.h; sourceTree = "<group>"; };
DEBAAE5A2A42175900BF2C1C /* OSInAppMessageController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OSInAppMessageController.h; sourceTree = "<group>"; };
Expand Down Expand Up @@ -2386,6 +2398,8 @@
3CB35FCA2F0FA20B000E6E0F /* OSMessagingControllerUserStateTests.swift */,
3C7021E72ECF0CF3001768C6 /* OneSignalInAppMessagesTests-Bridging-Header.h */,
67ECA2928D863073B785F93F /* IamFetchIdentityVerificationTests.swift */,
5C1A7E0D2FB0A00100AB0003 /* OSInAppMessageInsetsTests.swift */,
5C1A7E0E2FB0A00100AB0003 /* OSInAppMessageScrollTests.swift */,
);
path = OneSignalInAppMessagesTests;
sourceTree = "<group>";
Expand Down Expand Up @@ -3361,6 +3375,10 @@
DEBAAE532A42174A00BF2C1C /* OSInAppMessageView.m */,
DEBAAE522A42174A00BF2C1C /* OSInAppMessageViewController.h */,
DEBAAE502A42174A00BF2C1C /* OSInAppMessageViewController.m */,
5C1A7E0D2FB0A00100AB0001 /* OSInAppMessageInsets.h */,
5C1A7E0D2FB0A00100AB0002 /* OSInAppMessageInsets.m */,
5C1A7E0E2FB0A00100AB0001 /* OSInAppMessageScroll.h */,
5C1A7E0E2FB0A00100AB0002 /* OSInAppMessageScroll.m */,
);
path = UI;
sourceTree = "<group>";
Expand Down Expand Up @@ -3692,6 +3710,8 @@
DEBAAE662A42175A00BF2C1C /* OSDynamicTriggerController.h in Headers */,
DEBAAE642A42175A00BF2C1C /* OSTriggerController.h in Headers */,
DEBAAE562A42174A00BF2C1C /* OSInAppMessageViewController.h in Headers */,
5C1A7E0D2FB0A00100AB0004 /* OSInAppMessageInsets.h in Headers */,
5C1A7E0E2FB0A00100AB0004 /* OSInAppMessageScroll.h in Headers */,
DEBAAEB82A4381AE00BF2C1C /* OSInAppMessageMigrationController.h in Headers */,
DEBAAE7E2A42176800BF2C1C /* OSInAppMessageDisplayStats.h in Headers */,
DEBAAE882A42176800BF2C1C /* OSInAppMessageClickEvent.h in Headers */,
Expand Down Expand Up @@ -4657,6 +4677,8 @@
3C01519C2C2E29F90079E076 /* IAMRequestTests.m in Sources */,
3CB35FCB2F0FA20B000E6E0F /* OSMessagingControllerUserStateTests.swift in Sources */,
6F894909CB6D09258DCCA1C9 /* IamFetchIdentityVerificationTests.swift in Sources */,
5C1A7E0D2FB0A00100AB0006 /* OSInAppMessageInsetsTests.swift in Sources */,
5C1A7E0E2FB0A00100AB0006 /* OSInAppMessageScrollTests.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -5146,6 +5168,8 @@
DEBAAE8C2A42176800BF2C1C /* OSInAppMessagePushPrompt.m in Sources */,
DEBAAE8E2A42176800BF2C1C /* OSInAppMessageClickResult.m in Sources */,
DEBAAE572A42174A00BF2C1C /* OSInAppMessageView.m in Sources */,
5C1A7E0D2FB0A00100AB0005 /* OSInAppMessageInsets.m in Sources */,
5C1A7E0E2FB0A00100AB0005 /* OSInAppMessageScroll.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1382,7 +1382,7 @@ - (void)webViewContentFinishedLoading:(OSInAppMessageInternal *)message {
if (!self.window) {
self.window = [[UIWindow alloc] init];
self.window.windowLevel = UIWindowLevelAlert;
self.window.frame = [[UIScreen mainScreen] bounds];
self.window.frame = [UIApplication displayBounds];
}

self.window.rootViewController = _viewController;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/**
* Modified MIT License
*
* Copyright 2026 OneSignal
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* 1. The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* 2. All copies of substantial portions of the Software may only be used in connection
* with services provided by OneSignal.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#import <UIKit/UIKit.h>

NS_ASSUME_NONNULL_BEGIN

@interface OSInAppMessageInsets : NSObject

// Each side is the larger of the margin and its safe area inset. Region frames are in the scene
// view's coordinates; one sitting inside a side safe area, not flush with the edge, adds clearance.
// Both checks allow 1pt of slack: within 1pt of the screen edge counts as flush, and up to 1pt past
// the safe area edge still counts as inside.
// Full screen messages ignore the safe area and regions.
+ (UIEdgeInsets)horizontalInsetsWithMargin:(CGFloat)margin
safeArea:(UIEdgeInsets)safeArea
width:(CGFloat)width
regionFrames:(NSArray<NSValue *> *)regionFrames
isFullscreen:(BOOL)isFullscreen;

@end

NS_ASSUME_NONNULL_END
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/**
* Modified MIT License
*
* Copyright 2026 OneSignal
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* 1. The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* 2. All copies of substantial portions of the Software may only be used in connection
* with services provided by OneSignal.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#import "OSInAppMessageInsets.h"

@implementation OSInAppMessageInsets

+ (UIEdgeInsets)horizontalInsetsWithMargin:(CGFloat)margin
safeArea:(UIEdgeInsets)safeArea
width:(CGFloat)width
regionFrames:(NSArray<NSValue *> *)regionFrames
isFullscreen:(BOOL)isFullscreen {
if (isFullscreen) {
return UIEdgeInsetsMake(0, margin, 0, margin);
}
CGFloat left = MAX(margin, safeArea.left);
CGFloat right = MAX(margin, safeArea.right);
// Region frames already include UIKit's interactive margins; the message margin is added on top.
for (NSValue *value in regionFrames) {
CGRect frame = value.CGRectValue;
CGFloat minX = CGRectGetMinX(frame);
CGFloat maxX = CGRectGetMaxX(frame);
if (minX >= 1 && maxX <= safeArea.left + 1) {
left = MAX(left, maxX + margin);
} else if (maxX <= width - 1 && minX >= width - safeArea.right - 1) {
right = MAX(right, width - minX + margin);
}
}
return UIEdgeInsetsMake(0, left, 0, right);
}

@end
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/**
* Modified MIT License
*
* Copyright 2026 OneSignal
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* 1. The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* 2. All copies of substantial portions of the Software may only be used in connection
* with services provided by OneSignal.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#import <UIKit/UIKit.h>

NS_ASSUME_NONNULL_BEGIN

@interface OSInAppMessageScroll : NSObject

// Only content cut off by the screen height cap may scroll. Banners never scroll. Full screen
// messages report no height, so they are always treated as capped.
+ (BOOL)isHeightCappedWithMessageHeight:(CGFloat)messageHeight
availableHeight:(CGFloat)availableHeight
isBanner:(BOOL)isBanner
isFullscreen:(BOOL)isFullscreen;

// Overflow under 1pt is treated as fitting, so rounding never makes a message scroll.
+ (BOOL)contentOverflowsWithContentHeight:(CGFloat)contentHeight visibleHeight:(CGFloat)visibleHeight;

// A drag moves the message only when its content fits or is already at the edge it is dragged
// away from; otherwise the content scrolls. translationY is positive when dragging down.
+ (BOOL)shouldDragMessageWithContentOffsetY:(CGFloat)offsetY
contentHeight:(CGFloat)contentHeight
visibleHeight:(CGFloat)visibleHeight
translationY:(CGFloat)translationY;

@end

NS_ASSUME_NONNULL_END
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/**
* Modified MIT License
*
* Copyright 2026 OneSignal
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* 1. The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* 2. All copies of substantial portions of the Software may only be used in connection
* with services provided by OneSignal.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#import "OSInAppMessageScroll.h"

static const CGFloat kEdgeTolerance = 1.0;

@implementation OSInAppMessageScroll

+ (BOOL)isHeightCappedWithMessageHeight:(CGFloat)messageHeight
availableHeight:(CGFloat)availableHeight
isBanner:(BOOL)isBanner
isFullscreen:(BOOL)isFullscreen {
if (isBanner) return false;
if (isFullscreen) return true;
return messageHeight - availableHeight > kEdgeTolerance;
}

+ (BOOL)contentOverflowsWithContentHeight:(CGFloat)contentHeight visibleHeight:(CGFloat)visibleHeight {
return contentHeight - visibleHeight > kEdgeTolerance;
}

+ (BOOL)shouldDragMessageWithContentOffsetY:(CGFloat)offsetY
contentHeight:(CGFloat)contentHeight
visibleHeight:(CGFloat)visibleHeight
translationY:(CGFloat)translationY {
if (![self contentOverflowsWithContentHeight:contentHeight visibleHeight:visibleHeight]) {
return true;
}
if (translationY > 0) {
return offsetY <= kEdgeTolerance;
}
if (translationY < 0) {
return offsetY >= contentHeight - visibleHeight - kEdgeTolerance;
}
return false;
}

@end
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,21 @@ NS_ASSUME_NONNULL_BEGIN
@interface OSInAppMessageView : UIView <WKNavigationDelegate>

@property (weak, nonatomic, nullable) id<OSInAppMessageViewDelegate> delegate;
// Left & right space around the message, so content is laid out at the width it is displayed at
@property (nonatomic) UIEdgeInsets horizontalInsets;

- (instancetype _Nonnull)initWithMessage:(OSInAppMessageInternal *)inAppMessage withScriptMessageHandler:(id<WKScriptMessageHandler>)messageHandler;
- (void)resetWebViewToMaxBoundsAndResizeHeight:(void (^) (NSNumber *newHeight)) completion;
- (void)updateSafeAreaInsets;
- (void)resetWebViewToMaxBoundsAndResizeHeight:(void (^) (NSNumber * _Nullable newHeight)) completion;
- (void)updateSafeAreaInsets:(UIEdgeInsets)insets;
- (void)setupWebViewConstraints;
- (void)loadReplacementURL:(NSURL *)url;
- (void)loadedHtmlContent:(NSString *)html withBaseURL:(NSURL *)url;
- (void)removeScriptMessageHandler;
- (void)setIsFullscreen:(BOOL)isFullscreen;
- (BOOL)shouldDragMessageForTranslationY:(CGFloat)translationY;
@property (nonatomic, readonly) UIPanGestureRecognizer *contentPanGestureRecognizer;
// Content may scroll only while this is set, so leftover document height never makes a fitting message scroll
@property (nonatomic) BOOL contentScrollAllowed;
@end

NS_ASSUME_NONNULL_END
Loading
Loading