From e9e3a4c4749bfced03ef12dd1a30ccb81b692fba Mon Sep 17 00:00:00 2001 From: LittleSheep Date: Sat, 21 Dec 2024 22:38:22 +0800 Subject: [PATCH] :bug: Bug fixes on iOS widget --- ios/SolarWidget/CheckInWidget.swift | 15 +++------------ ios/SolarWidget/RandomPostWidget.swift | 17 +++++++++++------ 2 files changed, 14 insertions(+), 18 deletions(-) diff --git a/ios/SolarWidget/CheckInWidget.swift b/ios/SolarWidget/CheckInWidget.swift index 18a6ca9..9e7ef35 100644 --- a/ios/SolarWidget/CheckInWidget.swift +++ b/ios/SolarWidget/CheckInWidget.swift @@ -10,7 +10,7 @@ import SwiftUI struct CheckInProvider: TimelineProvider { func placeholder(in context: Context) -> CheckInEntry { - CheckInEntry(date: Date(), user: nil, checkIn: nil) + CheckInEntry(date: Date(), checkIn: nil) } func getSnapshot(in context: Context, completion: @escaping (CheckInEntry) -> ()) { @@ -23,24 +23,17 @@ struct CheckInProvider: TimelineProvider { jsonDecoder.dateDecodingStrategy = .formatted(dateFormatter) jsonDecoder.keyDecodingStrategy = .convertFromSnakeCase - let userRaw = prefs?.string(forKey: "user") - var user: SolarUser? - if let userRaw = userRaw { - user = try! jsonDecoder.decode(SolarUser.self, from: userRaw.data(using: .utf8)!) - } - let checkInRaw = prefs?.string(forKey: "pas_check_in_record") var checkIn: SolarCheckInRecord? if let checkInRaw = checkInRaw { checkIn = try! jsonDecoder.decode(SolarCheckInRecord.self, from: checkInRaw.data(using: .utf8)!) - if checkIn != nil && Calendar.current.isDate(checkIn!.createdAt, inSameDayAs: Date()) { + if checkIn != nil && !Calendar.current.isDate(checkIn!.createdAt, inSameDayAs: Date()) { checkIn = nil } } let entry = CheckInEntry( date: Date(), - user: user, checkIn: checkIn ) completion(entry) @@ -56,7 +49,6 @@ struct CheckInProvider: TimelineProvider { struct CheckInEntry: TimelineEntry { let date: Date - let user: SolarUser? let checkIn: SolarCheckInRecord? } @@ -135,10 +127,9 @@ struct CheckInWidget: Widget { #Preview(as: .systemSmall) { CheckInWidget() } timeline: { - CheckInEntry(date: .now, user: nil, checkIn: nil) + CheckInEntry(date: .now, checkIn: nil) CheckInEntry( date: .now, - user: SolarUser(id: 1, name: "demo", nick: "Deemo"), checkIn: SolarCheckInRecord(id: 1, resultTier: 1, resultExperience: 100, createdAt: Date.now) ) } diff --git a/ios/SolarWidget/RandomPostWidget.swift b/ios/SolarWidget/RandomPostWidget.swift index 48cba96..b31bda5 100644 --- a/ios/SolarWidget/RandomPostWidget.swift +++ b/ios/SolarWidget/RandomPostWidget.swift @@ -13,7 +13,7 @@ struct RandomPostProvider: TimelineProvider { func placeholder(in context: Context) -> RandomPostEntry { RandomPostEntry(date: Date(), user: nil, randomPost: nil, family: .systemMedium) } - + func getSnapshot(in context: Context, completion: @escaping (RandomPostEntry) -> ()) { let prefs = UserDefaults(suiteName: "group.solsynth.solian") @@ -45,7 +45,7 @@ struct RandomPostProvider: TimelineProvider { ) completion(entry) } - + func getTimeline(in context: Context, completion: @escaping (Timeline) -> ()) { getSnapshot(in: context) { (entry) in let timeline = Timeline(entries: [entry], policy: .atEnd) @@ -64,7 +64,7 @@ struct RandomPostEntry: TimelineEntry { struct RandomPostWidgetEntryView : View { var entry: RandomPostProvider.Entry - + var body: some View { VStack(alignment: .leading, spacing: 0) { if let randomPost = entry.randomPost { @@ -73,15 +73,20 @@ struct RandomPostWidgetEntryView : View { if let avatar = randomPost.publisher.avatar { let avatarUrl = getAttachmentUrl(for: avatar) let size: CGFloat = 28 - let scaleProcessor = ResizingImageProcessor(referenceSize: CGSize(width: size, height: size), mode: .aspectFit) + let scaleProcessor = ResizingImageProcessor(referenceSize: CGSize(width: size, height: size), mode: .aspectFill) KFImage.url(URL(string: avatarUrl)) .resizable() .setProcessor(scaleProcessor) .fade(duration: 0.25) - .aspectRatio(contentMode: .fit) + .placeholder{ + ProgressView() + .progressViewStyle(CircularProgressViewStyle()) + } + .aspectRatio(contentMode: .fill) .frame(width: size, height: size) .cornerRadius(size / 2) + .frame(width: size, height: size, alignment: .center) } @@ -158,7 +163,7 @@ struct RandomPostWidgetEntryView : View { struct RandomPostWidget: Widget { let kind: String = "SolarRandomPostWidget" - + var body: some WidgetConfiguration { StaticConfiguration(kind: kind, provider: RandomPostProvider()) { entry in if #available(iOS 17.0, *) {