Skip to content

Commit e26992d

Browse files
committed
Add ArchivedViewInput
1 parent bf18512 commit e26992d

File tree

1 file changed

+148
-0
lines changed

1 file changed

+148
-0
lines changed
Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
//
2+
// ArchivedViewInput.swift
3+
// OpenSwiftUICore
4+
//
5+
// Status: Complete
6+
7+
// MARK: - ArchivedViewInput [6.0.87]
8+
9+
/// A view input that manages archived view state and configuration.
10+
///
11+
/// `ArchivedViewInput` provides a way to store and retrieve view archival information,
12+
/// including feature flags and deployment version compatibility. This is used internally
13+
/// by OpenSwiftUI to maintain compatibility across different versions and to enable
14+
/// optimizations for archived view hierarchies.
15+
package struct ArchivedViewInput: ViewInput {
16+
/// Option flags that control archived view behavior.
17+
///
18+
/// These flags determine various aspects of how archived views are processed,
19+
/// including stability guarantees, font handling, and layout precision.
20+
package struct Flags: OptionSet {
21+
package let rawValue: UInt8
22+
23+
package init(rawValue: UInt8) {
24+
self.rawValue = rawValue
25+
}
26+
27+
/// Indicates that the view hierarchy is archived.
28+
package static let isArchived: ArchivedViewInput.Flags = .init(rawValue: 1 << 0)
29+
30+
/// Enables stable identifier tracking for archived views.
31+
package static let stableIDs: ArchivedViewInput.Flags = .init(rawValue: 1 << 1)
32+
33+
/// Enables custom font URL preservation in archived views.
34+
package static let customFontURLs: ArchivedViewInput.Flags = .init(rawValue: 1 << 2)
35+
36+
/// Enables asset catalog reference preservation in archived views.
37+
package static let assetCatalogRefences: ArchivedViewInput.Flags = .init(rawValue: 1 << 3)
38+
39+
/// Enables precise text layout calculations for archived views.
40+
package static let preciseTextLayout: ArchivedViewInput.Flags = .init(rawValue: 1 << 4)
41+
}
42+
43+
/// The value type that encapsulates archived view configuration.
44+
///
45+
/// This type combines feature flags with deployment version information
46+
/// to provide complete archived view context.
47+
package struct Value: Equatable {
48+
/// The active feature flags for this archived view.
49+
package var flags: ArchivedViewInput.Flags
50+
51+
/// The deployment version this archived view was created with.
52+
package var deploymentVersion: ArchivedViewInput.DeploymentVersion
53+
54+
/// Creates a new archived view value.
55+
///
56+
/// - Parameters:
57+
/// - flags: The feature flags to apply. Defaults to no flags.
58+
/// - deploymentVersion: The deployment version. Defaults to current.
59+
package init(
60+
flags: ArchivedViewInput.Flags = .init(),
61+
deploymentVersion: ArchivedViewInput.DeploymentVersion = .current
62+
) {
63+
self.flags = flags
64+
self.deploymentVersion = deploymentVersion
65+
}
66+
67+
/// A pre-configured value indicating an archived view.
68+
package static let isArchived: ArchivedViewInput.Value = .init(flags: .isArchived)
69+
70+
/// Whether this view hierarchy is archived.
71+
package var isArchived: Bool {
72+
flags.contains(.isArchived)
73+
}
74+
75+
/// Whether stable identifier tracking is enabled.
76+
package var stableIDs: Bool {
77+
flags.contains(.stableIDs)
78+
}
79+
80+
/// Whether custom font URL preservation is enabled.
81+
package var customFontURLs: Bool {
82+
flags.contains(.customFontURLs)
83+
}
84+
85+
/// Whether asset catalog reference preservation is enabled.
86+
package var assetCatalogRefences: Bool {
87+
flags.contains(.assetCatalogRefences)
88+
}
89+
90+
/// Whether precise text layout is enabled.
91+
package var preciseTextLayout: Bool {
92+
flags.contains(.preciseTextLayout)
93+
}
94+
}
95+
96+
/// Represents a deployment version for archived view compatibility.
97+
///
98+
/// Deployment versions track OpenSwiftUI version compatibility to ensure
99+
/// archived views can be properly decoded and displayed across different
100+
/// runtime versions.
101+
package struct DeploymentVersion: Hashable, Comparable, Codable, Sendable {
102+
/// The raw version value.
103+
package let rawValue: Int8
104+
105+
/// Creates a deployment version with the specified raw value.
106+
///
107+
/// - Parameter rawValue: The version identifier.
108+
package init(rawValue: Int8) {
109+
self.rawValue = rawValue
110+
}
111+
112+
/// OpenSwiftUI version 5 deployment target.
113+
package static let v5: ArchivedViewInput.DeploymentVersion = .init(rawValue: 1)
114+
115+
/// OpenSwiftUI version 6 deployment target.
116+
package static let v6: ArchivedViewInput.DeploymentVersion = .init(rawValue: 2)
117+
118+
/// The current deployment version for archived views.
119+
@_alwaysEmitIntoClient
120+
package static var current: ArchivedViewInput.DeploymentVersion { .v6 }
121+
122+
package static func < (
123+
lhs: ArchivedViewInput.DeploymentVersion,
124+
rhs: ArchivedViewInput.DeploymentVersion
125+
) -> Bool {
126+
lhs.rawValue < rhs.rawValue
127+
}
128+
129+
/// The oldest supported deployment version.
130+
package static let oldest: ArchivedViewInput.DeploymentVersion = .v5
131+
}
132+
133+
/// The default value for archived view input.
134+
package static let defaultValue: ArchivedViewInput.Value = .init()
135+
}
136+
137+
extension ArchivedViewInput.DeploymentVersion {
138+
package func encode(to encoder: any Encoder) throws {
139+
var container = encoder.singleValueContainer()
140+
try container.encode(rawValue)
141+
}
142+
143+
package init(from decoder: any Decoder) throws {
144+
let container = try decoder.singleValueContainer()
145+
let rawValue = try container.decode(Int8.self)
146+
self.init(rawValue: rawValue)
147+
}
148+
}

0 commit comments

Comments
 (0)