Skip to content

Commit 230e003

Browse files
committed
Update DerivedLayout
1 parent 4204c98 commit 230e003

File tree

2 files changed

+100
-21
lines changed

2 files changed

+100
-21
lines changed

Sources/OpenSwiftUICore/Layout/Layout.swift

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -680,24 +680,6 @@ extension Layout {
680680
)
681681
}
682682
}
683-
684-
static func makeDynamicView(
685-
root: _GraphValue<Self>,
686-
inputs: _ViewInputs,
687-
properties: LayoutProperties,
688-
list: Attribute<any ViewList>
689-
) -> _ViewOutputs {
690-
preconditionFailure("TODO")
691-
}
692-
693-
static func makeStaticView(
694-
root: _GraphValue<Self>,
695-
inputs: _ViewInputs,
696-
properties: LayoutProperties,
697-
list: ViewList.Elements
698-
) -> _ViewOutputs {
699-
preconditionFailure("TODO")
700-
}
701683
}
702684

703685
extension Layout {

Sources/OpenSwiftUICore/Layout/UnaryLayout.swift

Lines changed: 100 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,13 @@
22
// UnaryLayout.swift
33
// OpenSwiftUICore
44
//
5-
// Audited for iOS 18.0
6-
// Status: WIP
5+
// Status: Blocked by makeStaticView and makeDynamicView
76

87
package import Foundation
98
package import OpenGraphShims
109

10+
// MARK: - UnaryLayout [6.4.41]
11+
1112
package protocol UnaryLayout: Animatable, MultiViewModifier, PrimitiveViewModifier {
1213
associatedtype PlacementContextType = PlacementContext
1314

@@ -50,12 +51,108 @@ extension UnaryLayout {
5051
}
5152
}
5253

54+
// MARK: - DerivedLayout [6.4.41]
55+
56+
package protocol DerivedLayout: Layout {
57+
associatedtype Base: Layout where Cache == Base.Cache
58+
59+
var base: Base { get }
60+
}
61+
62+
extension DerivedLayout {
63+
public static var layoutProperties: LayoutProperties {
64+
Base.layoutProperties
65+
}
66+
67+
public func makeCache(subviews: Subviews) -> Base.Cache {
68+
base.makeCache(subviews: subviews)
69+
}
70+
71+
public func updateCache(_ cache: inout Base.Cache, subviews: Subviews) {
72+
base.updateCache(&cache, subviews: subviews)
73+
}
74+
75+
public func spacing(subviews: Subviews, cache: inout Base.Cache) -> ViewSpacing {
76+
base.spacing(subviews: subviews, cache: &cache)
77+
}
78+
79+
public func sizeThatFits(proposal: ProposedViewSize, subviews: Subviews, cache: inout Base.Cache) -> CGSize {
80+
base.sizeThatFits(proposal: proposal, subviews: subviews, cache: &cache)
81+
}
82+
83+
public func placeSubviews(in bounds: CGRect, proposal: ProposedViewSize, subviews: Subviews, cache: inout Base.Cache) {
84+
base.placeSubviews(in: bounds, proposal: proposal, subviews: subviews, cache: &cache)
85+
}
86+
87+
public func explicitAlignment(of guide: HorizontalAlignment, in bounds: CGRect, proposal: ProposedViewSize, subviews: Subviews, cache: inout Base.Cache) -> CGFloat? {
88+
base.explicitAlignment(of: guide, in: bounds, proposal: proposal, subviews: subviews, cache: &cache)
89+
}
90+
91+
public func explicitAlignment(of guide: VerticalAlignment, in bounds: CGRect, proposal: ProposedViewSize, subviews: Subviews, cache: inout Base.Cache) -> CGFloat? {
92+
base.explicitAlignment(of: guide, in: bounds, proposal: proposal, subviews: subviews, cache: &cache)
93+
}
94+
}
95+
96+
// MARK: - Layout + Static/Dynamic View Creation [6.4.41] [WIP]
97+
98+
extension Layout {
99+
package static func makeStaticView(
100+
root: _GraphValue<Self>,
101+
inputs: _ViewInputs,
102+
properties: LayoutProperties,
103+
list: any _ViewList_Elements
104+
) -> _ViewOutputs {
105+
preconditionFailure("TODO")
106+
}
107+
108+
static func makeDynamicView(
109+
root: _GraphValue<Self>,
110+
inputs: _ViewInputs,
111+
properties: LayoutProperties,
112+
list: Attribute<any ViewList>
113+
) -> _ViewOutputs {
114+
preconditionFailure("TODO")
115+
}
116+
}
117+
118+
package struct LayoutChildGeometries: Rule, AsyncAttribute {
119+
@Attribute
120+
private var parentSize: ViewSize
121+
122+
@Attribute
123+
private var parentPosition: PlatformPoint
124+
125+
@Attribute
126+
private var layoutComputer: LayoutComputer
127+
128+
package init(parentSize: Attribute<ViewSize>, parentPosition: Attribute<PlatformPoint>, layoutComputer: Attribute<LayoutComputer>) {
129+
_parentSize = parentSize
130+
_parentPosition = parentPosition
131+
_layoutComputer = layoutComputer
132+
}
133+
134+
package var value: [ViewGeometry] {
135+
layoutComputer.childGeometries(at: parentSize, origin: parentPosition)
136+
}
137+
}
138+
53139
extension StatefulRule where Value == LayoutComputer {
54140
package mutating func updateLayoutComputer<L>(
55141
layout: L,
56142
environment: Attribute<EnvironmentValues>,
57143
attributes: [LayoutProxyAttributes]
58144
) where L: Layout {
59-
preconditionFailure("TODO")
145+
let context = AnyRuleContext(attribute: .current!)
146+
layout.updateLayoutComputer(
147+
rule: &self,
148+
layoutContext: SizeAndSpacingContext(
149+
context: context,
150+
environment: environment
151+
),
152+
children: LayoutProxyCollection(
153+
context: context,
154+
attributes: attributes
155+
)
156+
)
60157
}
61158
}

0 commit comments

Comments
 (0)