#if os(iOS) import SwiftUI import UIKit /// UIKit supplies character wrapping without inserting characters into the /// log, so selection and copying preserve the exact stored text. struct WrappingLogText: UIViewRepresentable { let text: String func makeUIView(context: Context) -> UITextView { let view = UITextView() view.isEditable = false view.isSelectable = true view.isScrollEnabled = false view.backgroundColor = .clear view.textContainerInset = .zero view.textContainer.lineFragmentPadding = 0 view.textContainer.lineBreakMode = .byCharWrapping view.adjustsFontForContentSizeCategory = true return view } func updateUIView(_ view: UITextView, context: Context) { view.text = text view.textColor = .label view.font = UIFontMetrics(forTextStyle: .caption1).scaledFont(for: .monospacedSystemFont(ofSize: 12, weight: .regular)) } func sizeThatFits(_ proposal: ProposedViewSize, uiView: UITextView, context: Context) -> CGSize? { guard let width = proposal.width else { return nil } return uiView.sizeThatFits(CGSize(width: width, height: .greatestFiniteMagnitude)) } } #endif