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.
add: OpenAppLockScreenWidget 생성 (TeamNADA#364)
- 잠금화면 위젯으로만 사용하기 때문에 accessoryCircular 만 설정. - 선택목록이 없는 위젯이기 때문에 StaticConfiguration 사용.
- Loading branch information
Showing
1 changed file
with
56 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,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)) | ||
} | ||
} |