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
133 changes: 133 additions & 0 deletions Example/OpenSwiftUIUITests/Layout/Stack/HVStackUITests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
//
// HVStackUITests.swift
// OpenSwiftUIUITests

import Testing
import SnapshotTesting

@MainActor
@Suite(.snapshots(record: .never, diffTool: diffTool))
struct HVStackUITests {
@Test
func fixFrameForHStack() {
struct ContentView: View {
var body: some View {
HStack {
Color.red.frame(width: 50, height: 50)
Color.blue.frame(width: 50, height: 50)
}
.frame(width: 150, height: 150)
.background { Color.black }
}
}
openSwiftUIAssertSnapshot(
of: ContentView()
)
}

@Test
func fixFrameForVStack() {
struct ContentView: View {
var body: some View {
VStack {
Color.red.frame(width: 50, height: 50)
Color.blue.frame(width: 50, height: 50)
}
.frame(width: 150, height: 150)
.background { Color.black }
}
}
openSwiftUIAssertSnapshot(
of: ContentView()
)
}

@Test
func fixFrameForHVStack() {
struct ContentView: View {
var body: some View {
VStack {
Color.red.frame(width: 40, height: 40)
Color.blue.frame(width: 40, height: 40)
HStack {
Color.green.frame(width: 40, height: 40)
Color.yellow.frame(width: 40, height: 40)
}
}
.frame(width: 150, height: 150)
.background { Color.black }
}
}
withKnownIssue("Spacing is not implemented") {
openSwiftUIAssertSnapshot(
of: ContentView()
)
}
}

@Test
func fixElementForHVStack() {
struct ContentView: View {
var body: some View {
VStack {
Color.red.frame(width: 40, height: 40)
Color.blue.frame(width: 40, height: 40)
HStack {
Color.green.frame(width: 40, height: 40)
Color.yellow.frame(width: 40, height: 40)
}
}
.background { Color.black }
}
}
withKnownIssue("Spacing is not implemented") {
openSwiftUIAssertSnapshot(
of: ContentView()
)
}
}

@Test
func equalSizeForHVStack() {
struct ContentView: View {
var body: some View {
VStack {
Color.red
Color.blue
HStack {
Color.green
Color.yellow
}
}
.background { Color.black }
}
}
withKnownIssue("Proposal implmentation is not correct") {
openSwiftUIAssertSnapshot(
of: ContentView()
)
}
}

@Test
func layoutPriorityForHVStack() {
struct ContentView: View {
var body: some View {
VStack {
Color.red
Color.blue.layoutPriority(1)
HStack {
Color.green
Color.yellow
}
}
.background { Color.black }
}
}
withKnownIssue("Proposal implmentation is not correct") {
openSwiftUIAssertSnapshot(
of: ContentView()
)
}
}
}
58 changes: 40 additions & 18 deletions Sources/OpenSwiftUICore/Layout/Stack/HVStack.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
// HVStack.swift
// OpenSwiftUICore
//
// Audited for 6.4.41
// Status: WIP
// Audited for 6.5.4
// Status: Complete

package import Foundation

Expand All @@ -19,6 +19,7 @@ package protocol HVStack: Layout, _VariadicView_UnaryViewRoot where Cache == _St
static var resizeChildrenWithTrailingOverflow: Bool { get }
}

@available(OpenSwiftUI_v4_0, *)
public struct _StackLayoutCache {
var stack: StackLayout
}
Expand Down Expand Up @@ -50,51 +51,72 @@ extension HVStack {
}

public func makeCache(subviews: Subviews) -> Cache {
_openSwiftUIUnimplementedFailure()
Cache(
stack: StackLayout(
minorAxisAlignment: alignment.key,
uniformSpacing: spacing,
majorAxis: Self.majorAxis,
proxies: subviews,
resizeChildrenWithTrailingOverflow: Self.resizeChildrenWithTrailingOverflow
)
)
}

public func updateCache(_ cache: inout Cache, subviews: Self.Subviews) {
_openSwiftUIUnimplementedFailure()
public func updateCache(_ cache: inout Cache, subviews: Subviews) {
cache.stack.update(
children: subviews,
majorAxis: Self.majorAxis,
minorAxisAlignment: alignment.key,
uniformSpacing: spacing
)
}

public func spacing(subviews: Subviews, cache: inout Cache) -> ViewSpacing {
_openSwiftUIUnimplementedFailure()
cache.stack.spacing()
}

public func sizeThatFits(
proposal: ProposedViewSize,
subviews: Self.Subviews,
cache: inout Self.Cache
subviews: Subviews,
cache: inout Cache
) -> CGSize {
_openSwiftUIUnimplementedFailure()
cache.stack.sizeThatFits(proposal)
}

public func placeSubviews(
in bounds: CGRect,
proposal: ProposedViewSize,
subviews: Self.Subviews,
cache: inout Self.Cache
subviews: Subviews,
cache: inout Cache
) {
_openSwiftUIUnimplementedFailure()
cache.stack.placeSubviews(in: bounds, proposedSize: proposal)
}

public func explicitAlignment(
of guide: HorizontalAlignment,
in bounds: CGRect,
proposal: ProposedViewSize,
subviews: Self.Subviews,
cache: inout Self.Cache
subviews: Subviews,
cache: inout Cache
) -> CGFloat? {
_openSwiftUIUnimplementedFailure()
cache.stack.explicitAlignment(
guide.key,
in: bounds,
proposal: proposal
)
}

public func explicitAlignment(
of guide: VerticalAlignment,
in bounds: CGRect,
proposal: ProposedViewSize,
subviews: Self.Subviews,
cache: inout Self.Cache
subviews: Subviews,
cache: inout Cache
) -> CGFloat? {
_openSwiftUIUnimplementedFailure()
cache.stack.explicitAlignment(
guide.key,
in: bounds,
proposal: proposal
)
}
}
Loading