Skip to content

Commit 1aaa7bf

Browse files
authored
Add NamedImage API support (#806)
1 parent 33a74eb commit 1aaa7bf

File tree

18 files changed

+2528
-23
lines changed

18 files changed

+2528
-23
lines changed

Package.resolved

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Sources/OpenSwiftUICore/Data/EnvironmentKeys/EnvironmentAdditions.swift

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -59,21 +59,13 @@ extension Image {
5959
/// A scale that produces large images.
6060
case large
6161

62-
@_spi(ForOpenSwiftUIOnly)
63-
@available(OpenSwiftUI_v6_0, *)
64-
case _fittingCircleRadius(_fixedPointFraction: UInt16)
65-
6662
@_spi(Private)
6763
@available(OpenSwiftUI_v6_0, *)
68-
@available(*, deprecated, renamed: "_controlCenter_large")
69-
@_alwaysEmitIntoClient
70-
public static func fittingCircleRadius(pointSizeMultiple: CGFloat) -> Image.Scale {
71-
._controlCenter_large
72-
}
64+
case _controlCenter_small, _controlCenter_medium, _controlCenter_large
7365

7466
@_spi(Private)
7567
@available(OpenSwiftUI_v6_0, *)
76-
case _controlCenter_small, _controlCenter_medium, _controlCenter_large
68+
case _watch_toolbar_medium
7769
}
7870
}
7971

Sources/OpenSwiftUICore/Data/Protobuf/ProtobufEncoder.swift

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -382,6 +382,20 @@ extension ProtobufEncoder {
382382
try encodeMessage(value)
383383
}
384384

385+
/// Encodes an attached value with a hashable key and a data-producing closure.
386+
///
387+
/// When an `ArchiveWriter` is available, the data is deduplicated using
388+
/// a SHA1 hash and stored as an attachment reference. Otherwise, the data
389+
/// is encoded inline at field 2.
390+
///
391+
/// - Parameters:
392+
/// - key: A hashable key used for attachment deduplication.
393+
/// - data: A closure that produces the data to encode.
394+
package mutating func encodeAttachedValue<Key: Hashable>(key: Key, data: () throws -> Data) throws {
395+
// TODO: ArchiveWriter support for attachment deduplication
396+
try dataField(2, data())
397+
}
398+
385399
/// Encodes a string field.
386400
///
387401
/// - Parameters:

Sources/OpenSwiftUICore/Graphic/Color/NamedColor.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ extension Color {
9090
return nil
9191
}
9292
let gamut = key.displayGamut.cuiDisplayGamut
93-
let idiom = CUIDeviceIdiom(rawValue: environment.cuiAssetIdiom) ?? .universal
93+
let idiom = CUIDeviceIdiom(rawValue: environment.cuiAssetIdiom)!
9494
let color = catalog.findAsset(
9595
key: key.catalogKey,
9696
matchTypes: environment.cuiAssetMatchTypes,
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
//
2+
// SFSymbolsShims.swift
3+
// OpenSwiftUICore
4+
//
5+
// Status: WIP
6+
7+
// MARK: - SFSymbols Framework Access
8+
//
9+
// Currently uses dlopen/dlsym for dynamic symbol resolution at
10+
// runtime. This avoids a hard link dependency on the private SFSymbols
11+
// framework.
12+
//
13+
// TODO: Migrate to add SFSymbols in DarwinPrivateFrameworks package and link it with a new
14+
// OPENSWIFTUI_LINK_SFSYMBOLS build flag (following the CoreUI pattern).
15+
// When that migration happens:
16+
// 1. Add `import SFSymbols` under `#if OPENSWIFTUI_LINK_SFSYMBOLS`.
17+
// 2. Replace the dlopen-based implementations with direct calls.
18+
// 3. Call sites using `SFSymbols.symbol_order` etc. remain unchanged
19+
// because Swift resolves `SFSymbols.x` identically whether `SFSymbols`
20+
// is a local enum or a qualified module name.
21+
22+
#if canImport(Darwin)
23+
import Foundation
24+
25+
/// Shim for the private SFSymbols framework.
26+
///
27+
/// Property names intentionally use snake_case to match the framework's
28+
/// original API surface, ensuring a seamless migration to direct linking
29+
/// (Option C) with no source-breaking changes at call sites.
30+
package enum SFSymbols {
31+
// MARK: - Module-level Properties
32+
33+
/// All system symbol names in their canonical order.
34+
package static var symbol_order: [String] {
35+
_lookup("$s9SFSymbols12symbol_orderSaySSGvg", as: Getter_ArrayString.self)?() ?? []
36+
}
37+
38+
/// Private system symbol names in their canonical order.
39+
package static var private_symbol_order: [String] {
40+
_lookup("$s9SFSymbols20private_symbol_orderSaySSGvg", as: Getter_ArrayString.self)?() ?? []
41+
}
42+
43+
/// Mapping of alias names to their canonical symbol names.
44+
package static var name_aliases: [String: String] {
45+
_lookup("$s9SFSymbols12name_aliasesSDyS2SGvg", as: Getter_DictStringString.self)?() ?? [:]
46+
}
47+
48+
/// Mapping of private alias names to their canonical symbol names.
49+
package static var private_name_aliases: [String: String] {
50+
_lookup("$s9SFSymbols20private_name_aliasesSDyS2SGvg", as: Getter_DictStringString.self)?() ?? [:]
51+
}
52+
53+
/// Mapping from nofill symbol names to their fill variants.
54+
package static var nofill_to_fill: [String: String] {
55+
_lookup("$s9SFSymbols14nofill_to_fillSDyS2SGvg", as: Getter_DictStringString.self)?() ?? [:]
56+
}
57+
58+
/// Mapping from private nofill symbol names to their fill variants.
59+
package static var private_nofill_to_fill: [String: String] {
60+
_lookup("$s9SFSymbols22private_nofill_to_fillSDyS2SGvg", as: Getter_DictStringString.self)?() ?? [:]
61+
}
62+
63+
// MARK: - Private
64+
65+
private typealias Getter_ArrayString = @convention(thin) () -> [String]
66+
private typealias Getter_DictStringString = @convention(thin) () -> [String: String]
67+
68+
private static let handle: UnsafeMutableRawPointer? = {
69+
dlopen("/System/Library/PrivateFrameworks/SFSymbols.framework/SFSymbols", RTLD_LAZY)
70+
}()
71+
72+
private static func _lookup<T>(_ name: String, as type: T.Type) -> T? {
73+
guard let handle, let sym = dlsym(handle, name) else { return nil }
74+
return unsafeBitCast(sym, to: type)
75+
}
76+
}
77+
#endif
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
//
2+
// ArchivedView.swift
3+
// OpenSwiftUICore
4+
//
5+
// Audited for 6.5.4
6+
// Status: Complete
7+
8+
public import Foundation
9+
10+
// MARK: - ArchivedViewDelegate
11+
12+
@_spi(Private)
13+
@available(OpenSwiftUI_v4_0, *)
14+
public protocol ArchivedViewDelegate {
15+
mutating func resolveImage(uuid: UUID) throws -> Image.ResolvedUUID
16+
}
17+
18+
// MARK: - AnyArchivedViewDelegate
19+
20+
@_spi(ForOpenSwiftUIOnly)
21+
@available(OpenSwiftUI_v6_0, *)
22+
open class AnyArchivedViewDelegate {
23+
package init() {
24+
_openSwiftUIEmptyStub()
25+
}
26+
27+
@_spi(ForSwiftUIOnly)
28+
open func resolveImage(uuid: UUID) throws -> Image.ResolvedUUID {
29+
_openSwiftUIBaseClassAbstractMethod()
30+
}
31+
}
32+
33+
@_spi(ForOpenSwiftUIOnly)
34+
@available(*, unavailable)
35+
extension AnyArchivedViewDelegate: @unchecked Sendable {}

Sources/OpenSwiftUICore/View/Image/GraphicsImage.swift

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ package import OpenCoreGraphicsShims
1111
import CoreGraphics_Private
1212
#endif
1313

14+
#if OPENSWIFTUI_LINK_COREUI
15+
package import CoreUI
16+
#endif
17+
1418
// MARK: - GraphicsImage
1519

1620
package struct GraphicsImage: Equatable, Sendable {
@@ -165,6 +169,20 @@ package struct ResolvedVectorGlyph: Equatable {
165169
package var animatorVersion: UInt32
166170
package var allowsContentTransitions: Bool
167171
package var preservesVectorRepresentation: Bool
172+
#if OPENSWIFTUI_LINK_COREUI
173+
package let catalog: CUICatalog
174+
#endif
175+
176+
package init(
177+
glyph: CUINamedVectorGlyph,
178+
value: Float?,
179+
flipsRightToLeft: Bool,
180+
in context: ImageResolutionContext,
181+
at location: Image.Location,
182+
catalog: CUICatalog
183+
) {
184+
_openSwiftUIUnimplementedFailure()
185+
}
168186

169187
package var flipsRightToLeft: Bool {
170188
animator.flipsRightToLeft

Sources/OpenSwiftUICore/View/Image/Image.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,8 @@ package struct ImageResolutionContext {
128128
self.transaction = transaction
129129
}
130130

131+
// TODO: willUpdateVectorGlyph
132+
131133
package func effectiveAllowedDynamicRange(for image: GraphicsImage) -> Image.DynamicRange? {
132134
#if canImport(CoreGraphics)
133135
guard allowedDynamicRange != .none else {

0 commit comments

Comments
 (0)