From 178094fd0f5e85724b0b0545c15bea325bda0079 Mon Sep 17 00:00:00 2001 From: Georg Bauer Date: Fri, 31 Jul 2026 11:48:45 +0200 Subject: [PATCH] Fix source view rendering while scrolling --- ios/Sources/DetailScreens.swift | 34 ++++++++++++++++++++------------- 1 file changed, 21 insertions(+), 13 deletions(-) diff --git a/ios/Sources/DetailScreens.swift b/ios/Sources/DetailScreens.swift index 5c6ec49..06f8e7a 100644 --- a/ios/Sources/DetailScreens.swift +++ b/ios/Sources/DetailScreens.swift @@ -343,6 +343,7 @@ final class RepositoryFileViewController: UIViewController, QLPreviewControllerD private let spinner = UIActivityIndicatorView(style: .medium) private var loadingTask: Task? private var previewURL: URL? + private weak var sourceScrollView: UIScrollView? private weak var sourceTextView: UITextView? init(context: AppContext, owner: String, repository: String, path: String) { @@ -382,7 +383,7 @@ final class RepositoryFileViewController: UIViewController, QLPreviewControllerD override func viewDidLayoutSubviews() { super.viewDidLayoutSubviews() - updateSourceContentSize() + updateSourceLayout() } private func isMediaFile(_ path: String) -> Bool { @@ -424,7 +425,13 @@ final class RepositoryFileViewController: UIViewController, QLPreviewControllerD paragraph.lineBreakMode = .byClipping text.addAttribute(.paragraphStyle, value: paragraph, range: NSRange(location: 0, length: text.length)) - let textView = UITextView(frame: view.bounds) + let scrollView = UIScrollView(frame: view.bounds) + scrollView.autoresizingMask = [.flexibleWidth, .flexibleHeight] + scrollView.alwaysBounceHorizontal = true + scrollView.isDirectionalLockEnabled = true + scrollView.showsHorizontalScrollIndicator = true + + let textView = UITextView(frame: .zero) textView.textContainer.size = CGSize( width: CGFloat.greatestFiniteMagnitude, height: CGFloat.greatestFiniteMagnitude @@ -432,19 +439,18 @@ final class RepositoryFileViewController: UIViewController, QLPreviewControllerD textView.textContainer.lineBreakMode = .byClipping textView.textContainer.widthTracksTextView = false textView.textStorage.setAttributedString(text) - textView.autoresizingMask = [.flexibleWidth, .flexibleHeight] textView.isEditable = false + textView.isScrollEnabled = false textView.isSelectable = true - textView.alwaysBounceHorizontal = true - textView.isDirectionalLockEnabled = true - textView.showsHorizontalScrollIndicator = true + sourceScrollView = scrollView sourceTextView = textView - view.addSubview(textView) - updateSourceContentSize() + scrollView.addSubview(textView) + view.addSubview(scrollView) + updateSourceLayout() } - private func updateSourceContentSize() { - guard let textView = sourceTextView else { return } + private func updateSourceLayout() { + guard let scrollView = sourceScrollView, let textView = sourceTextView else { return } textView.textContainer.widthTracksTextView = false textView.textContainer.size = CGSize( width: CGFloat.greatestFiniteMagnitude, @@ -452,16 +458,18 @@ final class RepositoryFileViewController: UIViewController, QLPreviewControllerD ) textView.layoutManager.ensureLayout(for: textView.textContainer) let textSize = textView.layoutManager.usedRect(for: textView.textContainer).size - textView.contentSize = CGSize( + let contentSize = CGSize( width: max( - textView.bounds.width, + scrollView.bounds.width, ceil(textSize.width + textView.textContainerInset.left + textView.textContainerInset.right) ), height: max( - textView.bounds.height, + scrollView.bounds.height, ceil(textSize.height + textView.textContainerInset.top + textView.textContainerInset.bottom) ) ) + textView.frame = CGRect(origin: .zero, size: contentSize) + scrollView.contentSize = contentSize } private func showQuickLook(_ data: Data) throws {