Skip to content

Add DynamicViewContent #211

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 8, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions Sources/OpenSwiftUICore/View/DynamicViewContent.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
//
// DynamicViewContent.swift
// OpenSwiftUICore
//
// Audited for iOS 18.0
// Status: Complete

/// A type of view that generates views from an underlying collection of data.
public protocol DynamicViewContent: View {
/// The type of the underlying collection of data.
associatedtype Data: Collection

/// The collection of underlying data.
var data: Data { get }
}

extension ForEach: DynamicViewContent where Content: View {}

extension ModifiedContent: DynamicViewContent where Content: DynamicViewContent, Modifier: ViewModifier {
public var data: Content.Data {
content.data
}
}

package struct DynamicViewContentIDTraitKey: _ViewTraitKey {
package static let defaultValue: Int? = nil
}

package struct DynamicViewContentOffsetTraitKey: _ViewTraitKey {
package static let defaultValue: Int? = nil
}

package struct DynamicContentOffsetVisitor: ViewListVisitor {
package var offset: Int?

package mutating func visit(view: _ViewList_View, traits: ViewTraitCollection) -> Bool {
offset = traits.value(for: DynamicViewContentOffsetTraitKey.self)
return false
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,23 @@
/// ![A vertically arranged stack of labels showing various standard fonts,
/// such as Large Title and Headline.](OpenSwiftUI-ForEach-fonts.png)
public struct ForEach<Data, ID, Content> where Data: RandomAccessCollection, ID: Hashable {

/// The collection of underlying identified data that OpenSwiftUI uses to create
/// views dynamically.
public var data: Data

/// A function to create content on demand using the underlying data.
public var content: (Data.Element) -> Content
}

@available(*, unavailable)
extension ForEach: Sendable {}

extension ForEach: View, PrimitiveView where Content: View {
nonisolated public static func _makeView(view: _GraphValue<Self>, inputs: _ViewInputs) -> _ViewOutputs {
preconditionFailure("TODO")
}

nonisolated public static func _makeViewList(view: _GraphValue<ForEach<Data, ID, Content>>, inputs: _ViewListInputs) -> _ViewListOutputs {
preconditionFailure("TODO")
}
}
Loading