mirror of
https://github.com/SideStore/SideStore.git
synced 2026-02-09 06:43:25 +01:00
[Widgets]: Fix for AppDetailWidget previews crashing
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
{
|
{
|
||||||
"images" : [
|
"images" : [
|
||||||
{
|
{
|
||||||
|
"filename" : "1024.png",
|
||||||
"idiom" : "universal",
|
"idiom" : "universal",
|
||||||
"scale" : "1x"
|
"scale" : "1x"
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -88,11 +88,25 @@ private struct ActiveAppsWidgetView: View
|
|||||||
VStack(spacing: 12) {
|
VStack(spacing: 12) {
|
||||||
ForEach(entry.apps, id: \.bundleIdentifier) { app in
|
ForEach(entry.apps, id: \.bundleIdentifier) { app in
|
||||||
|
|
||||||
|
let icon = app.icon ?? UIImage(named: "SideStore")!
|
||||||
|
|
||||||
|
// 1024x1024 images are not supported by previews but supported by device
|
||||||
|
// so we scale the image to 97% so as to reduce its actual size but not too much
|
||||||
|
// to somewhere below value, acceptable by previews ie < 1042x948
|
||||||
|
let scalingFactor = 0.97
|
||||||
|
|
||||||
|
let resizedSize = CGSize(
|
||||||
|
width: icon.size.width * scalingFactor,
|
||||||
|
height: icon.size.height * scalingFactor
|
||||||
|
)
|
||||||
|
|
||||||
|
let resizedIcon = icon.resizing(to: resizedSize)!
|
||||||
|
|
||||||
let daysRemaining = app.expirationDate.numberOfCalendarDays(since: entry.date)
|
let daysRemaining = app.expirationDate.numberOfCalendarDays(since: entry.date)
|
||||||
let cornerRadius = rowHeight / 5.0
|
let cornerRadius = rowHeight / 5.0
|
||||||
|
|
||||||
HStack(spacing: 10) {
|
HStack(spacing: 10) {
|
||||||
Image(uiImage: app.icon ?? UIImage(named: "AltStore")!)
|
Image(uiImage: resizedIcon)
|
||||||
.resizable()
|
.resizable()
|
||||||
.aspectRatio(contentMode: .fit)
|
.aspectRatio(contentMode: .fit)
|
||||||
.cornerRadius(cornerRadius)
|
.cornerRadius(cornerRadius)
|
||||||
|
|||||||
@@ -130,7 +130,12 @@ private struct AppDetailWidgetView: View
|
|||||||
.frame(maxWidth: .infinity, maxHeight: .infinity)
|
.frame(maxWidth: .infinity, maxHeight: .infinity)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.widgetBackground(backgroundView(icon: entry.apps.first?.icon, tintColor: entry.apps.first?.tintColor))
|
.widgetBackground(
|
||||||
|
backgroundView(
|
||||||
|
icon: entry.apps.first?.icon,
|
||||||
|
tintColor: entry.apps.first?.tintColor
|
||||||
|
)
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -146,17 +151,35 @@ private extension AppDetailWidgetView
|
|||||||
let blurRadius = 5 as CGFloat
|
let blurRadius = 5 as CGFloat
|
||||||
let tintOpacity = 0.45
|
let tintOpacity = 0.45
|
||||||
|
|
||||||
|
// 1024x1024 images are not supported by previews but supported by device
|
||||||
|
// so we scale the image to 97% so as to reduce its actual size but not too much
|
||||||
|
// to somewhere below value, acceptable by previews ie < 1042x948
|
||||||
|
let scalingFactor = 0.97
|
||||||
|
|
||||||
|
let resizedSize = CGSize(
|
||||||
|
width: icon.size.width * scalingFactor,
|
||||||
|
height: icon.size.height * scalingFactor
|
||||||
|
)
|
||||||
|
|
||||||
|
let resizedIcon = icon.resizing(to: resizedSize)!
|
||||||
|
|
||||||
return ZStack(alignment: .topTrailing) {
|
return ZStack(alignment: .topTrailing) {
|
||||||
// Blurred Image
|
// Blurred Image
|
||||||
GeometryReader { geometry in
|
GeometryReader { geometry in
|
||||||
ZStack {
|
ZStack {
|
||||||
Image(uiImage: icon)
|
Image(uiImage: resizedIcon)
|
||||||
.resizable()
|
.resizable()
|
||||||
.aspectRatio(contentMode: .fill)
|
.aspectRatio(contentMode: .fill)
|
||||||
.frame(width: imageHeight, height: imageHeight, alignment: .center)
|
.frame(width: imageHeight, height: imageHeight, alignment: .center)
|
||||||
.saturation(saturation)
|
.saturation(saturation)
|
||||||
.blur(radius: blurRadius, opaque: true)
|
.blur(radius: blurRadius, opaque: true)
|
||||||
.scaleEffect(geometry.size.width / imageHeight, anchor: .center)
|
.scaleEffect(geometry.size.width / imageHeight, anchor: .center)
|
||||||
|
// .onAppear {
|
||||||
|
// print("Geometry size: \(geometry.size)")
|
||||||
|
// print("Image height: \(imageHeight), Geometry width: \(geometry.size.width)")
|
||||||
|
// print("Icon size: \(icon.size)")
|
||||||
|
// }
|
||||||
|
|
||||||
|
|
||||||
Color(tintColor)
|
Color(tintColor)
|
||||||
.opacity(tintOpacity)
|
.opacity(tintOpacity)
|
||||||
@@ -176,13 +199,11 @@ private extension AppDetailWidgetView
|
|||||||
AppDetailWidget()
|
AppDetailWidget()
|
||||||
} timeline: {
|
} timeline: {
|
||||||
let expiredDate = Date().addingTimeInterval(1 * 60 * 60 * 24 * 7)
|
let expiredDate = Date().addingTimeInterval(1 * 60 * 60 * 24 * 7)
|
||||||
let (altstore, delta, _, _, longDelta, _) = AppSnapshot.makePreviewSnapshots()
|
let (altstore, _, _, longAltStore, _, _) = AppSnapshot.makePreviewSnapshots()
|
||||||
|
|
||||||
AppsEntry(date: Date(), apps: [altstore])
|
AppsEntry(date: Date(), apps: [altstore])
|
||||||
AppsEntry(date: Date(), apps: [delta])
|
AppsEntry(date: Date(), apps: [longAltStore])
|
||||||
AppsEntry(date: Date(), apps: [longDelta])
|
|
||||||
|
|
||||||
AppsEntry(date: expiredDate, apps: [delta])
|
AppsEntry(date: expiredDate, apps: [altstore])
|
||||||
|
|
||||||
AppsEntry(date: Date(), apps: [])
|
AppsEntry(date: Date(), apps: [])
|
||||||
AppsEntry(date: Date(), apps: [], isPlaceholder: true)
|
AppsEntry(date: Date(), apps: [], isPlaceholder: true)
|
||||||
|
|||||||
Reference in New Issue
Block a user