|
2 | 2 | // UnaryLayout.swift
|
3 | 3 | // OpenSwiftUICore
|
4 | 4 | //
|
5 |
| -// Audited for iOS 18.0 |
6 |
| -// Status: WIP |
| 5 | +// Status: Blocked by makeStaticView and makeDynamicView |
7 | 6 |
|
8 | 7 | package import Foundation
|
9 | 8 | package import OpenGraphShims
|
10 | 9 |
|
| 10 | +// MARK: - UnaryLayout [6.4.41] |
| 11 | + |
11 | 12 | package protocol UnaryLayout: Animatable, MultiViewModifier, PrimitiveViewModifier {
|
12 | 13 | associatedtype PlacementContextType = PlacementContext
|
13 | 14 |
|
@@ -50,12 +51,108 @@ extension UnaryLayout {
|
50 | 51 | }
|
51 | 52 | }
|
52 | 53 |
|
| 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 | + |
53 | 139 | extension StatefulRule where Value == LayoutComputer {
|
54 | 140 | package mutating func updateLayoutComputer<L>(
|
55 | 141 | layout: L,
|
56 | 142 | environment: Attribute<EnvironmentValues>,
|
57 | 143 | attributes: [LayoutProxyAttributes]
|
58 | 144 | ) 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 | + ) |
60 | 157 | }
|
61 | 158 | }
|
0 commit comments