@@ -3,11 +3,13 @@ import UIKit
33
44internal 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+ }
0 commit comments