-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add ViewTraitCollection implementation * Add _ViewListOutputs related interface
- Loading branch information
Showing
20 changed files
with
278 additions
and
16 deletions.
There are no files selected for viewing
5 changes: 0 additions & 5 deletions
5
Sources/OpenSwiftUI/Core/View/TODO/_ViewListCountInputs.swift
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
File renamed without changes.
File renamed without changes.
7 changes: 7 additions & 0 deletions
7
...es/OpenSwiftUI/Core/View/ViewInputs.swift → ...enSwiftUI/Core/View/View/ViewInputs.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
32 changes: 32 additions & 0 deletions
32
Sources/OpenSwiftUI/Core/View/ViewList/ViewListCountInputs.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<Input: GraphInput>(_ type: Input.Type) -> Input.Value { | ||
get { customInputs[type] } | ||
set { customInputs[type] = newValue } | ||
} | ||
|
||
mutating func popLast<Input: GraphInput, Value>(_ 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<Input: GraphInput, Value>(_ value: Value, to type: Input.Type) where Input.Value == [Value] { | ||
var values = self[type] | ||
values.append(value) | ||
self[type] = values | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
Sources/OpenSwiftUI/Core/View/ViewList/ViewListInputs.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
Sources/OpenSwiftUI/Core/View/ViewList/ViewListOutputs.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<ViewList>, ListModifier?) | ||
} | ||
|
||
class ListModifier { | ||
init() {} | ||
|
||
func apply(to: inout ViewList) { | ||
// TODO | ||
} | ||
} | ||
} | ||
|
||
// TODO | ||
protocol ViewList { | ||
} |
18 changes: 18 additions & 0 deletions
18
Sources/OpenSwiftUI/Core/View/ViewList/ViewList_Elements.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} |
23 changes: 23 additions & 0 deletions
23
Sources/OpenSwiftUI/Core/View/ViewList/ViewList_IndirectMap.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} | ||
} |
47 changes: 47 additions & 0 deletions
47
Sources/OpenSwiftUI/Core/View/ViewList/ViewList_Subgraph.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() | ||
} | ||
} |
63 changes: 63 additions & 0 deletions
63
Sources/OpenSwiftUI/Core/View/ViewTrait/ViewTraitCollection.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<Key: _ViewTraitKey>: AnyViewTrait { | ||
var value: Key.Value | ||
|
||
init(value: Key.Value) { | ||
self.value = value | ||
} | ||
|
||
var id: ObjectIdentifier { ObjectIdentifier(Key.self) } | ||
|
||
subscript<V>() -> V { | ||
get { value as! V } | ||
set { value = newValue as! Key.Value } | ||
} | ||
} | ||
|
||
subscript<Key: _ViewTraitKey>(_: 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<Key>(value: newValue)) | ||
} | ||
} | ||
} | ||
|
||
func value<Key: _ViewTraitKey>(for _: Key.Type, defaultValue: Key.Value = Key.defaultValue) -> Key.Value { | ||
storage.first { $0.id == ObjectIdentifier(Key.self) }?[] ?? defaultValue | ||
} | ||
|
||
mutating func setValueIfUnset<Key: _ViewTraitKey>(_ value: Key.Value, for _: Key.Type) { | ||
guard !storage.contains(where: { $0.id == ObjectIdentifier(Key.self) }) else { | ||
return | ||
} | ||
storage.append(AnyTrait<Key>(value: value)) | ||
} | ||
|
||
// func insertInteraction(for: OnInsertInteraction.Strategy) -> OnInsertInteraction? { | ||
// fatalError("TODO") | ||
// } | ||
// | ||
// var optionalTransition: AnyTransition? { | ||
// fatalError("TODO") | ||
// } | ||
} | ||
|
||
private protocol AnyViewTrait { | ||
var id: ObjectIdentifier { get } | ||
subscript<V>() -> V { get set } | ||
} |
11 changes: 11 additions & 0 deletions
11
Sources/OpenSwiftUI/Core/View/ViewTrait/ViewTraitKey.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
// | ||
// ViewTraitKey.swift | ||
// OpenSwiftUI | ||
// | ||
// Audited for RELEASE_2021 | ||
// Status: Complete | ||
|
||
protocol _ViewTraitKey { | ||
associatedtype Value | ||
static var defaultValue: Value { get } | ||
} |
19 changes: 19 additions & 0 deletions
19
Sources/OpenSwiftUI/Core/View/ViewTrait/ViewTraitKeys.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// | ||
// ViewTraitKeys.swift | ||
// OpenSwiftUI | ||
// | ||
// Audited for RELEASE_2021 | ||
// Status: Complete | ||
|
||
struct ViewTraitKeys { | ||
var types: Set<ObjectIdentifier> | ||
var isDataDependent: Bool | ||
|
||
mutating func insert<Key: _ViewTraitKey>(_ type: Key.Type) { | ||
types.insert(ObjectIdentifier(type)) | ||
} | ||
|
||
func contains<Key: _ViewTraitKey>(_ type: Key.Type) -> Bool { | ||
types.contains(ObjectIdentifier(type)) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters