NetNewsWire/Multiplatform/Shared/Timeline/TimelineItemView.swift

75 lines
2.0 KiB
Swift
Raw Normal View History

2020-07-01 18:13:11 +02:00
//
// TimelineItemView.swift
// NetNewsWire
//
// Created by Maurice Parker on 7/1/20.
// Copyright © 2020 Ranchero Software. All rights reserved.
//
import SwiftUI
struct TimelineItemView: View {
@EnvironmentObject var defaults: AppDefaults
2020-07-02 00:21:58 +02:00
@StateObject var articleIconImageLoader = ArticleIconImageLoader()
2020-07-01 18:13:11 +02:00
var timelineItem: TimelineItem
#if os(macOS)
var verticalPadding: CGFloat = 10
#endif
#if os(iOS)
var verticalPadding: CGFloat = 0
#endif
2020-07-01 18:13:11 +02:00
var body: some View {
2020-07-01 19:30:55 +02:00
VStack {
2020-07-01 23:33:07 +02:00
HStack(alignment: .top) {
TimelineItemStatusView(status: timelineItem.status)
2020-07-02 00:21:58 +02:00
if let image = articleIconImageLoader.image {
IconImageView(iconImage: image)
2020-07-03 08:24:35 +02:00
.frame(width: CGFloat(defaults.timelineIconDimensions), height: CGFloat(defaults.timelineIconDimensions), alignment: /*@START_MENU_TOKEN@*/.center/*@END_MENU_TOKEN@*/)
2020-07-02 00:21:58 +02:00
}
2020-07-02 00:39:27 +02:00
VStack {
Text(verbatim: timelineItem.article.title ?? "N/A")
.fontWeight(.semibold)
.lineLimit(defaults.timelineNumberOfLines)
2020-07-02 00:39:27 +02:00
.frame(maxWidth: .infinity, alignment: .leading)
.padding(.trailing, 4)
Spacer()
HStack {
Text(verbatim: timelineItem.byline)
.lineLimit(1)
.truncationMode(.tail)
2020-07-02 00:39:27 +02:00
.font(.footnote)
.foregroundColor(.secondary)
Spacer()
Text(verbatim: timelineItem.dateTimeString)
.lineLimit(1)
2020-07-02 00:39:27 +02:00
.font(.footnote)
.foregroundColor(.secondary)
.padding(.trailing, 4)
}
}
2020-07-01 23:33:07 +02:00
}
2020-07-01 19:30:55 +02:00
}
.padding(.vertical, verticalPadding)
2020-07-02 00:21:58 +02:00
.onAppear {
articleIconImageLoader.loadImage(for: timelineItem.article)
}
2020-07-01 18:13:11 +02:00
}
}
2020-07-01 23:33:07 +02:00
struct TimelineItemView_Previews: PreviewProvider {
static var previews: some View {
Group {
TimelineItemView(timelineItem: TimelineItem(article: PreviewArticles.basicRead))
.frame(maxWidth: 250)
TimelineItemView(timelineItem: TimelineItem(article: PreviewArticles.basicUnread))
.frame(maxWidth: 250)
TimelineItemView(timelineItem: TimelineItem(article: PreviewArticles.basicStarred))
.frame(maxWidth: 250)
}
}
}