Skip to content

Commit

Permalink
Update VariadicView
Browse files Browse the repository at this point in the history
  • Loading branch information
Kyle-Ye committed Aug 28, 2024
1 parent 7ca6fce commit 23c7a9e
Show file tree
Hide file tree
Showing 7 changed files with 142 additions and 4 deletions.
54 changes: 54 additions & 0 deletions Sources/OpenSwiftUI/Core/View/VariadicView/ForEach.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
//
// ForEach.swift
// OpenSwiftUI
//
// Audited for RELEASE_2021
// Status: WIP

/// A structure that computes views on demand from an underlying collection of
/// identified data.
///
/// Use `ForEach` to provide views based on a
/// [RandomAccessCollection](https://developer.apple.com/documentation/swift/randomaccesscollection)
/// of some data type. Either the collection's elements must conform to
/// [Identifiable](https://developer.apple.com/documentation/swift/identifiable) or you
/// need to provide an `id` parameter to the `ForEach` initializer.
///
/// The following example creates a `NamedFont` type that conforms to
/// [Identifiable](https://developer.apple.com/documentation/swift/identifiable), and an
/// array of this type called `namedFonts`. A `ForEach` instance iterates
/// over the array, producing new ``Text`` instances that display examples
/// of each OpenSwiftUI ``Font`` style provided in the array.
///
/// private struct NamedFont: Identifiable {
/// let name: String
/// let font: Font
/// var id: String { name }
/// }
///
/// private let namedFonts: [NamedFont] = [
/// NamedFont(name: "Large Title", font: .largeTitle),
/// NamedFont(name: "Title", font: .title),
/// NamedFont(name: "Headline", font: .headline),
/// NamedFont(name: "Body", font: .body),
/// NamedFont(name: "Caption", font: .caption)
/// ]
///
/// var body: some View {
/// ForEach(namedFonts) { namedFont in
/// Text(namedFont.name)
/// .font(namedFont.font)
/// }
/// }
///
/// ![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
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,69 @@
// TODO
//
// VariadicView_Children.swift
// OpenSwiftUI
//
// Audited for RELEASE_2021
// Status: TODO
// ID: 52A2FFECFBCF37BFFEED558E33EBD1E3

internal import OpenGraphShims

/// An ad hoc collection of the children of a variadic view.
public struct _VariadicView_Children {
var list: ViewList
var contentSubgraph: OGSubgraph
}

extension _VariadicView_Children: RandomAccessCollection {
public struct Element: PrimitiveView, UnaryView, Identifiable {

// var view: _ViewList_View
var traits: ViewTraitCollection

public var id: AnyHashable {
// view.viewID
fatalError("TODO")

Check warning on line 26 in Sources/OpenSwiftUI/Core/View/VariadicView/VariadicView_Children.swift

View check run for this annotation

Codecov / codecov/patch

Sources/OpenSwiftUI/Core/View/VariadicView/VariadicView_Children.swift#L23-L26

Added lines #L23 - L26 were not covered by tests
}
public func id<ID>(as _: ID.Type = ID.self) -> ID? where ID : Hashable {
fatalError("TODO")

Check warning on line 29 in Sources/OpenSwiftUI/Core/View/VariadicView/VariadicView_Children.swift

View check run for this annotation

Codecov / codecov/patch

Sources/OpenSwiftUI/Core/View/VariadicView/VariadicView_Children.swift#L28-L29

Added lines #L28 - L29 were not covered by tests
}

public subscript<Trait: _ViewTraitKey>(key: Trait.Type) -> Trait.Value {
get { traits[key] }
set { traits[key] = newValue }

Check warning on line 34 in Sources/OpenSwiftUI/Core/View/VariadicView/VariadicView_Children.swift

View check run for this annotation

Codecov / codecov/patch

Sources/OpenSwiftUI/Core/View/VariadicView/VariadicView_Children.swift#L33-L34

Added lines #L33 - L34 were not covered by tests
}

public static func _makeView(view: _GraphValue<_VariadicView_Children.Element>, inputs: _ViewInputs) -> _ViewOutputs {
fatalError("TODO")

Check warning on line 38 in Sources/OpenSwiftUI/Core/View/VariadicView/VariadicView_Children.swift

View check run for this annotation

Codecov / codecov/patch

Sources/OpenSwiftUI/Core/View/VariadicView/VariadicView_Children.swift#L37-L38

Added lines #L37 - L38 were not covered by tests
}
}

public var startIndex: Int {
fatalError("TODO")

// get

Check warning on line 45 in Sources/OpenSwiftUI/Core/View/VariadicView/VariadicView_Children.swift

View check run for this annotation

Codecov / codecov/patch

Sources/OpenSwiftUI/Core/View/VariadicView/VariadicView_Children.swift#L42-L45

Added lines #L42 - L45 were not covered by tests
}
public var endIndex: Int {
fatalError("TODO")

// get

Check warning on line 50 in Sources/OpenSwiftUI/Core/View/VariadicView/VariadicView_Children.swift

View check run for this annotation

Codecov / codecov/patch

Sources/OpenSwiftUI/Core/View/VariadicView/VariadicView_Children.swift#L47-L50

Added lines #L47 - L50 were not covered by tests
}
public subscript(index: Int) -> _VariadicView_Children.Element {
fatalError("TODO")

// get

Check warning on line 55 in Sources/OpenSwiftUI/Core/View/VariadicView/VariadicView_Children.swift

View check run for this annotation

Codecov / codecov/patch

Sources/OpenSwiftUI/Core/View/VariadicView/VariadicView_Children.swift#L52-L55

Added lines #L52 - L55 were not covered by tests
}
}

extension _VariadicView_Children {
private struct Child: Rule, AsyncAttribute {
typealias Value = ForEach<_VariadicView_Children, AnyHashable, _VariadicView_Children.Element>

@Attribute var children: _VariadicView_Children

var value: Value {
fatalError("TODO")

Check warning on line 66 in Sources/OpenSwiftUI/Core/View/VariadicView/VariadicView_Children.swift

View check run for this annotation

Codecov / codecov/patch

Sources/OpenSwiftUI/Core/View/VariadicView/VariadicView_Children.swift#L65-L66

Added lines #L65 - L66 were not covered by tests
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
//
// Audited for RELEASE_2021
// Status: WIP
// ID: 00F12C0E37A19C593ECA0DBD3BE26541

internal import OpenGraphShims

Expand Down
3 changes: 1 addition & 2 deletions Sources/OpenSwiftUI/Core/View/ViewList/ViewListInputs.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ public struct _ViewListInputs {
private var base: _GraphInputs
var implicitID: Int
var options: _ViewListInputs.Options
@OptionalAttribute
var traits: ViewTraitCollection?
@OptionalAttribute var traits: ViewTraitCollection?
var traitKeys: ViewTraitKeys?

struct Options: OptionSet {
Expand Down
12 changes: 12 additions & 0 deletions Sources/OpenSwiftUI/Core/View/ViewList/ViewList_ID.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// ID: 70E71091E926A1B09B75AAEB38F5AA3F

struct _ViewList_ID {
var _index: Int32
var implicitID: Int32
private var explicitIDs: [Explicit]
}

extension _ViewList_ID {
private struct Explicit {
}
}
9 changes: 9 additions & 0 deletions Sources/OpenSwiftUI/Core/View/ViewList/ViewList_View.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
internal import OpenGraphShims

struct _ViewList_View {
var elements: _ViewList_Elements
var id: _ViewList_ID
var index: Int
var count: Int
var contentSubgraph: OGSubgraph
}
2 changes: 1 addition & 1 deletion Sources/OpenSwiftUI/Core/View/ViewTrait/ViewTraitKey.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
// Audited for RELEASE_2021
// Status: Complete

protocol _ViewTraitKey {
public protocol _ViewTraitKey {
associatedtype Value
static var defaultValue: Value { get }
}

0 comments on commit 23c7a9e

Please sign in to comment.