Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 23 additions & 12 deletions Sources/OpenSwiftUICore/View/Image/NamedImage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ package enum NamedImage {
self.idiom = idiom
}

#if OPENSWIFTUI_LINK_COREUI
fileprivate func loadVectorInfo(from catalog: CUICatalog, idiom: Int) -> VectorInfo? {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With #if OPENSWIFTUI_LINK_COREUI moved inside the body, this file still references CoreUI types (e.g., CUICatalog, CUINamedVectorGlyph) in signatures/fields (loadVectorInfo, VectorInfo, cache subscripts), so non-CoreUI builds may still need those symbols available. Can you confirm this won’t break configurations where CoreUI isn’t importable/linkable?

Severity: medium

Fix This in Augment

🤖 Was this useful? React with 👍 or 👎, or 🚀 if it prevented an incident/outage.

#if OPENSWIFTUI_LINK_COREUI
let matchType: CatalogAssetMatchType = .cuiIdiom(idiom)
let glyph: CUINamedVectorGlyph? = catalog.findAsset(
key: catalogKey,
Expand Down Expand Up @@ -136,6 +136,9 @@ package enum NamedImage {
layoutMetrics: metrics,
catalog: catalog
)
#else
_openSwiftUIPlatformUnimplementedFailure()
#endif
}

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

_openSwiftUIPlatformUnimplementedFailure() is the only statement in the #else branch of a non-Void function; this relies on it being -> Never for compilation/correctness when OPENSWIFTUI_LINK_COREUI is off (also applies to similar branches like symbolSizeScale).

Severity: medium

Fix This in Augment

🤖 Was this useful? React with 👍 or 👎, or 🚀 if it prevented an incident/outage.

/// Computes a scale factor for symbol images based on the glyph's
Expand All @@ -148,6 +151,7 @@ package enum NamedImage {
/// 4. Computes a reference circle.fill diameter for the current weight/pointSize
/// 5. Returns the ratio clamped to the allowed range
private func symbolSizeScale(for glyph: CUINamedVectorGlyph) -> CGFloat {
#if OPENSWIFTUI_LINK_COREUI
let range = imageScale.allowedScaleRange
guard range.lowerBound < range.upperBound else {
return range.lowerBound
Expand Down Expand Up @@ -213,23 +217,22 @@ package enum NamedImage {

let ratio = referenceRadius / actualRadius
return min(range.upperBound, max(range.lowerBound, ratio))
#else
_openSwiftUIPlatformUnimplementedFailure()
#endif
}
#endif
}


// MARK: - VectorInfo

fileprivate struct VectorInfo {
#if OPENSWIFTUI_LINK_COREUI
var glyph: CUINamedVectorGlyph

var flipsRightToLeft: Bool

var layoutMetrics: Image.LayoutMetrics

weak var catalog: CUICatalog?
#endif
}


Expand Down Expand Up @@ -315,8 +318,8 @@ package enum NamedImage {
}
}

#if OPENSWIFTUI_LINK_COREUI
func loadBitmapInfo(location: Image.Location, idiom: Int, subtype: Int) -> BitmapInfo? {
#if OPENSWIFTUI_LINK_COREUI
// Resolve catalog from location
guard case .bundle(let bundle) = location,
let (catalog, _) = NamedImage.sharedCache[bundle] else {
Expand Down Expand Up @@ -425,8 +428,11 @@ package enum NamedImage {
renderingMode: renderingMode,
resizingInfo: resizingInfo
)
#else
_openSwiftUIPlatformUnimplementedWarning()
return nil
#endif
}
#endif
}

// MARK: - NamedImage.BitmapInfo
Expand Down Expand Up @@ -514,10 +520,10 @@ package enum NamedImage {

// MARK: Cache subscripts

#if OPENSWIFTUI_LINK_COREUI
// Looks up cached VectorInfo for key; if not found or catalog changed,
// calls loadVectorInfo and caches the result.
fileprivate subscript(key: VectorKey, catalog: CUICatalog) -> VectorInfo? {
#if OPENSWIFTUI_LINK_COREUI
let cached = data.vectors[key]
if let cached {
if let cachedCatalog = cached.catalog, cachedCatalog == catalog {
Expand All @@ -529,8 +535,11 @@ package enum NamedImage {
}
data.vectors[key] = info
return info
#else
_openSwiftUIPlatformUnimplementedWarning()
return nil
#endif
}
#endif

// Looks up cached BitmapInfo for key; if not found,
// calls loadBitmapInfo and caches the result.
Expand All @@ -550,10 +559,10 @@ package enum NamedImage {
#endif
}

#if OPENSWIFTUI_LINK_COREUI
// Resolves a CUICatalog for the given bundle.
// First tries defaultUICatalog; falls back to Assets.car with weak caching.
package subscript(bundle: Bundle) -> (CUICatalog, retain: Bool)? {
#if OPENSWIFTUI_LINK_COREUI
if let catalog = CUICatalog.defaultUICatalog(for: bundle) {
return (catalog, retain: false)
}
Expand All @@ -570,10 +579,12 @@ package enum NamedImage {
}
data.catalogs[url] = WeakCatalog(catalog: catalog)
return (catalog, retain: true)
#else
_openSwiftUIPlatformUnimplementedWarning()
return nil
#endif
}

#endif

package func decode(_ key: Key) throws -> DecodedInfo {
switch key {
case .bitmap(let bitmapKey):
Expand Down
Loading