Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,11 @@ import Testing
struct InsetViewModifierUITests {

@Test(
.bug("https://github.com/OpenSwiftUIProject/OpenSwiftUI/issues/511"),
.disabled("Extra spacing value is taken into account. Disable the test case before we fix it.")
.bug(
"https://github.com/OpenSwiftUIProject/OpenSwiftUI/issues/511",
id: 511,
"safeAreaPadding with edge insets should apply padding to the specified edges"
)
)
func safeAreaPaddingWithEdgeInsets() {
struct ContentView: View {
Expand Down
18 changes: 10 additions & 8 deletions Sources/OpenSwiftUICore/Layout/Modifier/InsetViewModifier.swift
Original file line number Diff line number Diff line change
Expand Up @@ -253,23 +253,25 @@ struct SafeAreaPaddingModifier: ViewModifier {

@usableFromInline
func body(content: SafeAreaPaddingModifier.Content) -> some View {
content.safeAreaInset(edge: .top) {
content.safeAreaInset(edge: .top, spacing: 0) {
insetView(edge: .top)
}.safeAreaInset(edge: .bottom) {
}.safeAreaInset(edge: .bottom, spacing: 0) {
insetView(edge: .bottom)
}.safeAreaInset(edge: .leading) {
}.safeAreaInset(edge: .leading, spacing: 0) {
insetView(edge: .leading)
}.safeAreaInset(edge: .trailing) {
}.safeAreaInset(edge: .trailing, spacing: 0) {
insetView(edge: .trailing)
}
}

private func insetView(edge: Edge) -> some View {
let inset = edges.contains(edge) ? (insets ?? defaultPadding)[edge] : 0
let axis = Axis(edge: edge)
let inset = (insets ?? defaultPadding)[edge]
return axis == .horizontal
? Color.clear.frame(width: inset)
: Color.clear.frame(height: inset)
return Color.clear.frame(
width: axis == .horizontal ? inset : 0,
height: axis == .vertical ? inset : 0,
alignment: .center
)
}
}

Expand Down
Loading