Skip to content

Commit 170875a

Browse files
authored
Add DynamicView (#197)
* Add DynamicView interface * Add DynamicViewContainer * Format ViewList * Add DynamicViewList * Fix OG API and Linux build issue
1 parent 7e4a6f3 commit 170875a

File tree

12 files changed

+501
-83
lines changed

12 files changed

+501
-83
lines changed

Package.resolved

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"location" : "https://github.com/OpenSwiftUIProject/DarwinPrivateFrameworks.git",
88
"state" : {
99
"branch" : "main",
10-
"revision" : "932885521bc9164670aee302de2329116da11bc6"
10+
"revision" : "2cec508df7d16801a1bb5b659b906cec465b213e"
1111
}
1212
},
1313
{
@@ -25,7 +25,7 @@
2525
"location" : "https://github.com/OpenSwiftUIProject/OpenGraph",
2626
"state" : {
2727
"branch" : "main",
28-
"revision" : "5992cb5119cf2a7d294a535d76e6e6e1ef0d0ef4"
28+
"revision" : "40b020c8e1cf93f0eab1e5f70476bc31fe429620"
2929
}
3030
},
3131
{

Sources/OpenSwiftUICore/Data/Preference/PreferencesOutputs.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ package struct PreferencesOutputs {
7474
#endif
7575

7676
#if canImport(Darwin)
77-
package func setIndirectDependencies(_ dependency: AnyAttribute?) {
77+
package func setIndirectDependency(_ dependency: AnyAttribute?) {
7878
preferences.forEach {
7979
$0.value.indirectDependency = dependency
8080
}

Sources/OpenSwiftUICore/Data/Preference/View_Indirect.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ extension _ViewInputs {
3131

3232
extension _ViewOutputs {
3333
#if canImport(Darwin)
34-
package func setIndirectDependencies(_ dependency: AnyAttribute?) {
35-
preferences.setIndirectDependencies(dependency)
34+
package func setIndirectDependency(_ dependency: AnyAttribute?) {
35+
preferences.setIndirectDependency(dependency)
3636
if let target = layoutComputer?.identifier {
3737
target.indirectDependency = dependency
3838
}

Sources/OpenSwiftUICore/Data/Transaction/Transaction.swift

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
// Status: WIP
77
// ID: B2543BCA257433E04979186A1DC2B6BC
88

9-
import OpenGraphShims
9+
package import OpenGraphShims
1010
import OpenSwiftUI_SPI
1111

1212
/// The context of the current state-processing update.
@@ -247,11 +247,39 @@ extension Transaction {
247247
}
248248
}
249249

250-
// MARK: - TransactionID [TODO]
250+
// MARK: - TransactionID
251251

252-
package struct TransactionID/*: Comparable, Hashable */{
252+
package struct TransactionID: Comparable, Hashable {
253253
package var id: Int
254-
package init(id: Int) {
255-
self.id = id
254+
255+
@inlinable
256+
package init() { id = .zero }
257+
258+
@inlinable
259+
package init(graph: Graph) {
260+
id = Int(graph.counter(for: ._1))
261+
}
262+
263+
@inlinable
264+
package init(context: AnyRuleContext) {
265+
#if canImport(Darwin)
266+
self.init(graph: context.attribute.graph)
267+
#else
268+
preconditionFailure("See #39")
269+
#endif
270+
}
271+
272+
@inlinable
273+
package init<Value>(context: RuleContext<Value>) {
274+
#if canImport(Darwin)
275+
self.init(graph: context.attribute.graph)
276+
#else
277+
preconditionFailure("See #39")
278+
#endif
279+
}
280+
281+
@inlinable
282+
package static func < (lhs: TransactionID, rhs: TransactionID) -> Bool {
283+
lhs.id < rhs.id
256284
}
257285
}

Sources/OpenSwiftUICore/Graph/GraphInputs.swift

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -317,15 +317,16 @@ private struct MergedEnvironment: Rule, AsyncAttribute {
317317
}
318318
}
319319

320-
// FIXME: TO BE REMOVED
321320
extension _GraphInputs {
322-
323-
// MARK: - cachedEnvironment
321+
@inline(__always)
322+
mutating func detachEnvironmentInputs() {
323+
cachedEnvironment = MutableBox(cachedEnvironment.wrappedValue)
324+
}
324325

325326
@inline(__always)
326-
package func detechedEnvironmentInputs() -> Self {
327+
func detachedEnvironmentInputs() -> Self {
327328
var newInputs = self
328-
newInputs.cachedEnvironment = MutableBox(cachedEnvironment.wrappedValue)
329+
newInputs.detachEnvironmentInputs()
329330
return newInputs
330331
}
331332
}

Sources/OpenSwiftUICore/Modifier/ViewModifier/CustomViewModifier.swift

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,7 @@ extension ViewModifier {
1818
) -> _ViewOutputs {
1919
let fields = DynamicPropertyCache.fields(of: Self.self)
2020
var inputs = inputs
21-
let (view, buffer) = inputs.withMutateGraphInputs { inputs in
22-
makeBody(modifier: modifier, inputs: &inputs, fields: fields)
23-
}
21+
let (view, buffer) = makeBody(modifier: modifier, inputs: &inputs.base, fields: fields)
2422
inputs.append(.view(body), to: _ViewModifier_Content<Self>.BodyInput.self)
2523
let outputs = _ViewDebug.makeView(
2624
view: view,

Sources/OpenSwiftUICore/Modifier/ViewModifier/ViewModifier.swift

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,9 +107,7 @@ extension ViewModifier where Self: _GraphInputsModifier, Body == Never {
107107
body: @escaping (_Graph, _ViewInputs) -> _ViewOutputs
108108
) -> _ViewOutputs {
109109
var inputs = inputs
110-
inputs.withMutateGraphInputs { inputs in
111-
_makeInputs(modifier: modifier, inputs: &inputs)
112-
}
110+
_makeInputs(modifier: modifier, inputs: &inputs.base)
113111
let outputs = body(_Graph(), inputs)
114112
return outputs
115113
}

Sources/OpenSwiftUICore/View/AnyView.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ private struct AnyViewContainer: StatefulRule, AsyncAttribute {
188188
let childGraph = OGSubgraph(graph: parentSubgraph.graph)
189189
parentSubgraph.addChild(childGraph)
190190
return childGraph.apply {
191-
let childInputs = inputs.detechedEnvironmentInputs()
191+
let childInputs = inputs.detachedEnvironmentInputs()
192192
let childOutputs = storage.makeChild(
193193
uniqueId: uniqueId,
194194
container: current.unsafeCast(to: AnyViewInfo.self),

Sources/OpenSwiftUICore/View/CustomView.swift

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,7 @@ extension View {
2525
nonisolated package static func makeView(view: _GraphValue<Self>, inputs: _ViewInputs) -> _ViewOutputs {
2626
let fields = DynamicPropertyCache.fields(of: Self.self)
2727
var inputs = inputs
28-
let (body, buffer) = inputs.withMutateGraphInputs { inputs in
29-
makeBody(view: view, inputs: &inputs, fields: fields)
30-
}
28+
let (body, buffer) = makeBody(view: view, inputs: &inputs.base, fields: fields)
3129
// FIXME
3230
let outputs = _ViewDebug.makeView(
3331
view: body,

0 commit comments

Comments
 (0)