Skip to content

Add DynamicView #197

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 5 commits into from
Feb 16, 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
4 changes: 2 additions & 2 deletions Package.resolved

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ package struct PreferencesOutputs {
#endif

#if canImport(Darwin)
package func setIndirectDependencies(_ dependency: AnyAttribute?) {
package func setIndirectDependency(_ dependency: AnyAttribute?) {
preferences.forEach {
$0.value.indirectDependency = dependency
}
Expand Down
4 changes: 2 additions & 2 deletions Sources/OpenSwiftUICore/Data/Preference/View_Indirect.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ extension _ViewInputs {

extension _ViewOutputs {
#if canImport(Darwin)
package func setIndirectDependencies(_ dependency: AnyAttribute?) {
preferences.setIndirectDependencies(dependency)
package func setIndirectDependency(_ dependency: AnyAttribute?) {
preferences.setIndirectDependency(dependency)
if let target = layoutComputer?.identifier {
target.indirectDependency = dependency
}
Expand Down
38 changes: 33 additions & 5 deletions Sources/OpenSwiftUICore/Data/Transaction/Transaction.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
// Status: WIP
// ID: B2543BCA257433E04979186A1DC2B6BC

import OpenGraphShims
package import OpenGraphShims
import OpenSwiftUI_SPI

/// The context of the current state-processing update.
Expand Down Expand Up @@ -247,11 +247,39 @@ extension Transaction {
}
}

// MARK: - TransactionID [TODO]
// MARK: - TransactionID

package struct TransactionID/*: Comparable, Hashable */{
package struct TransactionID: Comparable, Hashable {
package var id: Int
package init(id: Int) {
self.id = id

@inlinable
package init() { id = .zero }

@inlinable
package init(graph: Graph) {
id = Int(graph.counter(for: ._1))
}

@inlinable
package init(context: AnyRuleContext) {
#if canImport(Darwin)
self.init(graph: context.attribute.graph)
#else
preconditionFailure("See #39")
#endif
}

@inlinable
package init<Value>(context: RuleContext<Value>) {
#if canImport(Darwin)
self.init(graph: context.attribute.graph)
#else
preconditionFailure("See #39")
#endif
}

@inlinable
package static func < (lhs: TransactionID, rhs: TransactionID) -> Bool {
lhs.id < rhs.id
}
}
11 changes: 6 additions & 5 deletions Sources/OpenSwiftUICore/Graph/GraphInputs.swift
Original file line number Diff line number Diff line change
Expand Up @@ -317,15 +317,16 @@ private struct MergedEnvironment: Rule, AsyncAttribute {
}
}

// FIXME: TO BE REMOVED
extension _GraphInputs {

// MARK: - cachedEnvironment
@inline(__always)
mutating func detachEnvironmentInputs() {
cachedEnvironment = MutableBox(cachedEnvironment.wrappedValue)
}

@inline(__always)
package func detechedEnvironmentInputs() -> Self {
func detachedEnvironmentInputs() -> Self {
var newInputs = self
newInputs.cachedEnvironment = MutableBox(cachedEnvironment.wrappedValue)
newInputs.detachEnvironmentInputs()
return newInputs
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@ extension ViewModifier {
) -> _ViewOutputs {
let fields = DynamicPropertyCache.fields(of: Self.self)
var inputs = inputs
let (view, buffer) = inputs.withMutateGraphInputs { inputs in
makeBody(modifier: modifier, inputs: &inputs, fields: fields)
}
let (view, buffer) = makeBody(modifier: modifier, inputs: &inputs.base, fields: fields)
inputs.append(.view(body), to: _ViewModifier_Content<Self>.BodyInput.self)
let outputs = _ViewDebug.makeView(
view: view,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,7 @@ extension ViewModifier where Self: _GraphInputsModifier, Body == Never {
body: @escaping (_Graph, _ViewInputs) -> _ViewOutputs
) -> _ViewOutputs {
var inputs = inputs
inputs.withMutateGraphInputs { inputs in
_makeInputs(modifier: modifier, inputs: &inputs)
}
_makeInputs(modifier: modifier, inputs: &inputs.base)
let outputs = body(_Graph(), inputs)
return outputs
}
Expand Down
2 changes: 1 addition & 1 deletion Sources/OpenSwiftUICore/View/AnyView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ private struct AnyViewContainer: StatefulRule, AsyncAttribute {
let childGraph = OGSubgraph(graph: parentSubgraph.graph)
parentSubgraph.addChild(childGraph)
return childGraph.apply {
let childInputs = inputs.detechedEnvironmentInputs()
let childInputs = inputs.detachedEnvironmentInputs()
let childOutputs = storage.makeChild(
uniqueId: uniqueId,
container: current.unsafeCast(to: AnyViewInfo.self),
Expand Down
4 changes: 1 addition & 3 deletions Sources/OpenSwiftUICore/View/CustomView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,7 @@ extension View {
nonisolated package static func makeView(view: _GraphValue<Self>, inputs: _ViewInputs) -> _ViewOutputs {
let fields = DynamicPropertyCache.fields(of: Self.self)
var inputs = inputs
let (body, buffer) = inputs.withMutateGraphInputs { inputs in
makeBody(view: view, inputs: &inputs, fields: fields)
}
let (body, buffer) = makeBody(view: view, inputs: &inputs.base, fields: fields)
// FIXME
let outputs = _ViewDebug.makeView(
view: body,
Expand Down
Loading
Loading