Skip to content

Commit 25c4cdf

Browse files
committed
Add UIKitEnvironmentTests
1 parent fa9a2a7 commit 25c4cdf

File tree

3 files changed

+85
-14
lines changed

3 files changed

+85
-14
lines changed

Sources/OpenSwiftUI/Event/Focus/FocusedValueKey.swift

Lines changed: 63 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,45 +2,98 @@
22
// FocusedValueKey.swift
33
// OpenSwiftUI
44
//
5-
// Audited for iOS 15.5
6-
// Status: Complete
5+
// Audited for 6.5.4
6+
// Status: WIP
77

88
import OpenSwiftUICore
99

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+
1052
/// A protocol for identifier types used when publishing and observing focused
1153
/// values.
1254
///
1355
/// Unlike ``EnvironmentKey``, `FocusedValueKey` has no default value
1456
/// requirement, because the default value for a key is always `nil`.
57+
@available(OpenSwiftUI_v2_0, *)
1558
public protocol FocusedValueKey {
1659
associatedtype Value
1760
}
1861

62+
/// A collection of state exported by the focused view and its ancestors.
63+
@available(OpenSwiftUI_v2_0, *)
1964
public struct FocusedValues {
20-
struct StorageOptions {
65+
var plist: PropertyList
66+
67+
struct StorageOptions: OptionSet {
2168
let rawValue: UInt8
2269
}
23-
24-
var plist: PropertyList
25-
var storageOptions: StorageOptions
70+
71+
var storageOptions: FocusedValues.StorageOptions
72+
73+
var navigationDepth: Int
74+
2675
var seed: VersionSeed
27-
76+
2877
@usableFromInline
2978
internal init() {
3079
plist = PropertyList()
31-
storageOptions = StorageOptions(rawValue: 0)
80+
storageOptions = []
81+
navigationDepth = -1
3282
seed = .empty
3383
}
34-
84+
3585
/// Reads and writes values associated with a given focused value key.
86+
3687
public subscript<Key>(key: Key.Type) -> Key.Value? where Key: FocusedValueKey {
37-
_openSwiftUIUnimplementedFailure()
88+
get { _openSwiftUIUnimplementedFailure() }
89+
set { _openSwiftUIUnimplementedFailure() }
3890
}
3991
}
4092

4193
@available(*, unavailable)
4294
extension FocusedValues: Sendable {}
4395

96+
@available(OpenSwiftUI_v3_0, *)
4497
extension FocusedValues: Equatable {
4598
public static func == (lhs: FocusedValues, rhs: FocusedValues) -> Bool {
4699
lhs.seed.matches(rhs.seed)

Tests/OpenSwiftUITests/Data/Environment/EnvironmentValuesOpenURLTests.swift

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
//
22
// EnvironmentValuesOpenURLTests.swift
3-
//
4-
//
5-
// Created by Kyle on 2023/11/28.
6-
//
3+
// OpenSwiftUITests
74

85
import Foundation
96
@testable import OpenSwiftUI
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
//
2+
// UIKitEnvironmentTests.swift
3+
// OpenSwiftUITests
4+
5+
#if os(iOS)
6+
@testable import OpenSwiftUI
7+
import Testing
8+
import UIKit
9+
10+
struct UIKitEnvironmentTests {
11+
@Test
12+
func overrideTrait() {
13+
let trait = UITraitCollection.current
14+
#expect(trait.layoutDirection == .unspecified)
15+
var environment = EnvironmentValues()
16+
environment.layoutDirection = .rightToLeft
17+
let newTrait = trait.byOverriding(with: environment, viewPhase: .init(), focusedValues: .init())
18+
#expect(newTrait.layoutDirection == .rightToLeft)
19+
}
20+
}
21+
#endif

0 commit comments

Comments
 (0)