Skip to content

Commit ed01c87

Browse files
committed
Add UnaryLayout
1 parent c888687 commit ed01c87

File tree

2 files changed

+61
-10
lines changed

2 files changed

+61
-10
lines changed

Sources/OpenSwiftUICore/Layout/Stack/LayoutPriorityLayout.swift

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
// Audited for iOS 18.0
66
// Status: WIP
77

8+
package import Foundation
9+
810
extension View {
911
/// Sets the priority by which a parent layout should apportion space to
1012
/// this child.
@@ -56,18 +58,17 @@ package struct LayoutPriorityTraitKey: _ViewTraitKey {
5658
@available(*, unavailable)
5759
extension LayoutPriorityTraitKey: Sendable {}
5860

59-
// FIXME
60-
protocol UnaryLayout: ViewModifier {
61-
static func makeViewImpl(
62-
modifier: _GraphValue<Self>,
63-
inputs: _ViewInputs,
64-
body: @escaping (_Graph, _ViewInputs) -> _ViewOutputs
65-
) -> _ViewOutputs
66-
}
67-
6861
// FIXME
6962
package struct LayoutPriorityLayout: UnaryLayout {
70-
static func makeViewImpl(modifier: _GraphValue<LayoutPriorityLayout>, inputs: _ViewInputs, body: @escaping (_Graph, _ViewInputs) -> _ViewOutputs) -> _ViewOutputs {
63+
package func placement(of child: LayoutProxy, in context: PlacementContext) -> _Placement {
64+
preconditionFailure("TODO")
65+
}
66+
67+
package func sizeThatFits(in proposedSize: _ProposedSize, context: SizeAndSpacingContext, child: LayoutProxy) -> CGSize {
68+
preconditionFailure("TODO")
69+
}
70+
71+
package static func makeViewImpl(modifier: _GraphValue<LayoutPriorityLayout>, inputs: _ViewInputs, body: @escaping (_Graph, _ViewInputs) -> _ViewOutputs) -> _ViewOutputs {
7172
.init()
7273
}
7374
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
//
2+
// UnaryLayout.swift
3+
// OpenSwiftUICore
4+
//
5+
// Audited for iOS 18.0
6+
// Status: WIP
7+
8+
package import Foundation
9+
10+
package protocol UnaryLayout: Animatable, MultiViewModifier, PrimitiveViewModifier {
11+
associatedtype PlacementContextType = PlacementContext
12+
13+
func spacing(in context: SizeAndSpacingContext, child: LayoutProxy) -> Spacing
14+
15+
func placement(of child: LayoutProxy, in context: PlacementContextType) -> _Placement
16+
17+
func sizeThatFits(in proposedSize: _ProposedSize, context: SizeAndSpacingContext, child: LayoutProxy) -> CGSize
18+
19+
func layoutPriority(child: LayoutProxy) -> Double
20+
21+
func ignoresAutomaticPadding(child: LayoutProxy) -> Bool
22+
23+
static func makeViewImpl(
24+
modifier: _GraphValue<Self>,
25+
inputs: _ViewInputs,
26+
body: @escaping (_Graph, _ViewInputs) -> _ViewOutputs
27+
) -> _ViewOutputs
28+
}
29+
30+
extension UnaryLayout {
31+
package func layoutPriority(child: LayoutProxy) -> Double {
32+
child.layoutPriority
33+
}
34+
35+
package func ignoresAutomaticPadding(child: LayoutProxy) -> Bool {
36+
false
37+
}
38+
39+
nonisolated public static func _makeView(
40+
modifier: _GraphValue<Self>,
41+
inputs: _ViewInputs,
42+
body: @escaping (_Graph, _ViewInputs) -> _ViewOutputs
43+
) -> _ViewOutputs {
44+
makeViewImpl(modifier: modifier, inputs: inputs, body: body)
45+
}
46+
47+
package func spacing(in context: SizeAndSpacingContext, child: LayoutProxy) -> Spacing {
48+
child.spacing()
49+
}
50+
}

0 commit comments

Comments
 (0)