Skip to content

Commit eaf5506

Browse files
committed
Implement _ViewListOutputs. groupViewList
1 parent 0b62a58 commit eaf5506

File tree

1 file changed

+78
-18
lines changed

1 file changed

+78
-18
lines changed

Sources/OpenSwiftUICore/View/Group.swift

Lines changed: 78 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// OpenSwiftUICore
44
//
55
// Audited for 6.5.4
6-
// Status: Blocked by _ViewListOutputs
6+
// Status: Complete
77
// ID: C1B8B6896BB94C69479F427820712D02 (SwiftUICore)
88

99
package import OpenAttributeGraphShims
@@ -137,7 +137,7 @@ extension Group: View, MultiView, PrimitiveView where Content: View {
137137
}
138138
}
139139

140-
// MARK: - _ViewListOutputs + Group [WIP]
140+
// MARK: - _ViewListOutputs + Group
141141

142142
extension _ViewListOutputs {
143143
package static func sectionListOutputs(
@@ -176,13 +176,84 @@ extension _ViewListOutputs {
176176
)
177177
}
178178

179+
@inline(__always)
180+
private static func groupViewListOptions(
181+
from options: _ViewListInputs.Options
182+
) -> _ViewListInputs.Options {
183+
var optionsWithoutNestedSections = options
184+
if optionsWithoutNestedSections.contains(.requiresNonEmptyGroupParent) {
185+
optionsWithoutNestedSections.subtract([.requiresNonEmptyGroupParent, .allowsNestedSections])
186+
}
187+
if optionsWithoutNestedSections.contains(.requiresSections) {
188+
optionsWithoutNestedSections.subtract([.requiresSections, .allowsNestedSections])
189+
}
190+
if options.contains(.allowsNestedSections) {
191+
return options
192+
} else {
193+
return optionsWithoutNestedSections
194+
}
195+
}
196+
179197
package static func groupViewList<Parent, Footer>(
180198
parent: _GraphValue<Parent>,
181199
footer: Attribute<Footer>,
182200
inputs: _ViewListInputs,
183201
body: @escaping (_Graph, _ViewListInputs) -> _ViewListOutputs
184202
) -> _ViewListOutputs where Parent: View, Footer: View {
185-
_openSwiftUIUnimplementedFailure()
203+
let options = inputs.options
204+
let groupOptionss = groupViewListOptions(from: options)
205+
206+
var headerInputs = inputs
207+
headerInputs.options = groupOptionss
208+
if options.contains(.requiresDepthAndSections) {
209+
headerInputs.traits = Attribute(SectionedTrait(traits: headerInputs._traits))
210+
headerInputs.addTraitKey(IsSectionedTraitKey.self)
211+
}
212+
213+
if options.contains(.requiresNonEmptyGroupParent) {
214+
headerInputs.options.insert(.isNonEmptyParent)
215+
headerInputs.traits = Attribute(SectionHeaderTrait(traits: headerInputs._traits))
216+
headerInputs.addTraitKey(IsSectionHeaderTraitKey.self)
217+
}
218+
if options.contains(.resetHeaderStyleContext) {
219+
headerInputs.base.resetStyleContext()
220+
}
221+
let headerOutputs = Parent.makeDebuggableViewList(
222+
view: parent,
223+
inputs: headerInputs
224+
)
225+
226+
var contentInputs = inputs
227+
contentInputs.implicitID = headerOutputs.nextImplicitID
228+
contentInputs.options = groupOptionss
229+
if options.contains(.requiresDepthAndSections) {
230+
contentInputs.traits = Attribute(DepthTrait(traits: headerInputs._traits))
231+
contentInputs.addTraitKey(DepthTraitKey.self)
232+
}
233+
let contentOutputs = body(.init(), contentInputs)
234+
235+
var footerInputs = inputs
236+
footerInputs.implicitID = contentOutputs.nextImplicitID
237+
footerInputs.options = groupOptionss
238+
if options.contains(.requiresNonEmptyGroupParent) {
239+
footerInputs.options.subtract(.requiresNonEmptyGroupParent)
240+
footerInputs.traits = Attribute(SectionFooterTrait(traits: footerInputs._traits))
241+
footerInputs.addTraitKey(IsSectionFooterTraitKey.self)
242+
}
243+
if options.contains(.resetFooterStyleContext) {
244+
footerInputs.base.resetStyleContext()
245+
}
246+
let footerOutputs = Footer.makeDebuggableViewList(
247+
view: .init(footer),
248+
inputs: footerInputs
249+
)
250+
251+
let outputs = [headerOutputs, contentOutputs, footerOutputs]
252+
if options.contains(.requiresSections) {
253+
return .sectionListOutputs(outputs, inputs: inputs)
254+
} else {
255+
return .concat(outputs, inputs: inputs)
256+
}
186257
}
187258

188259
package static func groupViewListCount<V, H, F>(
@@ -192,27 +263,16 @@ extension _ViewListOutputs {
192263
footerType: F.Type
193264
) -> Int? where V: View, H: View, F: View {
194265
let options = inputs.options
195-
var optionsWithoutNestedSections = options
196-
if optionsWithoutNestedSections.contains(.requiresNonEmptyGroupParent) {
197-
optionsWithoutNestedSections.subtract([.requiresNonEmptyGroupParent, .allowsNestedSections])
198-
}
199-
if optionsWithoutNestedSections.contains(.requiresSections) {
200-
optionsWithoutNestedSections.subtract([.requiresSections, .allowsNestedSections])
201-
}
202-
let contentOptions = if options.contains(.allowsNestedSections) {
203-
options
204-
} else {
205-
optionsWithoutNestedSections
206-
}
266+
let groupOptionss = groupViewListOptions(from: options)
207267

208268
var contentInputs = inputs
209-
contentInputs.options = contentOptions
269+
contentInputs.options = groupOptionss
210270
guard let contentCount = V._viewListCount(inputs: contentInputs) else {
211271
return nil
212272
}
213273
var count = contentCount
214274

215-
var headerOptions = contentOptions
275+
var headerOptions = groupOptionss
216276
if options.contains(.requiresNonEmptyGroupParent) {
217277
headerOptions.insert(.isNonEmptyParent)
218278
}
@@ -226,7 +286,7 @@ extension _ViewListOutputs {
226286
}
227287
count += headerCount
228288

229-
var footerOptions = contentOptions
289+
var footerOptions = groupOptionss
230290
if options.contains(.requiresNonEmptyGroupParent) {
231291
footerOptions.remove(.requiresNonEmptyGroupParent)
232292
}

0 commit comments

Comments
 (0)