mirror of
https://github.com/SideStore/SideStore.git
synced 2026-05-11 20:05:40 +02:00
fix(widget): blank app icons
Signed-off-by: Mod4 <omarelfarok24135@gmail.com> Co-authored-by: mahee96 <47920326+mahee96@users.noreply.github.com>
This commit is contained in:
@@ -7,6 +7,7 @@
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
import WidgetKit
|
||||
|
||||
extension View
|
||||
{
|
||||
@@ -78,4 +79,59 @@ extension View
|
||||
}
|
||||
}
|
||||
|
||||
/// Opts this view into the widget accent group on iOS 16+, which lets the
|
||||
/// system tint it with the user's chosen colour in tinted (accented) mode.
|
||||
/// No-op on older OS versions where the API does not exist.
|
||||
@ViewBuilder
|
||||
func widgetAccentableIfAvailable() -> some View
|
||||
{
|
||||
if #available(iOSApplicationExtension 16, *)
|
||||
{
|
||||
self.widgetAccentable()
|
||||
}
|
||||
else
|
||||
{
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
/// Applies `luminanceToAlpha()` only when the widget is rendering in
|
||||
/// accented (tinted) mode on iOS 16+. This converts the view's pixel
|
||||
/// brightness into opacity so the system can overlay the user's chosen
|
||||
/// tint colour correctly — without it, images appear as white rectangles
|
||||
/// in tinted mode. No-op in fullColor/dark/light mode and on older OS.
|
||||
@ViewBuilder
|
||||
func luminanceToAlphaInAccentedMode() -> some View
|
||||
{
|
||||
if #available(iOSApplicationExtension 16, *)
|
||||
{
|
||||
LuminanceToAlphaWrapper(content: self)
|
||||
}
|
||||
else
|
||||
{
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/// Helper view that reads widgetRenderingMode (iOS 16+) and conditionally
|
||||
/// applies luminanceToAlpha(). Kept separate so the environment read is
|
||||
/// cleanly scoped behind the @available gate.
|
||||
@available(iOSApplicationExtension 16, *)
|
||||
private struct LuminanceToAlphaWrapper<Content: View>: View
|
||||
{
|
||||
let content: Content
|
||||
@Environment(\.widgetRenderingMode) private var renderingMode
|
||||
|
||||
var body: some View {
|
||||
if renderingMode == .accented
|
||||
{
|
||||
content.luminanceToAlpha()
|
||||
}
|
||||
else
|
||||
{
|
||||
content
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user