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
37 changes: 14 additions & 23 deletions ios/AirshipEmbeddedViewWrapper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,8 @@ struct ReactAirshipEmbeddedView: View {
if let embeddedID = viewModel.embeddedID {
AirshipEmbeddedView(embeddedID: embeddedID,
embeddedSize: .init(
parentWidth: viewModel.width,
parentHeight: viewModel.height
parentWidth: viewModel.parentWidth,
parentHeight: viewModel.parentHeight
),
selection: viewModel.selection
)
Expand All @@ -124,27 +124,18 @@ struct ReactAirshipEmbeddedView: View {
@Published var size: CGSize?
@Published var selection: AirshipEmbeddedSelection = .priority

var height: CGFloat {
guard let height = self.size?.height, height > 0 else {
return Self.defaultScreenBounds.height
}
return height
}

var width: CGFloat {
guard let width = self.size?.width, width > 0 else {
return Self.defaultScreenBounds.width
}
return width
}

@MainActor
private static var defaultScreenBounds: CGRect {
let window = UIApplication.shared.connectedScenes
.compactMap { $0 as? UIWindowScene }
.flatMap { $0.windows }
.first { $0.isKeyWindow } ?? UIApplication.shared.delegate?.window ?? nil
return window?.screen.bounds ?? CGRect(x: 0, y: 0, width: 500, height: 500)
/// The host's bound on each axis, or nil while layout has not supplied one.
///
/// Nil is the SDK's own signal for "no parent stated": it resolves a percent
/// placement against the SwiftUI proposal instead, which is the real box. A
/// stand-in value overrides that and sizes content against space the app
/// never gave the view. In React Native an unsized view is 0, not unknown.
var parentWidth: CGFloat? { Self.bound(self.size?.width) }
var parentHeight: CGFloat? { Self.bound(self.size?.height) }

private static func bound(_ length: CGFloat?) -> CGFloat? {
guard let length, length > 0 else { return nil }
return length
}
}

Expand Down
3 changes: 3 additions & 0 deletions ios/RNAirshipEmbeddedView.mm
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ - (void)unmountChildComponentView:(UIView<RCTComponentViewProtocol> *)childCompo
- (instancetype) init {
self = [self initWithFrame:CGRectZero];
if (self) {
// Scene content reports its own size, which can exceed the box Yoga assigned.
// Unclipped, a UIView paints that overflow over the app's own views.
self.clipsToBounds = YES;
self.wrapper = [[RNAirshipEmbeddedViewBridgeClass() alloc] initWithFrame:self.bounds];
[self addSubview:self.wrapper];
}
Expand Down
Loading