diff --git a/Package.resolved b/Package.resolved index 7905b930..f288005d 100644 --- a/Package.resolved +++ b/Package.resolved @@ -6,7 +6,7 @@ "location" : "https://github.com/OpenSwiftUIProject/OpenGraph", "state" : { "branch" : "main", - "revision" : "2435a0a02b3ab3b97799a8f387284686fe9e6a7a" + "revision" : "ed01e7196afe56bf953f2f14b0b463208dda9c8d" } }, { diff --git a/Sources/OpenSwiftUI/Core/Attribute/AsyncAttribute.swift b/Sources/OpenSwiftUI/Core/Attribute/AsyncAttribute.swift new file mode 100644 index 00000000..a92582b5 --- /dev/null +++ b/Sources/OpenSwiftUI/Core/Attribute/AsyncAttribute.swift @@ -0,0 +1,16 @@ +// +// AsyncAttribute.swift +// OpenSwiftUI +// +// Audited for RELEASE_2021 +// Status: WIP + +internal import OpenGraphShims + +protocol AsyncAttribute: _AttributeBody {} + +extension Attribute { + func syncMainIfReferences(do body: (Value) -> V) -> V { + fatalError("TODO") + } +} diff --git a/Sources/OpenSwiftUI/Core/Data/Boxes/Indirect.swift b/Sources/OpenSwiftUI/Core/Data/Boxes/Indirect.swift index 70824a01..79fd0678 100644 --- a/Sources/OpenSwiftUI/Core/Data/Boxes/Indirect.swift +++ b/Sources/OpenSwiftUI/Core/Data/Boxes/Indirect.swift @@ -8,7 +8,7 @@ struct Indirect { var box : MutableBox - var value: A { box.value } + var value: A { box.wrappedValue } } extension Indirect: Equatable where A: Equatable { diff --git a/Sources/OpenSwiftUI/Core/Data/Boxes/MutableBox.swift b/Sources/OpenSwiftUI/Core/Data/Boxes/MutableBox.swift index 11cde23a..07fbca72 100644 --- a/Sources/OpenSwiftUI/Core/Data/Boxes/MutableBox.swift +++ b/Sources/OpenSwiftUI/Core/Data/Boxes/MutableBox.swift @@ -7,7 +7,7 @@ @propertyWrapper final class MutableBox { - var value: A + private var value: A var wrappedValue: A { get { value } diff --git a/Sources/OpenSwiftUI/Data/Environment/CachedEnvironment.swift b/Sources/OpenSwiftUI/Data/Environment/CachedEnvironment.swift new file mode 100644 index 00000000..be8bb48c --- /dev/null +++ b/Sources/OpenSwiftUI/Data/Environment/CachedEnvironment.swift @@ -0,0 +1,132 @@ +// +// CachedEnvironment.swift +// OpenSwiftUI +// +// Audited for RELEASE_2021 +// Status: WIP +// ID: C424ABD9FC88B2DFD0B7B2319F2E7987 + +import Foundation +internal import OpenGraphShims + +struct CachedEnvironment { + var environment: Attribute + private var items: [Item] + #if canImport(Darwin) + private var constants: [HashableConstant: OGAttribute] + #endif + private var animatedFrame: AnimatedFrame? + // private var resolvedFgStyles: [ResolvedFgStyle : Swift<_ShapeStyle_Resolved.ResolvedFg>] + + init(_ environment: Attribute) { + self.environment = environment + items = [] + #if canImport(Darwin) + constants = [:] + #endif + animatedFrame = nil + // resolvedFgStyles = [:] + } + + func intern(_ value: Value, id: Int) -> Attribute { + fatalError("TODO") + } + + func animatePosition(for inputs: _ViewInputs) -> Attribute { + fatalError("TODO") + } + + func animateSize(for inputs: _ViewInputs) -> Attribute { + fatalError("TODO") + } + + // func resolvedForegroundStyle() {} +} + +extension CachedEnvironment { + private struct Item { + var key: PartialKeyPath + #if canImport(Darwin) + var value: OGAttribute + #endif + } +} + +private protocol _Constant { + func hash(into hasher: inout Hasher) + func isEqual(to other: _Constant) -> Bool +} + +private struct Constant: _Constant { + let value: Value + let id: Int + + init(_ value: Value, id: Int) { + self.value = value + self.id = id + } + + func hash(into hasher: inout Hasher) { + hasher.combine(ObjectIdentifier(Value.self)) + hasher.combine(id) + } + + func isEqual(to other: _Constant) -> Bool { + let otherConstant = other as? Constant + return otherConstant.map { id == $0.id } ?? false + } +} + +private struct HashableConstant: Hashable { + let value: _Constant + + init(_ value: Value, id: Int) { + self.value = Constant(value, id: id) + } + + func hash(into hasher: inout Hasher) { + value.hash(into: &hasher) + } + + static func == (lhs: HashableConstant, rhs: HashableConstant) -> Bool { + lhs.value.isEqual(to: rhs.value) + } +} + +private struct AnimatedFrame { + let position: Attribute + let size: Attribute + let pixelLength: Attribute + let time: Attribute