More fix for timeline widget

This commit is contained in:
Thomas Ricouard 2024-05-05 18:06:47 +02:00
parent 73651cb7f1
commit c4dee39efe

View file

@ -10,7 +10,7 @@ struct LatestPostsWidgetProvider: AppIntentTimelineProvider {
.init(date: Date(), .init(date: Date(),
configuration: IceCubesWidgetConfigurationIntent(), configuration: IceCubesWidgetConfigurationIntent(),
timeline: .home, timeline: .home,
statuses: [.placeholder(), .placeholder()], statuses: [.placeholder()],
images: [:]) images: [:])
} }
@ -45,17 +45,17 @@ struct LatestPostsWidgetProvider: AppIntentTimelineProvider {
offset: nil)) offset: nil))
statuses = statuses.filter{ $0.reblog == nil && !$0.content.asRawText.isEmpty } statuses = statuses.filter{ $0.reblog == nil && !$0.content.asRawText.isEmpty }
switch context.family { switch context.family {
case .systemMedium: case .systemSmall, .systemMedium:
if statuses.count >= 2 { if statuses.count >= 1 {
statuses = statuses.prefix(upTo: 2).map{ $0 } statuses = statuses.prefix(upTo: 1).map{ $0 }
} }
case .systemLarge: case .systemLarge:
if statuses.count >= 5 { if statuses.count >= 4 {
statuses = statuses.prefix(upTo: 5).map{ $0 } statuses = statuses.prefix(upTo: 4).map{ $0 }
} }
case .systemExtraLarge: case .systemExtraLarge:
if statuses.count >= 8 { if statuses.count >= 6 {
statuses = statuses.prefix(upTo: 8).map{ $0 } statuses = statuses.prefix(upTo: 6).map{ $0 }
} }
default: default:
break break
@ -108,11 +108,24 @@ struct LatestPostsWidgetView : View {
@Environment(\.widgetFamily) var family @Environment(\.widgetFamily) var family
@Environment(\.redactionReasons) var redacted @Environment(\.redactionReasons) var redacted
var contentLineLimit: Int {
switch family {
case .systemSmall, .systemMedium:
return 4
default:
return 2
}
}
var body: some View { var body: some View {
VStack(alignment: .leading, spacing: 8) { VStack(alignment: .leading, spacing: 8) {
headerView headerView
ForEach(entry.statuses) { status in ForEach(entry.statuses) { status in
VStack(spacing: 4) {
makeStatusView(status) makeStatusView(status)
if entry.statuses.last?.id != status.id {
Divider()
}
}
} }
Spacer() Spacer()
} }
@ -134,11 +147,12 @@ struct LatestPostsWidgetView : View {
private func makeStatusView(_ status: Status) -> some View { private func makeStatusView(_ status: Status) -> some View {
if let url = URL(string: status.url ?? "") { if let url = URL(string: status.url ?? "") {
Link(destination: url, label: { Link(destination: url, label: {
VStack(alignment: .leading, spacing: 4) { VStack(alignment: .leading, spacing: 2) {
makeStatusHeaderView(status) makeStatusHeaderView(status)
Text(status.content.asRawText) Text(status.content.asSafeMarkdownAttributedString)
.font(.body) .font(.body)
.lineLimit(2) .lineLimit(contentLineLimit)
.fixedSize(horizontal: false, vertical: true)
} }
}) })
} }
@ -157,7 +171,9 @@ struct LatestPostsWidgetView : View {
.frame(width: 16, height: 16) .frame(width: 16, height: 16)
} }
HStack(spacing: 0) { HStack(spacing: 0) {
if family != .systemSmall {
Text(status.account.safeDisplayName) Text(status.account.safeDisplayName)
}
Text(" @") Text(" @")
Text(status.account.username) Text(status.account.username)
Spacer() Spacer()
@ -182,7 +198,7 @@ struct LatestPostsWidget: Widget {
} }
.configurationDisplayName("Latest posts") .configurationDisplayName("Latest posts")
.description("Show the latest post for the selected timeline") .description("Show the latest post for the selected timeline")
.supportedFamilies([.systemMedium, .systemLarge, .systemExtraLarge]) .supportedFamilies([.systemSmall, .systemMedium, .systemLarge, .systemExtraLarge])
} }
} }