feat(Widget): Implement MultiFollowersCountWidget for medium size

This commit is contained in:
Marcus Kida 2023-01-31 14:54:05 +01:00
parent 9eb26d4ed8
commit 15b6b9fb93
No known key found for this signature in database
GPG Key ID: 19FF64E08013CA40
2 changed files with 41 additions and 3 deletions

View File

@ -56,7 +56,7 @@ struct MultiFollowersCountEntry: TimelineEntry {
struct MultiFollowersCountWidget: Widget {
private var availableFamilies: [WidgetFamily] {
return [.systemSmall]
return [.systemSmall, .systemMedium]
}
var body: some WidgetConfiguration {

View File

@ -13,7 +13,9 @@ struct MultiFollowersCountWidgetView: View {
if let accounts = entry.accounts {
switch family {
case .systemSmall:
viewForSmallWidgetNoChart(accounts)
viewForSmallWidget(accounts)
case .systemMedium:
viewForMediumWidget(accounts)
default:
Text("Sorry but this Widget family is unsupported.")
}
@ -25,7 +27,7 @@ struct MultiFollowersCountWidgetView: View {
}
}
private func viewForSmallWidgetNoChart(_ accounts: [FollowersEntryAccountable]) -> some View {
private func viewForSmallWidget(_ accounts: [FollowersEntryAccountable]) -> some View {
VStack(alignment: .leading, spacing: 0) {
ForEach(accounts, id: \.acct) { account in
HStack {
@ -55,4 +57,40 @@ struct MultiFollowersCountWidgetView: View {
}
.padding(.vertical, 16)
}
private func viewForMediumWidget(_ accounts: [FollowersEntryAccountable]) -> some View {
VStack(alignment: .leading, spacing: 0) {
LazyVGrid(columns: [
GridItem(.flexible()),
GridItem(.flexible())
]) {
ForEach(accounts, id: \.acct) { account in
HStack {
if let avatarImage = account.avatarImage {
Image(uiImage: avatarImage)
.resizable()
.frame(width: 32, height: 32)
.cornerRadius(5)
}
VStack(alignment: .leading) {
Text(account.followersCount.asAbbreviatedCountString())
.font(.title2)
.lineLimit(1)
.truncationMode(.tail)
Text("@\(account.acct)")
.font(.caption2)
.foregroundColor(.secondary)
.lineLimit(1)
.truncationMode(.tail)
}
Spacer()
}
.padding(.leading, 20)
}
}
Spacer()
}
.padding(.vertical, 16)
}
}