Skip to content

Commit d248318

Browse files
committed
Update VariadicView
1 parent 7efb8b3 commit d248318

File tree

7 files changed

+142
-4
lines changed

7 files changed

+142
-4
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
//
2+
// ForEach.swift
3+
// OpenSwiftUI
4+
//
5+
// Audited for RELEASE_2021
6+
// Status: WIP
7+
8+
/// A structure that computes views on demand from an underlying collection of
9+
/// identified data.
10+
///
11+
/// Use `ForEach` to provide views based on a
12+
/// [RandomAccessCollection](https://developer.apple.com/documentation/swift/randomaccesscollection)
13+
/// of some data type. Either the collection's elements must conform to
14+
/// [Identifiable](https://developer.apple.com/documentation/swift/identifiable) or you
15+
/// need to provide an `id` parameter to the `ForEach` initializer.
16+
///
17+
/// The following example creates a `NamedFont` type that conforms to
18+
/// [Identifiable](https://developer.apple.com/documentation/swift/identifiable), and an
19+
/// array of this type called `namedFonts`. A `ForEach` instance iterates
20+
/// over the array, producing new ``Text`` instances that display examples
21+
/// of each OpenSwiftUI ``Font`` style provided in the array.
22+
///
23+
/// private struct NamedFont: Identifiable {
24+
/// let name: String
25+
/// let font: Font
26+
/// var id: String { name }
27+
/// }
28+
///
29+
/// private let namedFonts: [NamedFont] = [
30+
/// NamedFont(name: "Large Title", font: .largeTitle),
31+
/// NamedFont(name: "Title", font: .title),
32+
/// NamedFont(name: "Headline", font: .headline),
33+
/// NamedFont(name: "Body", font: .body),
34+
/// NamedFont(name: "Caption", font: .caption)
35+
/// ]
36+
///
37+
/// var body: some View {
38+
/// ForEach(namedFonts) { namedFont in
39+
/// Text(namedFont.name)
40+
/// .font(namedFont.font)
41+
/// }
42+
/// }
43+
///
44+
/// ![A vertically arranged stack of labels showing various standard fonts,
45+
/// such as Large Title and Headline.](OpenSwiftUI-ForEach-fonts.png)
46+
public struct ForEach<Data, ID, Content> where Data: RandomAccessCollection, ID: Hashable {
47+
48+
/// The collection of underlying identified data that OpenSwiftUI uses to create
49+
/// views dynamically.
50+
public var data: Data
51+
52+
/// A function to create content on demand using the underlying data.
53+
public var content: (Data.Element) -> Content
54+
}
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,69 @@
1-
// TODO
1+
//
2+
// VariadicView_Children.swift
3+
// OpenSwiftUI
4+
//
5+
// Audited for RELEASE_2021
6+
// Status: TODO
7+
// ID: 52A2FFECFBCF37BFFEED558E33EBD1E3
8+
9+
internal import OpenGraphShims
210

311
/// An ad hoc collection of the children of a variadic view.
412
public struct _VariadicView_Children {
13+
var list: ViewList
14+
var contentSubgraph: OGSubgraph
15+
}
16+
17+
extension _VariadicView_Children: RandomAccessCollection {
18+
public struct Element: PrimitiveView, UnaryView, Identifiable {
19+
20+
// var view: _ViewList_View
21+
var traits: ViewTraitCollection
22+
23+
public var id: AnyHashable {
24+
// view.viewID
25+
fatalError("TODO")
26+
27+
}
28+
public func id<ID>(as _: ID.Type = ID.self) -> ID? where ID : Hashable {
29+
fatalError("TODO")
30+
}
31+
32+
public subscript<Trait: _ViewTraitKey>(key: Trait.Type) -> Trait.Value {
33+
get { traits[key] }
34+
set { traits[key] = newValue }
35+
}
36+
37+
public static func _makeView(view: _GraphValue<_VariadicView_Children.Element>, inputs: _ViewInputs) -> _ViewOutputs {
38+
fatalError("TODO")
39+
}
40+
}
541

42+
public var startIndex: Int {
43+
fatalError("TODO")
44+
45+
// get
46+
}
47+
public var endIndex: Int {
48+
fatalError("TODO")
49+
50+
// get
51+
}
52+
public subscript(index: Int) -> _VariadicView_Children.Element {
53+
fatalError("TODO")
54+
55+
// get
56+
}
57+
}
58+
59+
extension _VariadicView_Children {
60+
private struct Child: Rule, AsyncAttribute {
61+
typealias Value = ForEach<_VariadicView_Children, AnyHashable, _VariadicView_Children.Element>
62+
63+
@Attribute var children: _VariadicView_Children
64+
65+
var value: Value {
66+
fatalError("TODO")
67+
}
68+
}
669
}

Sources/OpenSwiftUI/Core/View/VariadicView/VariadicView_ViewRoot.swift

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
//
55
// Audited for RELEASE_2021
66
// Status: WIP
7+
// ID: 00F12C0E37A19C593ECA0DBD3BE26541
78

89
internal import OpenGraphShims
910

Sources/OpenSwiftUI/Core/View/ViewList/ViewListInputs.swift

+1-2
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@ public struct _ViewListInputs {
1212
private var base: _GraphInputs
1313
var implicitID: Int
1414
var options: _ViewListInputs.Options
15-
@OptionalAttribute
16-
var traits: ViewTraitCollection?
15+
@OptionalAttribute var traits: ViewTraitCollection?
1716
var traitKeys: ViewTraitKeys?
1817

1918
struct Options: OptionSet {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// ID: 70E71091E926A1B09B75AAEB38F5AA3F
2+
3+
struct _ViewList_ID {
4+
var _index: Int32
5+
var implicitID: Int32
6+
private var explicitIDs: [Explicit]
7+
}
8+
9+
extension _ViewList_ID {
10+
private struct Explicit {
11+
}
12+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
internal import OpenGraphShims
2+
3+
struct _ViewList_View {
4+
var elements: _ViewList_Elements
5+
var id: _ViewList_ID
6+
var index: Int
7+
var count: Int
8+
var contentSubgraph: OGSubgraph
9+
}

Sources/OpenSwiftUI/Core/View/ViewTrait/ViewTraitKey.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
// Audited for RELEASE_2021
66
// Status: Complete
77

8-
protocol _ViewTraitKey {
8+
public protocol _ViewTraitKey {
99
associatedtype Value
1010
static var defaultValue: Value { get }
1111
}

0 commit comments

Comments
 (0)