Skip to content

Commit

Permalink
add: QRCodeWidget 생성 (TeamNADA#364)
Browse files Browse the repository at this point in the history
  • Loading branch information
hyun99999 committed Feb 6, 2023
1 parent 21f6d7f commit eee4a5c
Showing 1 changed file with 54 additions and 0 deletions.
54 changes: 54 additions & 0 deletions Widgets/WidgetsBundle/QRCodeWidget.swift
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))
}
}

0 comments on commit eee4a5c

Please sign in to comment.