2023-03-11 18:30:33 +01:00
|
|
|
//
|
|
|
|
// https://mczachurski.dev
|
|
|
|
// Copyright © 2023 Marcin Czachurski and the repository contributors.
|
2023-03-28 10:35:38 +02:00
|
|
|
// Licensed under the Apache License 2.0.
|
2023-03-11 18:30:33 +01:00
|
|
|
//
|
2023-04-01 12:10:59 +02:00
|
|
|
|
2023-03-11 18:30:33 +01:00
|
|
|
import SwiftUI
|
|
|
|
import WidgetKit
|
|
|
|
|
|
|
|
struct SmallWidgetView: View {
|
|
|
|
var entry: Provider.Entry
|
|
|
|
|
|
|
|
var body: some View {
|
|
|
|
if let uiImage = entry.image, let uiAvatar = entry.avatar {
|
2023-03-12 06:51:14 +01:00
|
|
|
self.getWidgetBody(uiImage: Image(uiImage: uiImage), uiAvatar: Image(uiImage: uiAvatar))
|
|
|
|
} else {
|
|
|
|
self.getWidgetBody(uiImage: Image("Placeholder"), uiAvatar: Image("Avatar"))
|
|
|
|
.unredacted()
|
|
|
|
}
|
|
|
|
}
|
2023-04-01 12:10:59 +02:00
|
|
|
|
2023-03-12 06:51:14 +01:00
|
|
|
@ViewBuilder
|
|
|
|
private func getWidgetBody(uiImage: Image, uiAvatar: Image) -> some View {
|
|
|
|
VStack {
|
|
|
|
Spacer()
|
|
|
|
HStack {
|
|
|
|
uiAvatar
|
2023-03-11 18:30:33 +01:00
|
|
|
.resizable()
|
2023-03-12 06:51:14 +01:00
|
|
|
.clipShape(Circle())
|
|
|
|
.aspectRatio(contentMode: .fit)
|
2023-03-12 07:06:41 +01:00
|
|
|
.frame(width: 16, height: 16)
|
2023-03-12 06:51:14 +01:00
|
|
|
.overlay(
|
|
|
|
Circle()
|
2023-03-12 07:06:41 +01:00
|
|
|
.stroke(Color.white.opacity(0.6), lineWidth: 1)
|
|
|
|
.frame(width: 16, height: 16)
|
2023-03-12 06:51:14 +01:00
|
|
|
)
|
2023-03-12 07:46:14 +01:00
|
|
|
.shadow(color: .black, radius: 2)
|
2023-04-01 12:10:59 +02:00
|
|
|
|
2023-03-12 06:51:14 +01:00
|
|
|
Spacer()
|
2023-03-11 18:30:33 +01:00
|
|
|
}
|
2023-03-12 06:51:14 +01:00
|
|
|
.padding(.leading, 8)
|
|
|
|
.padding(.bottom, 8)
|
|
|
|
}
|
|
|
|
.background {
|
|
|
|
uiImage
|
|
|
|
.resizable()
|
|
|
|
.aspectRatio(contentMode: .fill)
|
|
|
|
.widgetURL(URL(string: "\(AppConstants.statusUri)/\(entry.statusId ?? "")"))
|
2023-03-11 18:30:33 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|