Skip to content

Commit

Permalink
add: OpenAppLockScreenWidget 생성 (TeamNADA#364)
Browse files Browse the repository at this point in the history
- 잠금화면 위젯으로만 사용하기 때문에 accessoryCircular 만 설정.
- 선택목록이 없는 위젯이기 때문에 StaticConfiguration 사용.
  • Loading branch information
hyun99999 committed Feb 6, 2023
1 parent d1c163a commit 2dab489
Showing 1 changed file with 56 additions and 0 deletions.
56 changes: 56 additions & 0 deletions Widgets/WidgetsBundle/OpenAppLockScreenWidget.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
//
// OpenAppLockScreenWidget.swift
// WidgetsExtension
//
// Created by kimhyungyu on 2023/02/05.
//

import WidgetKit
import SwiftUI

struct OpenAppLockScreenProvider: TimelineProvider {
func placeholder(in context: Context) -> OpenAppLockScreenEntry {
OpenAppLockScreenEntry(date: Date())
}

func getSnapshot(in context: Context, completion: @escaping (OpenAppLockScreenEntry) -> Void) {
let entry = OpenAppLockScreenEntry(date: Date())
completion(entry)
}

func getTimeline(in context: Context, completion: @escaping (Timeline<Entry>) -> Void) {
var entries: [OpenAppLockScreenEntry] = []

let currentDate = Date()
for hourOffset in 0 ..< 5 {
let entryDate = Calendar.current.date(byAdding: .hour, value: hourOffset, to: currentDate)!
let entry = OpenAppLockScreenEntry(date: entryDate)
entries.append(entry)
}

let timeline = Timeline(entries: entries, policy: .never)
completion(timeline)
}
}

struct OpenAppLockScreenEntry: TimelineEntry {
let date: Date
}
struct OpenAppLockScreenWidget: Widget {
let kind: String = "OpenAppLockScreen"

var body: some WidgetConfiguration {
StaticConfiguration(kind: kind,
provider: OpenAppLockScreenProvider()) { entry in
OpenAppLockScreenEntryView(entry: entry)
}
.supportedFamilies([.accessoryCircular])
}
}

struct OpenAppLockScreenWidget_Previews: PreviewProvider {
static var previews: some View {
OpenAppLockScreenEntryView(entry: OpenAppLockScreenEntry(date: Date()))
.previewContext(WidgetPreviewContext(family: .accessoryCircular))
}
}

0 comments on commit 2dab489

Please sign in to comment.