Implement (static) widget (IOS-37)
This commit is contained in:
parent
4adf58015c
commit
d1c6c5523a
@ -5,21 +5,44 @@ import SwiftUI
|
||||
|
||||
struct HashtagWidgetProvider: IntentTimelineProvider {
|
||||
func placeholder(in context: Context) -> HashtagWidgetTimelineEntry {
|
||||
.init(date: Date())
|
||||
.placeholder
|
||||
}
|
||||
|
||||
func getSnapshot(for configuration: Intent, in context: Context, completion: @escaping (HashtagWidgetTimelineEntry) -> Void) {
|
||||
//TODO: Implement
|
||||
func getSnapshot(for configuration: HashtagIntent, in context: Context, completion: @escaping (HashtagWidgetTimelineEntry) -> Void) {
|
||||
loadMostRecentHashtag(for: configuration, in: context, completion: completion)
|
||||
}
|
||||
|
||||
func getTimeline(for configuration: HashtagIntent, in context: Context, completion: @escaping (Timeline<HashtagWidgetTimelineEntry>) -> Void) {
|
||||
//TODO: Implement
|
||||
loadMostRecentHashtag(for: configuration, in: context) { entry in
|
||||
completion(Timeline(entries: [entry], policy: .after(.now)))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
extension HashtagWidgetProvider {
|
||||
func loadMostRecentHashtag(for configuration: HashtagIntent, in context: Context, completion: @escaping (HashtagWidgetTimelineEntry) -> Void ) {
|
||||
let hashtagTimelineEntry = HashtagWidgetTimelineEntry.placeholder
|
||||
completion(hashtagTimelineEntry)
|
||||
}
|
||||
}
|
||||
|
||||
struct HashtagWidgetTimelineEntry: TimelineEntry {
|
||||
var date: Date
|
||||
//TODO: implement, add relevant information
|
||||
var hashtag: HashtagEntry
|
||||
|
||||
static var placeholder: Self {
|
||||
HashtagWidgetTimelineEntry(
|
||||
date: .now,
|
||||
hashtag: HashtagEntry(
|
||||
accountName: "John Mastodon",
|
||||
account: "@johnmastodon@mastodon.social",
|
||||
content: "Caturday is the best day of the week #CatsOfMastodon",
|
||||
reblogCount: 13,
|
||||
favoriteCount: 12,
|
||||
hashtag: "#CatsOfMastodon")
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
struct HashtagWidget: Widget {
|
||||
@ -34,10 +57,19 @@ struct HashtagWidget: Widget {
|
||||
|
||||
var body: some WidgetConfiguration {
|
||||
IntentConfiguration(kind: "Hashtag", intent: HashtagIntent.self, provider: HashtagWidgetProvider()) { entry in
|
||||
HashtagWidgetView()
|
||||
HashtagWidgetView(entry: entry)
|
||||
}
|
||||
.configurationDisplayName("Hashtag")
|
||||
.description("Show a Hashtag")
|
||||
.supportedFamilies(availableFamilies)
|
||||
}
|
||||
}
|
||||
|
||||
struct HashtagEntry {
|
||||
var accountName: String
|
||||
var account: String
|
||||
var content: String
|
||||
var reblogCount: Int
|
||||
var favoriteCount: Int
|
||||
var hashtag: String
|
||||
}
|
||||
|
@ -3,21 +3,49 @@
|
||||
import SwiftUI
|
||||
|
||||
struct HashtagWidgetView: View {
|
||||
|
||||
var entry: HashtagWidgetProvider.Entry
|
||||
|
||||
var body: some View {
|
||||
//TODO: Lockscreen has a different design
|
||||
VStack {
|
||||
VStack(alignment: .leading, spacing: 0) {
|
||||
HStack {
|
||||
Text("Username")
|
||||
Text("@user@mastodon.social")
|
||||
Text(entry.hashtag.accountName)
|
||||
.font(.caption)
|
||||
.fontWeight(.semibold)
|
||||
.foregroundColor(.secondary)
|
||||
Text(entry.hashtag.account)
|
||||
.lineLimit(1)
|
||||
.font(.caption)
|
||||
.foregroundColor(.secondary)
|
||||
Text("18h") //TODO: Implement
|
||||
.font(.caption)
|
||||
.foregroundColor(.secondary)
|
||||
}
|
||||
Text("Toot")
|
||||
HStack {
|
||||
Image(systemName: "arrow.2.squarepath")
|
||||
Text("Reblog Count")
|
||||
Image(systemName: "star")
|
||||
Text("Star Count")
|
||||
Text("#Hashtag")
|
||||
|
||||
Text(entry.hashtag.content)
|
||||
Spacer()
|
||||
HStack(alignment: .center, spacing: 16) {
|
||||
HStack(spacing: 0) {
|
||||
Image(systemName: "arrow.2.squarepath")
|
||||
.foregroundColor(.secondary)
|
||||
Text("\(entry.hashtag.reblogCount)")
|
||||
.font(.caption)
|
||||
.foregroundColor(.secondary)
|
||||
}
|
||||
HStack(spacing: 0) {
|
||||
Image(systemName: "star")
|
||||
.foregroundColor(.secondary)
|
||||
Text("\(entry.hashtag.favoriteCount)")
|
||||
.font(.caption)
|
||||
.foregroundColor(.secondary)
|
||||
}
|
||||
Text(entry.hashtag.hashtag)
|
||||
.font(.caption)
|
||||
.fontWeight(.semibold)
|
||||
.foregroundColor(.secondary)
|
||||
}
|
||||
}
|
||||
.padding(EdgeInsets(top: 12, leading: 29, bottom: 12, trailing: 29))
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user