Skip to content

Commit

Permalink
Update ModifiedContent implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
Kyle-Ye committed May 5, 2024
1 parent 3c5bc95 commit 06b7f78
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 12 deletions.
4 changes: 2 additions & 2 deletions Package.resolved
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
{
"originHash" : "c92107a159713b44e293a2fe944a02f419f98dc401c81653bfee56d07c8a2b70",
"originHash" : "807d4a48456544b2827b8d4f69dc5e39b01103e9105f11c138529cc3159d18d4",
"pins" : [
{
"identity" : "opengraph",
"kind" : "remoteSourceControl",
"location" : "https://github.com/OpenSwiftUIProject/OpenGraph",
"state" : {
"branch" : "main",
"revision" : "acbee3c7c30cac49d64a8f619f3e3856a4e943f8"
"revision" : "47a81fde4bfa4092577abd29122206c19ad0cf98"
}
},
{
Expand Down
66 changes: 61 additions & 5 deletions Sources/OpenSwiftUI/Core/Modifier/ModifiedContent.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,34 @@

extension View {
@inlinable
@inline(__always)
public func modifier<T>(_ modifier: T) -> ModifiedContent<Self, T> {
.init(content: self, modifier: modifier)
}
}

/// A value with a modifier applied to it.
@frozen
public struct ModifiedContent<Content, Modifier> {
public typealias Body = Never

/// The content that the modifier transforms into a new view or new
/// view modifier.
public var content: Content

/// The view modifier.
public var modifier: Modifier

/// A structure that the defines the content and modifier needed to produce
/// a new view or view modifier.
///
/// If `content` is a ``View`` and `modifier` is a ``ViewModifier``, the
/// result is a ``View``. If `content` and `modifier` are both view
/// modifiers, then the result is a new ``ViewModifier`` combining them.
///
/// - Parameters:
/// - content: The content that the modifier changes.
/// - modifier: The modifier to apply to the content.
@inlinable
@inline(__always)
public init(content: Content, modifier: Modifier) {
self.content = content
self.modifier = modifier
Expand All @@ -34,9 +48,51 @@ extension ModifiedContent: Equatable where Content: Equatable, Modifier: Equatab
}

extension ModifiedContent: View where Content: View, Modifier: ViewModifier {
// public static func _makeView(view: _GraphValue<ModifiedContent<Content, Modifier>>, inputs: _ViewInputs) -> _ViewOutputs
// public static func _makeViewList(view: _GraphValue<ModifiedContent<Content, Modifier>>, inputs: _ViewListInputs) -> _ViewListOutputs
// public static func _viewListCount(inputs: _ViewListCountInputs) -> Int?
public static func _makeView(
view: _GraphValue<Self>,
inputs: _ViewInputs
) -> _ViewOutputs {
_ViewDebug.makeView(
view: view[offset: { .of(&$0.modifier) }],
inputs: inputs
) { modifier, inputs in
Modifier._makeView(
modifier: modifier,
inputs: inputs
) { _, inputs in
_ViewDebug.makeView(
view: view[offset: { .of(&$0.content) }],
inputs: inputs
) { view, inputs in
Content._makeView(view: view, inputs: inputs)
}
}
}
}

public static func _makeViewList(
view: _GraphValue<Self>,
inputs: _ViewListInputs
) -> _ViewListOutputs {
Modifier.makeDebuggableViewList(
modifier: view[offset: { .of(&$0.modifier) }],
inputs: inputs
) { _, inputs in
Content.makeDebuggableViewList(
view: view[offset: { .of(&$0.content) }],
inputs: inputs
)
}
}

public static func _viewListCount(
inputs: _ViewListCountInputs
) -> Int? {
Modifier._viewListCount(inputs: inputs) { inputs in
Content._viewListCount(inputs: inputs)
}
}

public var body: ModifiedContent<Content, Modifier>.Body {
bodyError()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public struct _ViewModifier_Content<Modifier: ViewModifier>: PrimitiveView {
case let .view(makeViewBody):
return makeViewBody(_Graph(), inputs)
case let .list(makeViewListBody):
fatalError("TODO")
fatalError("TODO: \(String(describing: makeViewListBody))")
}
}

Expand Down
30 changes: 26 additions & 4 deletions Sources/OpenSwiftUI/View/Debug/TODO/ViewDebug.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,31 @@ import Foundation
internal import COpenSwiftUI
internal import OpenGraphShims

// MARK: View and ViewModifier

extension View {
static func makeDebuggableViewList(
view: _GraphValue<Self>,
inputs: _ViewListInputs
) -> _ViewListOutputs {
OGSubgraph.beginTreeElement(value: view.value, flags: 1)
defer { OGSubgraph.endTreeElement(value: view.value) }
return _makeViewList(view: view, inputs: inputs)
}
}

extension ViewModifier {
static func makeDebuggableViewList(
modifier: _GraphValue<Self>,
inputs: _ViewListInputs,
body: @escaping (_Graph, _ViewListInputs) -> _ViewListOutputs
) -> _ViewListOutputs {
OGSubgraph.beginTreeElement(value: modifier.value, flags: 1)
defer { OGSubgraph.endTreeElement(value: modifier.value) }
return _makeViewList(modifier: modifier, inputs: inputs, body: body)
}
}

// MARK: _ViewDebug

public enum _ViewDebug {
Expand Down Expand Up @@ -42,17 +67,14 @@ extension _ViewDebug {
}
}

@_transparent
@inline(__always)
static func makeView<Value>(
view: _GraphValue<Value>,
inputs: _ViewInputs,
body: (_ view: _GraphValue<Value>, _ inputs: _ViewInputs) -> _ViewOutputs
) -> _ViewOutputs {
var inputs = inputs
if OGSubgraph.shouldRecordTree {
OGSubgraph.beginTreeElement(value: view.value, flags: 0)
}
OGSubgraph.beginTreeElement(value: view.value, flags: 0)
var outputs = inputs.withEmptyChangedDebugPropertiesInputs { inputs in
body(view, inputs)
}
Expand Down

0 comments on commit 06b7f78

Please sign in to comment.