-
Notifications
You must be signed in to change notification settings - Fork 0
/
ComplexWidget.swift
90 lines (71 loc) · 2.28 KB
/
ComplexWidget.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
//
// ComplexWidget.swift
// BingeWatchersWidgetExtension
//
// Created by Anmol Jandaur on 6/8/22.
//
import SwiftUI
import WidgetKit
struct PortfolioWidgetMultipleEntryView: View {
let entry: Provider.Entry
@Environment(\.widgetFamily) var widgetFamily
@Environment(\.sizeCategory) var sizeCategory
var items: ArraySlice<Item> {
let itemCount: Int
switch widgetFamily {
case .systemSmall:
itemCount = 1
case .systemLarge:
if sizeCategory < .extraExtraLarge {
itemCount = 5
} else {
itemCount = 4
}
default:
if sizeCategory < .extraLarge {
itemCount = 3
} else {
itemCount = 2
}
}
return entry.items.prefix(itemCount)
}
var body: some View {
VStack(spacing: 5) {
ForEach(items) { item in
HStack {
Color(item.project?.color ?? "Light Blue")
.frame(width: 5)
.clipShape(Capsule())
VStack(alignment: .leading) {
Text(item.itemTitle)
.font(.headline)
.layoutPriority(1)
if let projectTitle = item.project?.title {
Text(projectTitle)
.foregroundColor(.secondary)
}
}
Spacer()
}
}
}
.padding(20)
}
}
struct ComplexPortfolioWidget: Widget {
let kind: String = "ComplexBingeWatchersWidget"
var body: some WidgetConfiguration {
StaticConfiguration(kind: kind, provider: Provider()) { entry in
PortfolioWidgetMultipleEntryView(entry: entry)
}
.configurationDisplayName("Up next…")
.description("Your most important items.")
}
}
struct ComplexBingeWatchersWidget_Previews: PreviewProvider {
static var previews: some View {
PortfolioWidgetMultipleEntryView(entry: SimpleEntry(date: Date(), items: [Item.example]))
.previewContext(WidgetPreviewContext(family: .systemSmall))
}
}