import WidgetKit import SwiftUI struct Provider: TimelineProvider { public typealias Entry = SimpleEntry public func snapshot(with context: Context, completion: @escaping (SimpleEntry) -> ()) { let entry = SimpleEntry(date: Date()) completion(entry) } public func timeline(with 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: .minute, value: hourOffset, to: currentDate)! let entry = SimpleEntry(date: entryDate) entries.append(entry) } let timeline = Timeline(entries: entries, policy: .atEnd) completion(timeline) } } struct SimpleEntry: TimelineEntry { public let date: Date } struct PlaceholderView : View { var body: some View { Text("01:05 AM\nMarch 22nd, 2020") } } struct CPCWidgetEntryView : View { var entry: Provider.Entry let components = DateComponents(minute: 11, second: 14) let futureDate = Calendar.current.date(byAdding : DateComponents(minute: 1, second: 0), to: Date())! var body: some View { ZStack { Color(.black) .edgesIgnoringSafeArea(.all) VStack(alignment: .center, spacing: 0) { Text(futureDate, style: .time) .font(.custom("Times New Roman-bold", size: 30)) // Text(futureDate, style: .date) // .font(.custom("Times New Roman-bold", size: 38)) // } .background(Color.black).foregroundColor(Color.orange) } } } @main struct CPCWidget: Widget { private let kind: String = "CPCWidget" public var body: some WidgetConfiguration { StaticConfiguration(kind: "com.connectingpeoplesoftware.cpclockwidget", provider: Provider(), placeholder: PlaceholderView()) { entry in CPCWidgetEntryView(entry: entry) } .configurationDisplayName("CPClock") .description("CPClock in widget form.") .supportedFamilies([.systemSmall, .systemMedium, .systemLarge]) } } struct CPCWidget_Previews: PreviewProvider { static var previews: some View { /*@START_MENU_TOKEN@*/Text("Hello, World!")/*@END_MENU_TOKEN@*/ } }