Skip to content

Commit 52ff271

Browse files
committed
Constraint modal sizing to parent (screen) size to support iPadOS window resizing capabilities
1 parent 3f2a189 commit 52ff271

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

WooCommerce/Classes/POS/Presentation/Reusable Views/POSModalSizing.swift

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ extension View {
99

1010
struct POSModalSizing: ViewModifier {
1111
@Environment(\.sizeCategory) private var sizeCategory
12+
@Environment(\.posModalParentSize) private var parentSize
1213

1314
func body(content: Content) -> some View {
1415
content
@@ -19,6 +20,10 @@ struct POSModalSizing: ViewModifier {
1920

2021
private extension POSModalSizing {
2122
var frameWidth: CGFloat {
23+
return min(preferredFrameWidth, maxAvailableFrameWidth)
24+
}
25+
26+
var preferredFrameWidth: CGFloat {
2227
switch sizeCategory {
2328
case .extraSmall, .small:
2429
return 560
@@ -37,7 +42,15 @@ private extension POSModalSizing {
3742
}
3843
}
3944

45+
var maxAvailableFrameWidth: CGFloat {
46+
return parentSize.width
47+
}
48+
4049
var frameHeight: CGFloat {
50+
return min(preferredFrameHeight, parentSize.height)
51+
}
52+
53+
var preferredFrameHeight: CGFloat {
4154
switch sizeCategory {
4255
case .extraSmall, .small:
4356
return 640
@@ -56,6 +69,10 @@ private extension POSModalSizing {
5669
}
5770
}
5871

72+
var maxAvailableFrameHeight: CGFloat {
73+
parentSize.height
74+
}
75+
5976
var windowBounds: CGRect {
6077
window?.bounds ?? UIScreen.main.bounds
6178
}

0 commit comments

Comments
 (0)