| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143 |
- import SwiftUI
- import WidgetKit
- // MARK: - Timeline Entry
- struct TrioWatchComplicationEntry: TimelineEntry {
- let date: Date
- }
- // MARK: - Provider
- struct TrioWatchComplicationProvider: TimelineProvider {
- func placeholder(in _: Context) -> TrioWatchComplicationEntry {
- TrioWatchComplicationEntry(date: Date())
- }
- func getSnapshot(in _: Context, completion: @escaping (TrioWatchComplicationEntry) -> Void) {
- let entry = TrioWatchComplicationEntry(date: Date())
- completion(entry)
- }
- func getTimeline(in _: Context, completion: @escaping (Timeline<TrioWatchComplicationEntry>) -> Void) {
- let entry = TrioWatchComplicationEntry(date: Date())
- let timeline = Timeline(entries: [entry], policy: .never)
- completion(timeline)
- }
- }
- // MARK: - Views
- //// Displayed View Wrapper
- struct TrioWatchComplicationEntryView: View {
- @Environment(\.widgetFamily) private var widgetFamily
- var entry: TrioWatchComplicationEntry
- var body: some View {
- switch widgetFamily {
- case .accessoryRectangular:
- TrioAccessoryRectangularView(entry: entry)
- case .accessoryCircular:
- TrioAccessoryCircularView(entry: entry)
- case .accessoryCorner:
- TrioAccessoryCornerView(entry: entry)
- case .accessoryInline:
- TrioAccessoryInlineView(entry: entry)
- default:
- Image("ComplicationIcon")
- }
- }
- }
- /// Corner Complication
- struct TrioAccessoryCornerView: View {
- var entry: TrioWatchComplicationProvider.Entry
- var body: some View {
- ZStack {
- Circle()
- .fill(Color.white.opacity(0.2))
- Image("ComplicationIcon")
- .resizable()
- .scaledToFit()
- .padding(5)
- }
- }
- }
- /// Circular Complication
- struct TrioAccessoryCircularView: View {
- var entry: TrioWatchComplicationProvider.Entry
- var body: some View {
- if let uiImage = UIImage(named: "ComplicationIcon") {
- Image(uiImage: uiImage)
- .resizable()
- .scaledToFit()
- .padding(5)
- } else {
- ZStack {
- Circle().fill(Color.red.opacity(0.2))
- Text("No Image!")
- .font(.caption)
- .foregroundColor(.white)
- }
- }
- }
- }
- /// Rectangular Complication
- struct TrioAccessoryRectangularView: View {
- var entry: TrioWatchComplicationProvider.Entry
- var body: some View {
- HStack {
- Image("ComplicationIcon")
- .resizable()
- .scaledToFit()
- .frame(width: 30, height: 30)
- Text("Trio")
- .font(.headline)
- .foregroundColor(.primary)
- }
- }
- }
- /// Inline Complication
- struct TrioAccessoryInlineView: View {
- var entry: TrioWatchComplicationProvider.Entry
- var body: some View {
- HStack {
- Image("ComplicationIcon")
- .resizable()
- .scaledToFit()
- .frame(width: 12, height: 12)
- Text("Trio")
- .font(.caption)
- .foregroundColor(.primary)
- }
- }
- }
- // MARK: - Widget Configuration
- @main struct TrioWatchComplication: Widget {
- let kind: String = "TrioWatchComplication"
- var body: some WidgetConfiguration {
- StaticConfiguration(kind: kind, provider: TrioWatchComplicationProvider()) { entry in
- TrioWatchComplicationEntryView(entry: entry)
- }
- .configurationDisplayName("Trio")
- .description("Displays Trio app icon as complication")
- .supportedFamilies([
- .accessoryCorner,
- .accessoryCircular,
- .accessoryRectangular,
- .accessoryInline
- ])
- }
- }
|