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 {
|
|
|
|
|
2020-07-02 12:46:56 +02:00
|
|
|
@EnvironmentObject var defaults: AppDefaults
|
2020-07-02 00:21:58 +02:00
|
|
|
@StateObject var articleIconImageLoader = ArticleIconImageLoader()
|
2020-07-02 12:46:56 +02:00
|
|
|
|
2020-07-20 01:20:05 +02:00
|
|
|
var selected: Bool
|
2020-07-17 02:36:20 +02:00
|
|
|
var width: CGFloat
|
2020-07-01 18:13:11 +02:00
|
|
|
var timelineItem: TimelineItem
|
2020-07-03 19:21:08 +02:00
|
|
|
|
2020-07-27 17:24:32 +02:00
|
|
|
#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-17 02:36:20 +02:00
|
|
|
HStack(alignment: .top) {
|
2020-07-20 01:20:05 +02:00
|
|
|
TimelineItemStatusView(selected: selected, status: timelineItem.status)
|
2020-07-17 02:36:20 +02:00
|
|
|
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)
|
2020-07-02 00:42:44 +02:00
|
|
|
.fontWeight(.semibold)
|
2020-07-17 02:36:20 +02:00
|
|
|
.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)
|
2020-07-17 02:36:20 +02:00
|
|
|
.fixedSize(horizontal: false, vertical: true)
|
|
|
|
}
|
2020-07-20 04:13:24 +02:00
|
|
|
Spacer(minLength: 0)
|
2020-07-17 02:36:20 +02:00
|
|
|
HStack {
|
|
|
|
Text(verbatim: timelineItem.byline)
|
|
|
|
.lineLimit(1)
|
|
|
|
.truncationMode(.tail)
|
|
|
|
.font(.footnote)
|
|
|
|
.foregroundColor(.secondary)
|
2020-07-02 00:39:27 +02:00
|
|
|
Spacer()
|
2020-07-17 02:36:20 +02:00
|
|
|
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
|
|
|
}
|
2020-07-27 17:24:32 +02:00
|
|
|
.padding(.vertical, verticalPadding)
|
2020-07-02 00:21:58 +02:00
|
|
|
.onAppear {
|
|
|
|
articleIconImageLoader.loadImage(for: timelineItem.article)
|
|
|
|
}
|
2020-07-18 00:59:35 +02:00
|
|
|
.contextMenu {
|
|
|
|
TimelineContextMenu(timelineItem: timelineItem)
|
|
|
|
}
|
2020-07-01 18:13:11 +02:00
|
|
|
}
|
|
|
|
}
|