feat(widget): add initial widget target
This commit is contained in:
		| @@ -0,0 +1,11 @@ | ||||
| { | ||||
|   "colors" : [ | ||||
|     { | ||||
|       "idiom" : "universal" | ||||
|     } | ||||
|   ], | ||||
|   "info" : { | ||||
|     "author" : "xcode", | ||||
|     "version" : 1 | ||||
|   } | ||||
| } | ||||
| @@ -0,0 +1,35 @@ | ||||
| { | ||||
|   "images" : [ | ||||
|     { | ||||
|       "idiom" : "universal", | ||||
|       "platform" : "ios", | ||||
|       "size" : "1024x1024" | ||||
|     }, | ||||
|     { | ||||
|       "appearances" : [ | ||||
|         { | ||||
|           "appearance" : "luminosity", | ||||
|           "value" : "dark" | ||||
|         } | ||||
|       ], | ||||
|       "idiom" : "universal", | ||||
|       "platform" : "ios", | ||||
|       "size" : "1024x1024" | ||||
|     }, | ||||
|     { | ||||
|       "appearances" : [ | ||||
|         { | ||||
|           "appearance" : "luminosity", | ||||
|           "value" : "tinted" | ||||
|         } | ||||
|       ], | ||||
|       "idiom" : "universal", | ||||
|       "platform" : "ios", | ||||
|       "size" : "1024x1024" | ||||
|     } | ||||
|   ], | ||||
|   "info" : { | ||||
|     "author" : "xcode", | ||||
|     "version" : 1 | ||||
|   } | ||||
| } | ||||
							
								
								
									
										6
									
								
								StepMapWidgets/Assets.xcassets/Contents.json
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										6
									
								
								StepMapWidgets/Assets.xcassets/Contents.json
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,6 @@ | ||||
| { | ||||
|   "info" : { | ||||
|     "author" : "xcode", | ||||
|     "version" : 1 | ||||
|   } | ||||
| } | ||||
| @@ -0,0 +1,11 @@ | ||||
| { | ||||
|   "colors" : [ | ||||
|     { | ||||
|       "idiom" : "universal" | ||||
|     } | ||||
|   ], | ||||
|   "info" : { | ||||
|     "author" : "xcode", | ||||
|     "version" : 1 | ||||
|   } | ||||
| } | ||||
							
								
								
									
										11
									
								
								StepMapWidgets/Info.plist
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										11
									
								
								StepMapWidgets/Info.plist
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,11 @@ | ||||
| <?xml version="1.0" encoding="UTF-8"?> | ||||
| <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | ||||
| <plist version="1.0"> | ||||
| <dict> | ||||
| 	<key>NSExtension</key> | ||||
| 	<dict> | ||||
| 		<key>NSExtensionPointIdentifier</key> | ||||
| 		<string>com.apple.widgetkit-extension</string> | ||||
| 	</dict> | ||||
| </dict> | ||||
| </plist> | ||||
							
								
								
									
										84
									
								
								StepMapWidgets/StepMapWidgets.swift
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										84
									
								
								StepMapWidgets/StepMapWidgets.swift
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,84 @@ | ||||
| // | ||||
| //  StepMapWidgets.swift | ||||
| //  StepMapWidgets | ||||
| // | ||||
| //  Created by Oliver Hnát on 04.12.2024. | ||||
| // | ||||
|  | ||||
| import WidgetKit | ||||
| import SwiftUI | ||||
|  | ||||
| struct Provider: TimelineProvider { | ||||
|     func placeholder(in context: Context) -> SimpleEntry { | ||||
|         SimpleEntry(date: Date(), emoji: "😀") | ||||
|     } | ||||
|  | ||||
|     func getSnapshot(in context: Context, completion: @escaping (SimpleEntry) -> ()) { | ||||
|         let entry = SimpleEntry(date: Date(), emoji: "😀") | ||||
|         completion(entry) | ||||
|     } | ||||
|  | ||||
|     func getTimeline(in context: Context, completion: @escaping (Timeline<Entry>) -> ()) { | ||||
|         var entries: [SimpleEntry] = [] | ||||
|  | ||||
|         // Generate a timeline consisting of five entries an hour apart, starting from the current date. | ||||
|         let currentDate = Date() | ||||
|         for hourOffset in 0 ..< 5 { | ||||
|             let entryDate = Calendar.current.date(byAdding: .hour, value: hourOffset, to: currentDate)! | ||||
|             let entry = SimpleEntry(date: entryDate, emoji: "😀") | ||||
|             entries.append(entry) | ||||
|         } | ||||
|  | ||||
|         let timeline = Timeline(entries: entries, policy: .atEnd) | ||||
|         completion(timeline) | ||||
|     } | ||||
|  | ||||
| //    func relevances() async -> WidgetRelevances<Void> { | ||||
| //        // Generate a list containing the contexts this widget is relevant in. | ||||
| //    } | ||||
| } | ||||
|  | ||||
| struct SimpleEntry: TimelineEntry { | ||||
|     let date: Date | ||||
|     let emoji: String | ||||
| } | ||||
|  | ||||
| struct StepMapWidgetsEntryView : View { | ||||
|     var entry: Provider.Entry | ||||
|  | ||||
|     var body: some View { | ||||
|         VStack { | ||||
|             Text("Time:") | ||||
|             Text(entry.date, style: .time) | ||||
|  | ||||
|             Text("Emoji:") | ||||
|             Text(entry.emoji) | ||||
|         } | ||||
|     } | ||||
| } | ||||
|  | ||||
| struct StepMapWidgets: Widget { | ||||
|     let kind: String = "StepMapWidgets" | ||||
|  | ||||
|     var body: some WidgetConfiguration { | ||||
|         StaticConfiguration(kind: kind, provider: Provider()) { entry in | ||||
|             if #available(iOS 17.0, *) { | ||||
|                 StepMapWidgetsEntryView(entry: entry) | ||||
|                     .containerBackground(.fill.tertiary, for: .widget) | ||||
|             } else { | ||||
|                 StepMapWidgetsEntryView(entry: entry) | ||||
|                     .padding() | ||||
|                     .background() | ||||
|             } | ||||
|         } | ||||
|         .configurationDisplayName("My Widget") | ||||
|         .description("This is an example widget.") | ||||
|     } | ||||
| } | ||||
|  | ||||
| #Preview(as: .systemSmall) { | ||||
|     StepMapWidgets() | ||||
| } timeline: { | ||||
|     SimpleEntry(date: .now, emoji: "😀") | ||||
|     SimpleEntry(date: .now, emoji: "🤩") | ||||
| } | ||||
							
								
								
									
										16
									
								
								StepMapWidgets/StepMapWidgetsBundle.swift
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										16
									
								
								StepMapWidgets/StepMapWidgetsBundle.swift
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,16 @@ | ||||
| // | ||||
| //  StepMapWidgetsBundle.swift | ||||
| //  StepMapWidgets | ||||
| // | ||||
| //  Created by Oliver Hnát on 04.12.2024. | ||||
| // | ||||
|  | ||||
| import WidgetKit | ||||
| import SwiftUI | ||||
|  | ||||
| @main | ||||
| struct StepMapWidgetsBundle: WidgetBundle { | ||||
|     var body: some Widget { | ||||
|         StepMapWidgets() | ||||
|     } | ||||
| } | ||||
		Reference in New Issue
	
	Block a user