diff --git a/Sources/OpenSwiftUI/Core/View/TODO/_ViewListCountInputs.swift b/Sources/OpenSwiftUI/Core/View/TODO/_ViewListCountInputs.swift deleted file mode 100644 index 637c5ecb..00000000 --- a/Sources/OpenSwiftUI/Core/View/TODO/_ViewListCountInputs.swift +++ /dev/null @@ -1,5 +0,0 @@ -public struct _ViewListCountInputs { -// var customInputs : PropertyList -// var options : _ViewListInputs.Options -// var baseOptions : _GraphInputs.Options -} diff --git a/Sources/OpenSwiftUI/Core/View/TODO/_ViewListInputs.swift b/Sources/OpenSwiftUI/Core/View/TODO/_ViewListInputs.swift deleted file mode 100644 index 30b42dda..00000000 --- a/Sources/OpenSwiftUI/Core/View/TODO/_ViewListInputs.swift +++ /dev/null @@ -1,2 +0,0 @@ -public struct _ViewListInputs { -} diff --git a/Sources/OpenSwiftUI/Core/View/TODO/_ViewListOutputs.swift b/Sources/OpenSwiftUI/Core/View/TODO/_ViewListOutputs.swift deleted file mode 100644 index bb938b7a..00000000 --- a/Sources/OpenSwiftUI/Core/View/TODO/_ViewListOutputs.swift +++ /dev/null @@ -1,2 +0,0 @@ -public struct _ViewListOutputs { -} diff --git a/Sources/OpenSwiftUI/Core/View/ViewInput.swift b/Sources/OpenSwiftUI/Core/View/View/ViewInput.swift similarity index 100% rename from Sources/OpenSwiftUI/Core/View/ViewInput.swift rename to Sources/OpenSwiftUI/Core/View/View/ViewInput.swift diff --git a/Sources/OpenSwiftUI/Core/View/TODO/ViewInputBoolFlag.swift b/Sources/OpenSwiftUI/Core/View/View/ViewInputBoolFlag.swift similarity index 100% rename from Sources/OpenSwiftUI/Core/View/TODO/ViewInputBoolFlag.swift rename to Sources/OpenSwiftUI/Core/View/View/ViewInputBoolFlag.swift diff --git a/Sources/OpenSwiftUI/Core/View/ViewInputs.swift b/Sources/OpenSwiftUI/Core/View/View/ViewInputs.swift similarity index 97% rename from Sources/OpenSwiftUI/Core/View/ViewInputs.swift rename to Sources/OpenSwiftUI/Core/View/View/ViewInputs.swift index a35197ad..6df008a4 100644 --- a/Sources/OpenSwiftUI/Core/View/ViewInputs.swift +++ b/Sources/OpenSwiftUI/Core/View/View/ViewInputs.swift @@ -1,3 +1,10 @@ +// +// ViewInputs.swift +// OpenSwiftUI +// +// Audited for RELEASE_2021 +// Status: WIP + internal import OpenGraphShims public struct _ViewInputs { diff --git a/Sources/OpenSwiftUI/Core/View/ViewOutputs.swift b/Sources/OpenSwiftUI/Core/View/View/ViewOutputs.swift similarity index 100% rename from Sources/OpenSwiftUI/Core/View/ViewOutputs.swift rename to Sources/OpenSwiftUI/Core/View/View/ViewOutputs.swift diff --git a/Sources/OpenSwiftUI/Core/View/ViewList/ViewListCountInputs.swift b/Sources/OpenSwiftUI/Core/View/ViewList/ViewListCountInputs.swift new file mode 100644 index 00000000..07d685dc --- /dev/null +++ b/Sources/OpenSwiftUI/Core/View/ViewList/ViewListCountInputs.swift @@ -0,0 +1,32 @@ +// +// ViewListCountInputs.swift +// OpenSwiftUI +// +// Audited for RELEASE_2021 +// Status: WIP + +public struct _ViewListCountInputs { + var customInputs : PropertyList + var options : _ViewListInputs.Options + var baseOptions : _GraphInputs.Options + + subscript(_ type: Input.Type) -> Input.Value { + get { customInputs[type] } + set { customInputs[type] = newValue } + } + + mutating func popLast(_ type: Input.Type) -> Value? where Input.Value == [Value] { + var values = self[type] + guard let value = values.popLast() else { + return nil + } + self[type] = values + return value + } + + mutating func append(_ value: Value, to type: Input.Type) where Input.Value == [Value] { + var values = self[type] + values.append(value) + self[type] = values + } +} diff --git a/Sources/OpenSwiftUI/Core/View/ViewList/ViewListInputs.swift b/Sources/OpenSwiftUI/Core/View/ViewList/ViewListInputs.swift new file mode 100644 index 00000000..f7598c47 --- /dev/null +++ b/Sources/OpenSwiftUI/Core/View/ViewList/ViewListInputs.swift @@ -0,0 +1,21 @@ +// +// ViewListInputs.swift +// OpenSwiftUI +// +// Audited for RELEASE_2021 +// Status: WIP + +internal import OpenGraphShims + +public struct _ViewListInputs { + var base: _GraphInputs + var implicitID: Int + var options: _ViewListInputs.Options + @OptionalAttribute + var traits: ViewTraitCollection? + var traitKeys: ViewTraitKeys? + + struct Options: OptionSet { + let rawValue: Int + } +} diff --git a/Sources/OpenSwiftUI/Core/View/ViewList/ViewListOutputs.swift b/Sources/OpenSwiftUI/Core/View/ViewList/ViewListOutputs.swift new file mode 100644 index 00000000..649cc181 --- /dev/null +++ b/Sources/OpenSwiftUI/Core/View/ViewList/ViewListOutputs.swift @@ -0,0 +1,31 @@ +// +// ViewListOutputs.swift +// OpenSwiftUI +// +// Audited for RELEASE_2021 +// Status: WIP + +internal import OpenGraphShims + +public struct _ViewListOutputs { + var views: Views + var nextImplicitID: Int + var staticCount: Int? + + enum Views { + case staticList(_ViewList_Elements) + case dynamicList(Attribute, ListModifier?) + } + + class ListModifier { + init() {} + + func apply(to: inout ViewList) { + // TODO + } + } +} + +// TODO +protocol ViewList { +} diff --git a/Sources/OpenSwiftUI/Core/View/ViewList/ViewList_Elements.swift b/Sources/OpenSwiftUI/Core/View/ViewList/ViewList_Elements.swift new file mode 100644 index 00000000..058f4b79 --- /dev/null +++ b/Sources/OpenSwiftUI/Core/View/ViewList/ViewList_Elements.swift @@ -0,0 +1,18 @@ +// +// ViewList_Elements.swift +// OpenSwiftUI +// +// Audited for RELEASE_2021 +// Status: WIP + +protocol _ViewList_Elements { + var count: Int { get } + func makeElements( + from: inout Int, + inputs: _ViewInputs, + indirectMap: _ViewList_IndirectMap?, + body: (_ViewInputs, (_ViewInputs) -> _ViewOutputs) -> (_ViewOutputs?, Bool) + ) -> (_ViewOutputs?, Bool) + func tryToReuseElement(at: Int, by: _ViewList_Elements, at: Int, indirectMap: _ViewList_IndirectMap, testOnly: Bool) -> Bool + func retain() -> () -> Void +} diff --git a/Sources/OpenSwiftUI/Core/View/ViewList/ViewList_IndirectMap.swift b/Sources/OpenSwiftUI/Core/View/ViewList/ViewList_IndirectMap.swift new file mode 100644 index 00000000..2cd7ca65 --- /dev/null +++ b/Sources/OpenSwiftUI/Core/View/ViewList/ViewList_IndirectMap.swift @@ -0,0 +1,23 @@ +// +// ViewList_IndirectMap.swift +// OpenSwiftUI +// +// Audited for RELEASE_2021 +// Status: WIP +// ID: 70E71091E926A1B09B75AAEB38F5AA3F + +internal import OpenGraphShims + +final class _ViewList_IndirectMap { + let subgraph: OGSubgraph + #if canImport(Darwin) + private var map: [OGAttribute: OGAttribute] + #endif + + init(subgraph: OGSubgraph) { + self.subgraph = subgraph + #if canImport(Darwin) + self.map = [:] + #endif + } +} diff --git a/Sources/OpenSwiftUI/Core/View/ViewList/ViewList_Subgraph.swift b/Sources/OpenSwiftUI/Core/View/ViewList/ViewList_Subgraph.swift new file mode 100644 index 00000000..31c2ea09 --- /dev/null +++ b/Sources/OpenSwiftUI/Core/View/ViewList/ViewList_Subgraph.swift @@ -0,0 +1,47 @@ +// +// ViewList_Subgraph.swift +// OpenSwiftUI +// +// Audited for RELEASE_2021 +// Status: WIP +// ID: 70E71091E926A1B09B75AAEB38F5AA3F + +internal import OpenGraphShims + +class _ViewList_Subgraph { + let subgraph: OGSubgraph + private var refcount : UInt32 + + init(subgraph: OGSubgraph) { + self.subgraph = subgraph + self.refcount = 1 // TODO + } + + func invalidate() {} +} + +extension _ViewList_Subgraph { + var isValid: Bool { + guard refcount > 0 else { + return false + } + return subgraph.isValid + } + + func retain() { + refcount &+= 1 + } + + func release(isInserted: Bool) { + refcount &-= 1 + guard refcount == 0 else { + return + } + invalidate() + guard subgraph.isValid else { + return + } + subgraph.willInvalidate(isInserted: isInserted) + subgraph.invalidate() + } +} diff --git a/Sources/OpenSwiftUI/Core/View/ViewTrait/ViewTraitCollection.swift b/Sources/OpenSwiftUI/Core/View/ViewTrait/ViewTraitCollection.swift new file mode 100644 index 00000000..e4b35858 --- /dev/null +++ b/Sources/OpenSwiftUI/Core/View/ViewTrait/ViewTraitCollection.swift @@ -0,0 +1,63 @@ +// +// ViewTraitCollection.swift +// OpenSwiftUI +// +// Audited for RELEASE_2021 +// Status: WIP +// ID: 9929B476764059557433A108298EE66F + +struct ViewTraitCollection { + private var storage: [any AnyViewTrait] + + private struct AnyTrait: AnyViewTrait { + var value: Key.Value + + init(value: Key.Value) { + self.value = value + } + + var id: ObjectIdentifier { ObjectIdentifier(Key.self) } + + subscript() -> V { + get { value as! V } + set { value = newValue as! Key.Value } + } + } + + subscript(_: Key.Type) -> Key.Value { + get { + value(for: Key.self) + } + set { + if let index = storage.firstIndex(where: { $0.id == ObjectIdentifier(Key.self) }) { + storage[index][] = newValue + } else { + storage.append(AnyTrait(value: newValue)) + } + } + } + + func value(for _: Key.Type, defaultValue: Key.Value = Key.defaultValue) -> Key.Value { + storage.first { $0.id == ObjectIdentifier(Key.self) }?[] ?? defaultValue + } + + mutating func setValueIfUnset(_ value: Key.Value, for _: Key.Type) { + guard !storage.contains(where: { $0.id == ObjectIdentifier(Key.self) }) else { + return + } + storage.append(AnyTrait(value: value)) + } + +// func insertInteraction(for: OnInsertInteraction.Strategy) -> OnInsertInteraction? { +// fatalError("TODO") +// } +// +// var optionalTransition: AnyTransition? { +// fatalError("TODO") +// } +} + +private protocol AnyViewTrait { + var id: ObjectIdentifier { get } + subscript() -> V { get set } +} diff --git a/Sources/OpenSwiftUI/Core/View/ViewTrait/ViewTraitKey.swift b/Sources/OpenSwiftUI/Core/View/ViewTrait/ViewTraitKey.swift new file mode 100644 index 00000000..1c613487 --- /dev/null +++ b/Sources/OpenSwiftUI/Core/View/ViewTrait/ViewTraitKey.swift @@ -0,0 +1,11 @@ +// +// ViewTraitKey.swift +// OpenSwiftUI +// +// Audited for RELEASE_2021 +// Status: Complete + +protocol _ViewTraitKey { + associatedtype Value + static var defaultValue: Value { get } +} diff --git a/Sources/OpenSwiftUI/Core/View/ViewTrait/ViewTraitKeys.swift b/Sources/OpenSwiftUI/Core/View/ViewTrait/ViewTraitKeys.swift new file mode 100644 index 00000000..3f0d80b6 --- /dev/null +++ b/Sources/OpenSwiftUI/Core/View/ViewTrait/ViewTraitKeys.swift @@ -0,0 +1,19 @@ +// +// ViewTraitKeys.swift +// OpenSwiftUI +// +// Audited for RELEASE_2021 +// Status: Complete + +struct ViewTraitKeys { + var types: Set + var isDataDependent: Bool + + mutating func insert(_ type: Key.Type) { + types.insert(ObjectIdentifier(type)) + } + + func contains(_ type: Key.Type) -> Bool { + types.contains(ObjectIdentifier(type)) + } +} diff --git a/Sources/OpenSwiftUI/View/Animation/TODO/AnimatableModifier.swift b/Sources/OpenSwiftUI/View/Animation/TODO/AnimatableModifier.swift index f5501752..a06ca6ae 100644 --- a/Sources/OpenSwiftUI/View/Animation/TODO/AnimatableModifier.swift +++ b/Sources/OpenSwiftUI/View/Animation/TODO/AnimatableModifier.swift @@ -15,7 +15,7 @@ extension AnimatableModifier { } public static func _makeViewList(modifier _: _GraphValue, inputs _: _ViewListInputs, body _: @escaping (_Graph, _ViewListInputs) -> _ViewListOutputs) -> _ViewListOutputs { - .init() + fatalError("TODO") } } @@ -25,6 +25,6 @@ extension ViewModifier where Self: Animatable { } public static func _makeViewList(modifier _: _GraphValue, inputs _: _ViewListInputs, body _: @escaping (_Graph, _ViewListInputs) -> _ViewListOutputs) -> _ViewListOutputs { - .init() + fatalError("TODO") } } diff --git a/Sources/OpenSwiftUI/View/Animation/TODO/_AnimatableView.swift b/Sources/OpenSwiftUI/View/Animation/TODO/_AnimatableView.swift index 58e3a792..ac227e04 100644 --- a/Sources/OpenSwiftUI/View/Animation/TODO/_AnimatableView.swift +++ b/Sources/OpenSwiftUI/View/Animation/TODO/_AnimatableView.swift @@ -15,7 +15,7 @@ extension _AnimatableView { } public static func _makeViewList(view _: _GraphValue, inputs _: _ViewListInputs) -> _ViewListOutputs { - .init() + fatalError("TODO") } } @@ -25,6 +25,6 @@ extension View where Self: Animatable { } public static func _makeViewList(view _: _GraphValue, inputs _: _ViewListInputs) -> _ViewListOutputs { - .init() + fatalError("TODO") } } diff --git a/Sources/OpenSwiftUI/View/View/AnyView.swift b/Sources/OpenSwiftUI/View/View/AnyView.swift index 629f151d..2806f8c4 100644 --- a/Sources/OpenSwiftUI/View/View/AnyView.swift +++ b/Sources/OpenSwiftUI/View/View/AnyView.swift @@ -74,8 +74,7 @@ public struct AnyView: PrimitiveView { } public static func _makeViewList(view: _GraphValue, inputs: _ViewListInputs) -> _ViewListOutputs { - // TODO - .init() + fatalError("TODO") } } diff --git a/Sources/OpenSwiftUI/View/View/EmptyView.swift b/Sources/OpenSwiftUI/View/View/EmptyView.swift index 51c91fc5..c76344c7 100644 --- a/Sources/OpenSwiftUI/View/View/EmptyView.swift +++ b/Sources/OpenSwiftUI/View/View/EmptyView.swift @@ -13,7 +13,7 @@ public struct EmptyView: PrimitiveView { } public static func _makeViewList(view: _GraphValue, inputs: _ViewListInputs) -> _ViewListOutputs { - .init() // FIXME + fatalError("TODO") } public static func _viewListCount(inputs: _ViewListCountInputs) -> Int? {