NetNewsWire/Multiplatform/Shared/Timeline/TimelineItemView.swift

75 lines
2.1 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()
var width: CGFloat
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 {
HStack(alignment: .top) {
TimelineItemStatusView(status: timelineItem.status)
if let image = articleIconImageLoader.image {
IconImageView(iconImage: image)
.frame(width: CGFloat(defaults.timelineIconDimensions), height: CGFloat(defaults.timelineIconDimensions), alignment: /*@START_MENU_TOKEN@*/.center/*@END_MENU_TOKEN@*/)
}
VStack {
let titleLines = timelineItem.numberOfTitleLines(width: width)
if titleLines > 0 {
Text(verbatim: timelineItem.truncatedTitle)
.fontWeight(.semibold)
.lineLimit(titleLines)
.frame(maxWidth: .infinity, alignment: .leading)
.padding(.trailing, 4)
.fixedSize(horizontal: false, vertical: true)
}
let summaryLines = timelineItem.numberOfSummaryLines(width: width, titleLines: titleLines)
if summaryLines > 0 {
Text(verbatim: timelineItem.truncatedSummary)
.lineLimit(summaryLines)
2020-07-02 00:39:27 +02:00
.frame(maxWidth: .infinity, alignment: .leading)
.padding(.trailing, 4)
.fixedSize(horizontal: false, vertical: true)
}
HStack {
Text(verbatim: timelineItem.byline)
.lineLimit(1)
.truncationMode(.tail)
.font(.footnote)
.foregroundColor(.secondary)
2020-07-02 00:39:27 +02:00
Spacer()
Text(verbatim: timelineItem.dateTimeString)
.lineLimit(1)
.font(.footnote)
.foregroundColor(.secondary)
.padding(.trailing, 4)
2020-07-02 00:39:27 +02:00
}
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)
}
.contextMenu {
TimelineContextMenu(timelineItem: timelineItem)
}
2020-07-01 18:13:11 +02:00
}
}