Skip to content

Commit 4673930

Browse files
committed
disableSafeArea 기능 추가
1 parent af0adae commit 4673930

File tree

2 files changed

+31
-17
lines changed

2 files changed

+31
-17
lines changed

Sources/WindowOverlay/Internals/WindowBridgingView.swift

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,13 @@ import UIKit
33

44
internal struct WindowBridgingView<V: View>: UIViewRepresentable {
55
var isPresented: Bool
6+
var disableSafeArea: Bool
67
var content: V
78

89
func makeUIView(context: Context) -> _HelperView {
910
return _HelperView(
1011
isPresented: isPresented,
12+
disableSafeArea: disableSafeArea,
1113
content: EnvPassingView(
1214
content: content,
1315
environment: context.environment
@@ -17,6 +19,7 @@ internal struct WindowBridgingView<V: View>: UIViewRepresentable {
1719
func updateUIView(_ helper: _HelperView, context: Context) {
1820
helper.setContent(
1921
isPresented: isPresented,
22+
disableSafeArea: disableSafeArea,
2023
content: EnvPassingView(
2124
content: content,
2225
environment: context.environment
@@ -32,18 +35,20 @@ internal struct WindowBridgingView<V: View>: UIViewRepresentable {
3235
content.environment(\.self, environment)
3336
}
3437
}
35-
38+
3639
internal final class _HelperView: UIView {
3740
private var isPresented: Bool
41+
private var disableSafeArea: Bool
3842
private var content: EnvPassingView
3943

4044
private var overlayWindow: WindowOverlayWindow?
4145
private var hostingController: UIHostingController<EnvPassingView>? {
4246
overlayWindow?.rootViewController as? UIHostingController<EnvPassingView>
4347
}
4448

45-
fileprivate init(isPresented: Bool, content: EnvPassingView) {
49+
fileprivate init(isPresented: Bool, disableSafeArea: Bool, content: EnvPassingView) {
4650
self.isPresented = isPresented
51+
self.disableSafeArea = disableSafeArea
4752
self.content = content
4853
super.init(frame: .zero)
4954
}
@@ -60,9 +65,11 @@ internal struct WindowBridgingView<V: View>: UIViewRepresentable {
6065

6166
fileprivate func setContent(
6267
isPresented: Bool,
68+
disableSafeArea: Bool,
6369
content: EnvPassingView
6470
) {
6571
self.isPresented = isPresented
72+
self.disableSafeArea = disableSafeArea
6673
self.content = content
6774
updateView()
6875
}
@@ -72,6 +79,7 @@ internal struct WindowBridgingView<V: View>: UIViewRepresentable {
7279
if hostingController == nil {
7380
overlayWindow?.rootViewController = UIHostingController(rootView: content)
7481
overlayWindow?.rootViewController?.view.backgroundColor = .clear
82+
hostingController?.disableSafeArea(disableSafeArea)
7583
} else {
7684
hostingController?.rootView = content
7785
}
@@ -83,3 +91,13 @@ internal struct WindowBridgingView<V: View>: UIViewRepresentable {
8391
}
8492
}
8593
}
94+
95+
extension UIHostingController {
96+
func disableSafeArea(_ disable: Bool) {
97+
if #available(iOS 16.4, *) {
98+
self.safeAreaRegions = disable ? [] : .all
99+
} else {
100+
self._disableSafeArea = disable
101+
}
102+
}
103+
}
Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,16 @@
11
import SwiftUI
22

33
extension View {
4-
public func windowOverlay<V: View>(isPresented: Bool, @ViewBuilder content: () -> V) -> some View {
5-
modifier(WindowOverlayModifier(isPresented: isPresented, overlay: content()))
6-
}
7-
}
8-
9-
private struct WindowOverlayModifier<V: View>: ViewModifier {
10-
var isPresented: Bool
11-
var overlay: V
12-
13-
func body(content: Content) -> some View {
14-
content
15-
._background {
16-
WindowBridgingView(isPresented: isPresented, content: overlay)
17-
.allowsHitTesting(false)
18-
}
4+
public func windowOverlay<V: View>(
5+
isPresented: Bool,
6+
disableSafeArea: Bool = false,
7+
@ViewBuilder content: () -> V
8+
) -> some View {
9+
self._background {
10+
WindowBridgingView(
11+
isPresented: isPresented, disableSafeArea: disableSafeArea, content: content()
12+
)
13+
.allowsHitTesting(false)
14+
}
1915
}
2016
}

0 commit comments

Comments
 (0)