diff --git a/Sources/PulseUI/Features/FileViewer/RichTextView/RichTextView-tvOS.swift b/Sources/PulseUI/Features/FileViewer/RichTextView/RichTextView-tvOS.swift new file mode 100644 index 000000000..d8a0c6561 --- /dev/null +++ b/Sources/PulseUI/Features/FileViewer/RichTextView/RichTextView-tvOS.swift @@ -0,0 +1,58 @@ +// +// RichTextView-tvOS.swift +// Pulse +// +// Created by seunghwan Lee on 12/1/24. +// + +#if os(tvOS) +import UIKit +import SwiftUI +import Pulse + +struct ScrollableTextView: UIViewRepresentable { + var text: String? + var attributedText: NSAttributedString? + + init(text: String? = nil, attributedText: AttributedString? = nil) { + self.text = text + if let attributedText { + self.attributedText = NSAttributedString(attributedText) + } + } + + func makeUIView(context: UIViewRepresentableContext) -> UITextView { + let textView = UITextView() + textView.isScrollEnabled = true + textView.isUserInteractionEnabled = true + textView.panGestureRecognizer.allowedTouchTypes = [NSNumber(value: UITouch.TouchType.indirect.rawValue)] + textView.bounces = true + textView.contentInsetAdjustmentBehavior = .never + textView.insetsLayoutMarginsFromSafeArea = false + textView.showsVerticalScrollIndicator = true + textView.showsHorizontalScrollIndicator = false + textView.indicatorStyle = .white + return textView + } + + func updateUIView(_ uiView: UITextView, context: UIViewRepresentableContext) { + if let attributedText { + uiView.attributedText = attributedText + } else if let text { + uiView.text = text + } + } +} + +struct RichTextView: View { + let viewModel: RichTextViewModel + + var body: some View { + if let attributedText = viewModel.attributedString { + ScrollableTextView(attributedText: attributedText) + } else { + ScrollableTextView(text: viewModel.text) + } + } +} +#endif diff --git a/Sources/PulseUI/Features/FileViewer/RichTextView/RichTextView-watchos.swift b/Sources/PulseUI/Features/FileViewer/RichTextView/RichTextView-watchos.swift index c1032f823..f35c61473 100644 --- a/Sources/PulseUI/Features/FileViewer/RichTextView/RichTextView-watchos.swift +++ b/Sources/PulseUI/Features/FileViewer/RichTextView/RichTextView-watchos.swift @@ -5,8 +5,7 @@ import SwiftUI import Pulse -#if os(watchOS) || os(tvOS) || os(macOS) - +#if os(watchOS) || os(macOS) struct RichTextView: View { let viewModel: RichTextViewModel @@ -27,6 +26,7 @@ struct RichTextView: View { #endif } } +#endif final class RichTextViewModel: ObservableObject { let text: String @@ -49,5 +49,3 @@ final class RichTextViewModel: ObservableObject { self.text = string.string } } - -#endif