mirror of
https://github.com/kean/Pulse.git
synced 2026-05-30 21:07:33 +00:00
50 lines
1.1 KiB
Swift
50 lines
1.1 KiB
Swift
// The MIT License (MIT)
|
|
//
|
|
// Copyright (c) 2020-2024 Alexander Grebenyuk (github.com/kean).
|
|
|
|
import SwiftUI
|
|
import Pulse
|
|
|
|
#if os(watchOS) || os(tvOS)
|
|
|
|
struct RichTextView: View {
|
|
let viewModel: RichTextViewModel
|
|
|
|
var body: some View {
|
|
ScrollView {
|
|
if let string = viewModel.attributedString {
|
|
Text(string)
|
|
} else {
|
|
Text(viewModel.text)
|
|
}
|
|
}
|
|
#if os(watchOS)
|
|
.toolbar {
|
|
if #available(watchOS 9.0, *) {
|
|
ShareLink(item: viewModel.text)
|
|
}
|
|
}
|
|
#endif
|
|
}
|
|
}
|
|
|
|
final class RichTextViewModel: ObservableObject {
|
|
let text: String
|
|
let attributedString: AttributedString?
|
|
|
|
var isLinkDetectionEnabled = true
|
|
var isEmpty: Bool { text.isEmpty }
|
|
|
|
init(string: String) {
|
|
self.text = string
|
|
self.attributedString = nil
|
|
}
|
|
|
|
init(string: NSAttributedString, contentType: NetworkLogger.ContentType? = nil) {
|
|
self.attributedString = try? AttributedString(string, including: \.uiKit)
|
|
self.text = string.string
|
|
}
|
|
}
|
|
|
|
#endif
|