Files
Pulse/Sources/PulseUI/Features/Console/ConsoleMessageView.swift
T
2022-07-18 17:11:56 -04:00

85 lines
1.9 KiB
Swift
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// The MIT License (MIT)
//
// Copyright (c) 20202022 Alexander Grebenyuk (github.com/kean).
import SwiftUI
import PulseCore
import CoreData
import Combine
#if os(watchOS) || os(tvOS) || os(macOS)
struct ConsoleMessageView: View {
let viewModel: ConsoleMessageViewModel
var body: some View {
VStack(alignment: .leading, spacing: 4) {
HStack(alignment: .firstTextBaseline) {
title
#if os(watchOS)
Spacer()
PinView(viewModel: viewModel.pinViewModel, font: fonts.title)
#else
PinView(viewModel: viewModel.pinViewModel, font: fonts.title)
Spacer()
#endif
}
text
}
.padding(.vertical, 4)
}
private var title: some View {
badge + Text(viewModel.title)
.font(fonts.title)
.foregroundColor(.secondary)
}
private var badge: Text {
guard let badge = viewModel.badge else {
return Text("")
}
var separator: Text {
#if os(watchOS)
return Text("\n")
#else
return Text(" · ")
.font(fonts.title)
.foregroundColor(.secondary)
#endif
}
return Text(badge.title)
.font(fonts.title)
.foregroundColor(badge.color)
+ separator
}
private var pin: some View {
Image(systemName: "pin")
.font(fonts.title)
.foregroundColor(.secondary)
}
private var text: some View {
Text(viewModel.text)
.font(fonts.body)
.foregroundColor(viewModel.textColor)
.lineLimit(4)
}
private struct Fonts {
let title: Font
let body: Font
}
private var fonts: Fonts {
#if os(watchOS)
return Fonts(title: .system(size: 12), body: .system(size: 15))
#else
return Fonts(title: .body, body: .body)
#endif
}
}
#endif