💄 Optimize iOS notifications widget

This commit is contained in:
2026-01-04 01:20:50 +08:00
parent 9071ac44fe
commit 97a5e951e1

View File

@@ -110,6 +110,10 @@ class NotificationService {
}()
func fetchRecentNotifications(take: Int = 5) async throws -> [SnNotification] {
if take == 0 {
return []
}
guard let token = networkService.token else {
throw RemoteError.missingCredentials
}
@@ -213,13 +217,13 @@ struct NotificationProvider: TimelineProvider {
let takeLimit: Int
switch context.family {
case .systemSmall:
takeLimit = 3
takeLimit = 0
case .systemMedium:
takeLimit = 5
takeLimit = 1
case .systemLarge:
takeLimit = 10
takeLimit = 3
default:
takeLimit = 5
takeLimit = 0
}
async let notifications = try await notificationService.fetchRecentNotifications(take: takeLimit)
@@ -384,7 +388,7 @@ struct NotificationWidgetEntryView: View {
}
}.padding(.bottom, 8)
let displayCount = family == .systemMedium ? 1 : 3
let displayCount = family == .systemMedium ? 1 : 5
let displayNotifications = Array(notifications.prefix(displayCount))
VStack(alignment: .leading, spacing: 4) {
@@ -439,6 +443,13 @@ struct NotificationWidgetEntryView: View {
.lineLimit(1)
}
if !compact && !notification.content.isEmpty {
Text(notification.content)
.font(.caption2)
.lineLimit(2)
.multilineTextAlignment(.leading)
}
if let createdDate = notification.createdDate {
Text(formatRelativeTime(createdDate))
.font(.caption2)