Skip to content

Commit 03ee0fd

Browse files
authored
Add DynamicViewContent (#211)
1 parent e0978d2 commit 03ee0fd

File tree

2 files changed

+53
-1
lines changed

2 files changed

+53
-1
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
//
2+
// DynamicViewContent.swift
3+
// OpenSwiftUICore
4+
//
5+
// Audited for iOS 18.0
6+
// Status: Complete
7+
8+
/// A type of view that generates views from an underlying collection of data.
9+
public protocol DynamicViewContent: View {
10+
/// The type of the underlying collection of data.
11+
associatedtype Data: Collection
12+
13+
/// The collection of underlying data.
14+
var data: Data { get }
15+
}
16+
17+
extension ForEach: DynamicViewContent where Content: View {}
18+
19+
extension ModifiedContent: DynamicViewContent where Content: DynamicViewContent, Modifier: ViewModifier {
20+
public var data: Content.Data {
21+
content.data
22+
}
23+
}
24+
25+
package struct DynamicViewContentIDTraitKey: _ViewTraitKey {
26+
package static let defaultValue: Int? = nil
27+
}
28+
29+
package struct DynamicViewContentOffsetTraitKey: _ViewTraitKey {
30+
package static let defaultValue: Int? = nil
31+
}
32+
33+
package struct DynamicContentOffsetVisitor: ViewListVisitor {
34+
package var offset: Int?
35+
36+
package mutating func visit(view: _ViewList_View, traits: ViewTraitCollection) -> Bool {
37+
offset = traits.value(for: DynamicViewContentOffsetTraitKey.self)
38+
return false
39+
}
40+
}

Sources/OpenSwiftUICore/View/Variadic/ForEach.swift renamed to Sources/OpenSwiftUICore/View/ForEach.swift

+13-1
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,23 @@
4444
/// ![A vertically arranged stack of labels showing various standard fonts,
4545
/// such as Large Title and Headline.](OpenSwiftUI-ForEach-fonts.png)
4646
public struct ForEach<Data, ID, Content> where Data: RandomAccessCollection, ID: Hashable {
47-
4847
/// The collection of underlying identified data that OpenSwiftUI uses to create
4948
/// views dynamically.
5049
public var data: Data
5150

5251
/// A function to create content on demand using the underlying data.
5352
public var content: (Data.Element) -> Content
5453
}
54+
55+
@available(*, unavailable)
56+
extension ForEach: Sendable {}
57+
58+
extension ForEach: View, PrimitiveView where Content: View {
59+
nonisolated public static func _makeView(view: _GraphValue<Self>, inputs: _ViewInputs) -> _ViewOutputs {
60+
preconditionFailure("TODO")
61+
}
62+
63+
nonisolated public static func _makeViewList(view: _GraphValue<ForEach<Data, ID, Content>>, inputs: _ViewListInputs) -> _ViewListOutputs {
64+
preconditionFailure("TODO")
65+
}
66+
}

0 commit comments

Comments
 (0)