Skip to content

Commit

Permalink
Add ignoresSafeArea parameter to container configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
fatbobman committed Apr 3, 2022
1 parent 2105ffb commit 4d6f65a
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 2 deletions.
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
4 changes: 4 additions & 0 deletions READMECN.md
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,10 @@ struct MyContainerConfiguration:ContainerConfigurationProtocol{

对容器进行剪裁,当想限制视图转换的边界时需要设置为真

* ignoresSafeArea

忽略安全区域。默认值为 disable (不忽略)、 all (忽略全部安全区域)、custom (自定义 region 和 edge )

* 其他所有容器视图的配置(用作容器视图的默认值)

详情参阅下方的配置容器视图
Expand Down
1 change: 1 addition & 0 deletions Sources/SwiftUIOverlayContainer/Container/Container.swift
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ struct OverlayContainer: View {
#endif
}
.clipped(enable: configuration.clipped)
.ignoresSafeArea(type: configuration.ignoresSafeArea)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
Expand Down
9 changes: 9 additions & 0 deletions Sources/SwiftUIOverlayContainer/Container/ContainerType.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
16 changes: 15 additions & 1 deletion Sources/SwiftUIOverlayContainer/Extensions/SwiftUI.swift
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,9 @@ extension View {
}
}

// condition clip

extension View {
/// condition clip
@ViewBuilder
func clipped(enable: Bool) -> some View {
if enable {
Expand All @@ -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)
}
}
}

0 comments on commit 4d6f65a

Please sign in to comment.