forked from TeamNADA/NADA-iOS-ForRelease
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
54 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
// | ||
// QRCodeWidget.swift | ||
// WidgetsExtension | ||
// | ||
// Created by kimhyungyu on 2023/02/05. | ||
// | ||
|
||
import WidgetKit | ||
import SwiftUI | ||
|
||
struct QRCodeProvider: TimelineProvider { | ||
func placeholder(in context: Context) -> QRCodeEntry { | ||
QRCodeEntry(date: Date()) | ||
} | ||
|
||
func getSnapshot(in context: Context, completion: @escaping (QRCodeEntry) -> Void) { | ||
let entry = QRCodeEntry(date: Date()) | ||
completion(entry) | ||
} | ||
|
||
func getTimeline(in context: Context, completion: @escaping (Timeline<Entry>) -> Void) { | ||
var entries: [QRCodeEntry] = [] | ||
|
||
let currentDate = Date() | ||
for hourOffset in 0 ..< 5 { | ||
let entryDate = Calendar.current.date(byAdding: .hour, value: hourOffset, to: currentDate)! | ||
let entry = QRCodeEntry(date: entryDate) | ||
entries.append(entry) | ||
} | ||
|
||
let timeline = Timeline(entries: entries, policy: .never) | ||
completion(timeline) | ||
} | ||
} | ||
|
||
struct QRCodeEntry: TimelineEntry { | ||
let date: Date | ||
} | ||
struct QRCodeWidget: Widget { | ||
let kind: String = "QRCodeWidget" | ||
|
||
var body: some WidgetConfiguration { | ||
StaticConfiguration(kind: kind, | ||
provider: QRCodeProvider()) { entry in | ||
QRCodeEntryView(entry: entry) | ||
} | ||
} | ||
|
||
struct QRCodeWidget_Previews: PreviewProvider { | ||
static var previews: some View { | ||
QRCodeEntryView(entry: QRCodeEntry(date: Date())) | ||
.previewContext(WidgetPreviewContext(family: .systemSmall)) | ||
} | ||
} |