|
2 | 2 | // FocusedValueKey.swift |
3 | 3 | // OpenSwiftUI |
4 | 4 | // |
5 | | -// Audited for iOS 15.5 |
6 | | -// Status: Complete |
| 5 | +// Audited for 6.5.4 |
| 6 | +// Status: WIP |
7 | 7 |
|
8 | 8 | import OpenSwiftUICore |
9 | 9 |
|
| 10 | +@available(OpenSwiftUI_v2_0, *) |
| 11 | +@propertyWrapper |
| 12 | +public struct FocusedValue<Value>: DynamicProperty { |
| 13 | + @usableFromInline |
| 14 | + @frozen |
| 15 | + internal enum Content { |
| 16 | + case keyPath(KeyPath<FocusedValues, Value?>) |
| 17 | + case value(Value?) |
| 18 | + } |
| 19 | + |
| 20 | + @usableFromInline |
| 21 | + internal var content: FocusedValue<Value>.Content |
| 22 | + |
| 23 | + public init(_ keyPath: KeyPath<FocusedValues, Value?>) { |
| 24 | + _openSwiftUIUnimplementedFailure() |
| 25 | + } |
| 26 | + |
| 27 | + @inlinable |
| 28 | + public var wrappedValue: Value? { |
| 29 | + if case .value(let value) = content { |
| 30 | + return value |
| 31 | + } else { |
| 32 | + return nil |
| 33 | + } |
| 34 | + } |
| 35 | + |
| 36 | + public static func _makeProperty<V>( |
| 37 | + in buffer: inout _DynamicPropertyBuffer, |
| 38 | + container: _GraphValue<V>, |
| 39 | + fieldOffset: Int, |
| 40 | + inputs: inout _GraphInputs |
| 41 | + ) { |
| 42 | + _openSwiftUIUnimplementedFailure() |
| 43 | + } |
| 44 | +} |
| 45 | + |
| 46 | +@available(*, unavailable) |
| 47 | +extension FocusedValue: Sendable {} |
| 48 | + |
| 49 | +@available(*, unavailable) |
| 50 | +extension FocusedValue.Content: Sendable {} |
| 51 | + |
10 | 52 | /// A protocol for identifier types used when publishing and observing focused |
11 | 53 | /// values. |
12 | 54 | /// |
13 | 55 | /// Unlike ``EnvironmentKey``, `FocusedValueKey` has no default value |
14 | 56 | /// requirement, because the default value for a key is always `nil`. |
| 57 | +@available(OpenSwiftUI_v2_0, *) |
15 | 58 | public protocol FocusedValueKey { |
16 | 59 | associatedtype Value |
17 | 60 | } |
18 | 61 |
|
| 62 | +/// A collection of state exported by the focused view and its ancestors. |
| 63 | +@available(OpenSwiftUI_v2_0, *) |
19 | 64 | public struct FocusedValues { |
20 | | - struct StorageOptions { |
| 65 | + var plist: PropertyList |
| 66 | + |
| 67 | + struct StorageOptions: OptionSet { |
21 | 68 | let rawValue: UInt8 |
22 | 69 | } |
23 | | - |
24 | | - var plist: PropertyList |
25 | | - var storageOptions: StorageOptions |
| 70 | + |
| 71 | + var storageOptions: FocusedValues.StorageOptions |
| 72 | + |
| 73 | + var navigationDepth: Int |
| 74 | + |
26 | 75 | var seed: VersionSeed |
27 | | - |
| 76 | + |
28 | 77 | @usableFromInline |
29 | 78 | internal init() { |
30 | 79 | plist = PropertyList() |
31 | | - storageOptions = StorageOptions(rawValue: 0) |
| 80 | + storageOptions = [] |
| 81 | + navigationDepth = -1 |
32 | 82 | seed = .empty |
33 | 83 | } |
34 | | - |
| 84 | + |
35 | 85 | /// Reads and writes values associated with a given focused value key. |
| 86 | + |
36 | 87 | public subscript<Key>(key: Key.Type) -> Key.Value? where Key: FocusedValueKey { |
37 | | - _openSwiftUIUnimplementedFailure() |
| 88 | + get { _openSwiftUIUnimplementedFailure() } |
| 89 | + set { _openSwiftUIUnimplementedFailure() } |
38 | 90 | } |
39 | 91 | } |
40 | 92 |
|
41 | 93 | @available(*, unavailable) |
42 | 94 | extension FocusedValues: Sendable {} |
43 | 95 |
|
| 96 | +@available(OpenSwiftUI_v3_0, *) |
44 | 97 | extension FocusedValues: Equatable { |
45 | 98 | public static func == (lhs: FocusedValues, rhs: FocusedValues) -> Bool { |
46 | 99 | lhs.seed.matches(rhs.seed) |
|
0 commit comments