From 4d6f65a0caf316a4dcb7bf69cc5724cfe1f7a923 Mon Sep 17 00:00:00 2001 From: Yang Xu Date: Sun, 3 Apr 2022 17:57:12 +0800 Subject: [PATCH] Add ignoresSafeArea parameter to container configuration --- README.md | 6 +++++- READMECN.md | 4 ++++ .../Container/Container.swift | 1 + .../Container/ContainerProtocols.swift | 7 +++++++ .../Container/ContainerType.swift | 9 +++++++++ .../Extensions/SwiftUI.swift | 16 +++++++++++++++- 6 files changed, 41 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index f69189d..e88cb7f 100644 --- a/README.md +++ b/README.md @@ -194,7 +194,11 @@ Other properties: * clipped - Clip the container, set to true when you want to limit the bounds of the view transition + Clipping the container, set to true when you want to limit the bounds of the view transition + +* ignoresSafeArea + + Expending the container out of it's safe area. The default value is `.disable` (do not ignore), `.all` (ignore all safe area) and `.custom` (customize regions and edges) * Configuration for all other container views (used as defaults for container views) diff --git a/READMECN.md b/READMECN.md index 8cdbcf1..4292718 100644 --- a/READMECN.md +++ b/READMECN.md @@ -191,6 +191,10 @@ struct MyContainerConfiguration:ContainerConfigurationProtocol{ 对容器进行剪裁,当想限制视图转换的边界时需要设置为真 +* ignoresSafeArea + + 忽略安全区域。默认值为 disable (不忽略)、 all (忽略全部安全区域)、custom (自定义 region 和 edge ) + * 其他所有容器视图的配置(用作容器视图的默认值) 详情参阅下方的配置容器视图 diff --git a/Sources/SwiftUIOverlayContainer/Container/Container.swift b/Sources/SwiftUIOverlayContainer/Container/Container.swift index e785782..2fbeb41 100644 --- a/Sources/SwiftUIOverlayContainer/Container/Container.swift +++ b/Sources/SwiftUIOverlayContainer/Container/Container.swift @@ -194,6 +194,7 @@ struct OverlayContainer: View { #endif } .clipped(enable: configuration.clipped) + .ignoresSafeArea(type: configuration.ignoresSafeArea) } } diff --git a/Sources/SwiftUIOverlayContainer/Container/ContainerProtocols.swift b/Sources/SwiftUIOverlayContainer/Container/ContainerProtocols.swift index 3f7801e..8ea1946 100644 --- a/Sources/SwiftUIOverlayContainer/Container/ContainerProtocols.swift +++ b/Sources/SwiftUIOverlayContainer/Container/ContainerProtocols.swift @@ -62,6 +62,11 @@ public protocol ContainerCompositionProtocol { /// Pass true when the bounds of the view's transition need to limited /// Can't be changed dynamically var clipped: Bool { get } + + /// Expands the container out of its safe area. + /// + /// Default value is disable + var ignoresSafeArea: ContainerIgnoresSafeArea { get } } public extension ContainerCompositionProtocol { @@ -70,6 +75,8 @@ public extension ContainerCompositionProtocol { var insets: EdgeInsets { .init() } var clipped: Bool { false } + + var ignoresSafeArea: ContainerIgnoresSafeArea { .disable } } /// A combined protocol that defines all the configuration of the container diff --git a/Sources/SwiftUIOverlayContainer/Container/ContainerType.swift b/Sources/SwiftUIOverlayContainer/Container/ContainerType.swift index 3fd3899..f08bad1 100644 --- a/Sources/SwiftUIOverlayContainer/Container/ContainerType.swift +++ b/Sources/SwiftUIOverlayContainer/Container/ContainerType.swift @@ -39,3 +39,12 @@ public enum ContainerViewQueueType { /// The maximum number of view that can show at the same time base one maximumNumberOfViewsInMultipleMode case multiple } + +/// Expands the container out of its safe area. +public enum ContainerIgnoresSafeArea { + case disable + /// equivalent to `ignoresSafeArea(_ regions: SafeAreaRegions = .all, edges: Edge.Set = .all)` + case all + /// set custom regions and edges of safe area + case custom(SafeAreaRegions, Edge.Set) +} diff --git a/Sources/SwiftUIOverlayContainer/Extensions/SwiftUI.swift b/Sources/SwiftUIOverlayContainer/Extensions/SwiftUI.swift index 1c044ca..4602516 100644 --- a/Sources/SwiftUIOverlayContainer/Extensions/SwiftUI.swift +++ b/Sources/SwiftUIOverlayContainer/Extensions/SwiftUI.swift @@ -89,8 +89,9 @@ extension View { } } -// condition clip + extension View { + /// condition clip @ViewBuilder func clipped(enable: Bool) -> some View { if enable { @@ -99,4 +100,17 @@ extension View { self } } + + /// condition ignoresSafeArea + @ViewBuilder + func ignoresSafeArea(type: ContainerIgnoresSafeArea) -> some View { + switch type { + case .disable: + self + case .all: + ignoresSafeArea() + case .custom(let regions, let edges): + ignoresSafeArea(regions, edges: edges) + } + } }