Skip to content

Commit

Permalink
[Feat] #252 - 위젯 설정
Browse files Browse the repository at this point in the history
  • Loading branch information
yungu0010 committed Apr 19, 2024
1 parent 434cbdb commit 65ac534
Show file tree
Hide file tree
Showing 2 changed files with 291 additions and 53 deletions.
52 changes: 22 additions & 30 deletions iOS-NOTTODO/Widget-NOTTODO/Widget_NOTTODO.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,45 +10,41 @@ import SwiftUI

struct Provider: AppIntentTimelineProvider {
func placeholder(in context: Context) -> SimpleEntry {
SimpleEntry(date: Date(), configuration: ConfigurationAppIntent())
SimpleEntry(lastThreeTask: Array(MissionDataModel.shared.model.prefix(3)))
}

func snapshot(for configuration: ConfigurationAppIntent, in context: Context) async -> SimpleEntry {
SimpleEntry(date: Date(), configuration: configuration)
SimpleEntry(lastThreeTask: Array(MissionDataModel.shared.model.prefix(3)))
}

func timeline(for configuration: ConfigurationAppIntent, in context: Context) async -> Timeline<SimpleEntry> {
var entries: [SimpleEntry] = []

let lastestTask = Array(MissionDataModel.shared.model.prefix(3))
let entries: [SimpleEntry] = [SimpleEntry(lastThreeTask: lastestTask)]
// 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: .hour, value: hourOffset, to: currentDate)!
let entry = SimpleEntry(date: entryDate, configuration: configuration)
entries.append(entry)
}

return Timeline(entries: entries, policy: .atEnd)
}
}

struct SimpleEntry: TimelineEntry {
let date: Date
let configuration: ConfigurationAppIntent
let date: Date = .now
var lastThreeTask: [MissionModel]
}

struct Widget_NOTTODOEntryView : View {
struct Widget_NOTTODOEntryView: View {
@Environment(\.widgetFamily) var family: WidgetFamily
var entry: Provider.Entry


@ViewBuilder
var body: some View {
VStack {
Text("Time:")
Text(entry.date, style: .time)

Text("Favorite Emoji:")
Text(entry.configuration.favoriteEmoji)
switch self.family {
case .systemSmall:
SmallFamily(entry: SimpleEntry(lastThreeTask: MissionDataModel.shared.model))
default:
MediumFamily(entry: SimpleEntry(lastThreeTask: []))
}
}

}

struct Widget_NOTTODO: Widget {
Expand All @@ -59,26 +55,22 @@ struct Widget_NOTTODO: Widget {
Widget_NOTTODOEntryView(entry: entry)
.containerBackground(.fill.tertiary, for: .widget)
}
.configurationDisplayName("낫투두 위젯")
.description("낫투두 위젯입니다.")
.contentMarginsDisabled()
.supportedFamilies([.systemSmall, .systemMedium])
}
}

extension ConfigurationAppIntent {
fileprivate static var smiley: ConfigurationAppIntent {
let intent = ConfigurationAppIntent()
intent.favoriteEmoji = "😀"
return intent
}

fileprivate static var starEyes: ConfigurationAppIntent {
let intent = ConfigurationAppIntent()
intent.favoriteEmoji = "🤩"
return intent
}
}

#Preview(as: .systemSmall) {
#Preview(as: .systemMedium) {
Widget_NOTTODO()
} timeline: {
SimpleEntry(date: .now, configuration: .smiley)
SimpleEntry(date: .now, configuration: .starEyes)
SimpleEntry(lastThreeTask: MissionDataModel.shared.model)
}
Loading

0 comments on commit 65ac534

Please sign in to comment.