Modern Apps git

xtool.git

Public
git clone https://git.maproj.org/xtool.git
appstore-distribution ▾

xtool.git / Examples / DemoExtensions / Sources / DemoExtensionsWidget / Widget.swift

Widget.swift51 lines · 1.2 KiBRaw
1import WidgetKit
2import SwiftUI
3
4@main struct Bundle: WidgetBundle {
5 var body: some Widget {
6 DemoWidget()
7 }
8}
9
10struct DemoWidget: Widget {
11 var body: some WidgetConfiguration {
12 StaticConfiguration(
13 kind: "DemoWidget",
14 provider: Provider()
15 ) { entry in
16 VStack {
17 Text(entry.date, style: .date)
18 }
19 .containerBackground(.fill.tertiary, for: .widget)
20 }
21 .configurationDisplayName("DemoWidget")
22 .description("This is an example widget.")
23 }
24
25 struct Entry: TimelineEntry {
26 var date = Date()
27 }
28
29 struct Provider: TimelineProvider {
30 func placeholder(in context: Context) -> Entry {
31 Entry()
32 }
33
34 func getSnapshot(
35 in context: Context,
36 completion: @escaping (Entry) -> Void
37 ) {
38 completion(Entry())
39 }
40
41 func getTimeline(
42 in context: Context,
43 completion: @escaping (Timeline<Entry>) -> Void
44 ) {
45 completion(Timeline(
46 entries: [Entry()],
47 policy: .after(.now + 3600)
48 ))
49 }
50 }
51}