From 2eebc312ff4c68dcc39e35f088878cad8622da22 Mon Sep 17 00:00:00 2001 From: yankezhi Date: Tue, 6 Feb 2024 14:36:43 +0800 Subject: [PATCH] Add configuration of security zones for background control When setting a security area that only requires the background container, the background can be independently controlled by adding a new configuration (bgIgnoresSafeArea) without affecting the parent container --- .../xcschemes/xcschememanagement.plist | 14 ++++++++++++++ .../xcschemes/xcschememanagement.plist | 19 +++++++++++++++++++ Demo/Shared/Demos/BackgroundDemo.swift | 5 +++++ Demo/Shared/en.lproj/Localizable.strings | 2 +- Demo/Shared/zh-Hans.lproj/Localizable.strings | 2 +- .../Container/CompositeContainerView.swift | 1 + .../Container/Container.swift | 1 + .../Container/ContainerProtocols.swift | 9 ++++++++- 8 files changed, 50 insertions(+), 3 deletions(-) create mode 100644 .swiftpm/xcode/xcuserdata/yadmin.xcuserdatad/xcschemes/xcschememanagement.plist create mode 100644 Demo/Demo.xcodeproj/xcuserdata/yadmin.xcuserdatad/xcschemes/xcschememanagement.plist diff --git a/.swiftpm/xcode/xcuserdata/yadmin.xcuserdatad/xcschemes/xcschememanagement.plist b/.swiftpm/xcode/xcuserdata/yadmin.xcuserdatad/xcschemes/xcschememanagement.plist new file mode 100644 index 0000000..d02156a --- /dev/null +++ b/.swiftpm/xcode/xcuserdata/yadmin.xcuserdatad/xcschemes/xcschememanagement.plist @@ -0,0 +1,14 @@ + + + + + SchemeUserState + + SwiftUIOverlayContainer.xcscheme_^#shared#^_ + + orderHint + 2 + + + + diff --git a/Demo/Demo.xcodeproj/xcuserdata/yadmin.xcuserdatad/xcschemes/xcschememanagement.plist b/Demo/Demo.xcodeproj/xcuserdata/yadmin.xcuserdatad/xcschemes/xcschememanagement.plist new file mode 100644 index 0000000..a4e05a8 --- /dev/null +++ b/Demo/Demo.xcodeproj/xcuserdata/yadmin.xcuserdatad/xcschemes/xcschememanagement.plist @@ -0,0 +1,19 @@ + + + + + SchemeUserState + + Demo (iOS).xcscheme_^#shared#^_ + + orderHint + 0 + + Demo (macOS).xcscheme_^#shared#^_ + + orderHint + 1 + + + + diff --git a/Demo/Shared/Demos/BackgroundDemo.swift b/Demo/Shared/Demos/BackgroundDemo.swift index 0145f6a..d4a50e0 100644 --- a/Demo/Shared/Demos/BackgroundDemo.swift +++ b/Demo/Shared/Demos/BackgroundDemo.swift @@ -15,6 +15,7 @@ import SwiftUIOverlayContainer struct BackgroundDemo: View { @Environment(\.overlayContainerManager) var manager @State var tapToDismiss = true + var body: some View { ZStack { Color.clear @@ -26,6 +27,7 @@ struct BackgroundDemo: View { tapToDismiss: tapToDismiss, backgroundStyle: background.background ) + let size = CGSize(width: 300, height: 400) let view = BlockView(size: size, text: background.description, opacity: 1, allowDismiss: false) manager.show(view: view, in: "backgroundContainer", using: viewConfiguration) @@ -97,6 +99,7 @@ struct BackgroundContainerConfiguration: ContainerConfigurationProtocol { var queueType: ContainerViewQueueType { .oneByOne } var alignment: Alignment? { .center } var transition: AnyTransition? { .scale.combined(with: .opacity) } + var bgIgnoresSafeArea: ContainerIgnoresSafeArea { .all} var dismissGesture: ContainerViewDismissGesture? { .tap } @@ -104,6 +107,8 @@ struct BackgroundContainerConfiguration: ContainerConfigurationProtocol { var shadowStyle: ContainerViewShadowStyle? { .radius(10) } + + } struct BackgroundDemoViewConfiguration: ContainerViewConfigurationProtocol { diff --git a/Demo/Shared/en.lproj/Localizable.strings b/Demo/Shared/en.lproj/Localizable.strings index da308a9..7581494 100644 --- a/Demo/Shared/en.lproj/Localizable.strings +++ b/Demo/Shared/en.lproj/Localizable.strings @@ -68,7 +68,7 @@ "DisableBackground" = "No background"; "ViewBackgroundDescription" = "When using material type as background, only iOS 15, macOS 12, tvOS 15 and above are supported. TapToDismiss will be ignored when no background is used.\nIn vertical and horizontal modes, the container will use its own background configuration and ignore the view's background settings."; "TapToDismiss" = "Tap on the background to dismiss the view"; - +"BgIgnoresSafeArea" = "Background Cancel Security Zone"; // MARK: - Bind Demo diff --git a/Demo/Shared/zh-Hans.lproj/Localizable.strings b/Demo/Shared/zh-Hans.lproj/Localizable.strings index 4c3f307..7cc4737 100644 --- a/Demo/Shared/zh-Hans.lproj/Localizable.strings +++ b/Demo/Shared/zh-Hans.lproj/Localizable.strings @@ -68,7 +68,7 @@ "DisableBackground" = "不添加背景"; "ViewBackgroundDescription" = "当使用材料类型作为背景时,只支持iOS 15、macOS 12、tvOS 15及以上版本。当没有使用背景时,TapToDismiss将被忽略。在垂直和水平模式下,将忽略视图的背景设置,使用容器的背景配置。"; "TapToDismiss" = "点击背景取消视图"; - +"BgIgnoresSafeArea" = "背景取消安全区域"; // MARK: - Bind Demo diff --git a/Sources/SwiftUIOverlayContainer/Container/CompositeContainerView.swift b/Sources/SwiftUIOverlayContainer/Container/CompositeContainerView.swift index acf1899..17d0e78 100644 --- a/Sources/SwiftUIOverlayContainer/Container/CompositeContainerView.swift +++ b/Sources/SwiftUIOverlayContainer/Container/CompositeContainerView.swift @@ -175,6 +175,7 @@ extension OverlayContainer { // the current context of view is ZStack (GenericStack) backgroundOfIdentifiableView .zIndex(timeStamp: identifiableView.timeStamp, order: containerConfiguration.displayOrder, background: true) + .ignoresSafeArea(type: containerConfiguration.bgIgnoresSafeArea) compositingView .padding(containerConfiguration.insets) // add insets for each view .frame(minWidth: 0, maxWidth: .infinity, minHeight: 0, maxHeight: .infinity, alignment: alignment) diff --git a/Sources/SwiftUIOverlayContainer/Container/Container.swift b/Sources/SwiftUIOverlayContainer/Container/Container.swift index b80de7b..1307f2e 100644 --- a/Sources/SwiftUIOverlayContainer/Container/Container.swift +++ b/Sources/SwiftUIOverlayContainer/Container/Container.swift @@ -141,6 +141,7 @@ struct OverlayContainer: View { background .opacity(queueHandler.mainQueue.isEmpty ? 0 : 1) .zIndex(1.0) + .ignoresSafeArea(type: configuration.bgIgnoresSafeArea) GenericStack(displayType: configuration.displayType, alignment: alignment, spacing: configuration.spacing) { ForEach(queueHandler.mainQueue.alignment( diff --git a/Sources/SwiftUIOverlayContainer/Container/ContainerProtocols.swift b/Sources/SwiftUIOverlayContainer/Container/ContainerProtocols.swift index d5bc872..cf63672 100644 --- a/Sources/SwiftUIOverlayContainer/Container/ContainerProtocols.swift +++ b/Sources/SwiftUIOverlayContainer/Container/ContainerProtocols.swift @@ -68,6 +68,11 @@ public protocol ContainerCompositionProtocol { /// Default value is disable var ignoresSafeArea: ContainerIgnoresSafeArea { get } + /// Expands the backgroud container out of its safe area. + /// + /// Default value is disable + var bgIgnoresSafeArea: ContainerIgnoresSafeArea { get } + /// Controls the display order of overlapping views. /// /// Default value is ascending order, new container view can overlap the old one @@ -97,7 +102,9 @@ public extension ContainerCompositionProtocol { var clipped: Bool { false } var ignoresSafeArea: ContainerIgnoresSafeArea { .disable } - + + var bgIgnoresSafeArea: ContainerIgnoresSafeArea { .disable } + var displayOrder: ContainerDisplayOrder { .ascending } }