You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
85 lines
2.3 KiB
Swift
85 lines
2.3 KiB
Swift
|
4 weeks ago
|
//
|
||
|
|
// live_notifications.swift
|
||
|
|
// live_notifications
|
||
|
|
//
|
||
|
|
// Created by Cloud Solutions on 21/07/2026.
|
||
|
|
//
|
||
|
|
|
||
|
|
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 live_notificationEntryView : View {
|
||
|
|
var entry: Provider.Entry
|
||
|
|
|
||
|
|
var body: some View {
|
||
|
|
VStack {
|
||
|
|
Text("Time:")
|
||
|
|
Text(entry.date, style: .time)
|
||
|
|
|
||
|
|
Text("Emoji:")
|
||
|
|
Text(entry.emoji)
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
struct live_notification: Widget {
|
||
|
|
let kind: String = "live_notifications"
|
||
|
|
|
||
|
|
var body: some WidgetConfiguration {
|
||
|
|
StaticConfiguration(kind: kind, provider: Provider()) { entry in
|
||
|
|
if #available(iOS 17.0, *) {
|
||
|
|
live_notificationEntryView(entry: entry)
|
||
|
|
.containerBackground(.fill.tertiary, for: .widget)
|
||
|
|
} else {
|
||
|
|
live_notificationEntryView(entry: entry)
|
||
|
|
.padding()
|
||
|
|
.background()
|
||
|
|
}
|
||
|
|
}
|
||
|
|
.configurationDisplayName("My Widget")
|
||
|
|
.description("This is an example widget.")
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
#Preview(as: .systemSmall) {
|
||
|
|
live_notification()
|
||
|
|
} timeline: {
|
||
|
|
SimpleEntry(date: .now, emoji: "😀")
|
||
|
|
SimpleEntry(date: .now, emoji: "🤩")
|
||
|
|
}
|