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 @@ -7,6 +7,7 @@ import Testing
@MainActor
@Suite(.snapshots(record: .never, diffTool: diffTool))
struct InsetViewModifierUITests {

@Test(.bug("https://github.com/OpenSwiftUIProject/OpenSwiftUI/issues/511"))
func safeAreaPaddingWithEdgeInsets() {
struct ContentView: View {
Expand All @@ -17,4 +18,26 @@ struct InsetViewModifierUITests {
}
openSwiftUIAssertSnapshot(of: ContentView())
}

@Test
func safeAreaInset() {
struct ContentView: View {
var body: some View {
Color.red
.safeAreaInset(edge: .leading) {
Color.green.frame(width: 10)
}
.safeAreaInset(edge: .top) {
Color.blue.frame(height: 20)
}
.safeAreaInset(edge: .trailing) {
Color.gray.frame(width: 30)
}
.safeAreaInset(edge: .bottom) {
Color.yellow.frame(height: 40)
}
}
}
openSwiftUIAssertSnapshot(of: ContentView())
}
}
7 changes: 1 addition & 6 deletions Example/SharedExample/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,6 @@ import Foundation

struct ContentView: View {
var body: some View {
Color.blue
.frame(width: 80, height: 60)
.scaleEffect(0.5)
.background { Color.red }
.frame(width: 10, height: 10)
.clipped()
InsetViewModifierExample()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
//
// InsetViewModifierExample.swift
// SharedExample

#if OPENSWIFTUI
import OpenSwiftUI
#else
import SwiftUI
#endif

struct InsetViewModifierExample: View {
var body: some View {
Color.red
.safeAreaInset(edge: .leading) {
Color.green.frame(width: 10)
}
.safeAreaInset(edge: .top) {
Color.blue.frame(height: 20)
}
.safeAreaInset(edge: .trailing) {
Color.gray.frame(width: 30)
}
.safeAreaInset(edge: .bottom) {
Color.yellow.frame(height: 40)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -541,14 +541,12 @@ private struct InsetViewLayout {
id: alignmentKeyID,
axis: secondaryAxis)
]
let position = (primaryPlacement.anchorPosition[secondaryAxis] + primaryAlignmentValue) - (secondaryAlignmentValue + .zero)
let secondaryAnchor = UnitPoint(edge: props.edge)
let secondaryPlacement = _Placement(
proposedSize: secondaryProposal,
aligning: secondaryAnchor,
in: parentSize.value
)

var primaryGeometry = ViewGeometry(
placement: primaryPlacement,
dimensions: primaryDimensions
Expand All @@ -557,7 +555,7 @@ private struct InsetViewLayout {
placement: secondaryPlacement,
dimensions: secondaryDimensions
)
secondaryGeometry.origin[secondaryAxis] = position
secondaryGeometry.origin[secondaryAxis] = primaryGeometry.origin[secondaryAxis] + (primaryAlignmentValue - secondaryAlignmentValue)

primaryGeometry.finalizeLayoutDirection(
layoutDirection,
Expand Down
Loading