From b5ee24febe0339ccdb01e9a590b79596caa59f69 Mon Sep 17 00:00:00 2001 From: Igor Solomennikov Date: Tue, 30 Aug 2022 10:36:41 -0700 Subject: [PATCH] Fix an issue causing incorrect line wraps in media editor's text overlays. When calculating layout size of the photo overlay text max width is capped at how wide UITextView was during editing, with the purpose of preserving wrapping between editor (UITextView) and overlay (CATextLayer). Previously though, UITextView was set to auto-shrink its width to content size, which caused max width to not be not enough after changing the font to a bolder variant. The fix is to pin UITextView's width to view margins so that all available width is always used when measuring text overlay height. --- SignalUI/Views/ImageEditor/ImageEditorCanvasView.swift | 7 +------ .../Views/ImageEditor/ImageEditorViewController+Text.swift | 4 ++-- 2 files changed, 3 insertions(+), 8 deletions(-) diff --git a/SignalUI/Views/ImageEditor/ImageEditorCanvasView.swift b/SignalUI/Views/ImageEditor/ImageEditorCanvasView.swift index ffbf499878..5fcf68872b 100644 --- a/SignalUI/Views/ImageEditor/ImageEditorCanvasView.swift +++ b/SignalUI/Views/ImageEditor/ImageEditorCanvasView.swift @@ -799,12 +799,7 @@ class ImageEditorCanvasView: AttachmentPrepContentView { // * Model transform (so that text doesn't become blurry as you zoom the content). layer.contentsScale = UIScreen.main.scale * item.scaling * transform.scaling - // TODO: Min with measured width. - let maxWidth = imageFrame.size.width * item.unitWidth - - let maxSize = CGSize(width: maxWidth, height: CGFloat.greatestFiniteMagnitude) - // TODO: Is there a more accurate way to measure text in a CATextLayer? - // CoreText? + let maxSize = CGSize(width: imageFrame.size.width * item.unitWidth, height: CGFloat.greatestFiniteMagnitude) let textBounds = attributedString.boundingRect(with: maxSize, options: [ .usesLineFragmentOrigin, .usesFontLeading ], context: nil) diff --git a/SignalUI/Views/ImageEditor/ImageEditorViewController+Text.swift b/SignalUI/Views/ImageEditor/ImageEditorViewController+Text.swift index 925c7e082c..580cafe49c 100644 --- a/SignalUI/Views/ImageEditor/ImageEditorViewController+Text.swift +++ b/SignalUI/Views/ImageEditor/ImageEditorViewController+Text.swift @@ -52,8 +52,8 @@ extension ImageEditorViewController { textContainerBackground.autoPinEdge(toSuperviewEdge: .bottom, withInset: -300) textViewContainer.addSubview(textView) - textView.autoCenterInSuperview() - textView.autoPinWidthToSuperviewMargins(relation: .lessThanOrEqual) + textView.autoVCenterInSuperview() + textView.autoPinWidthToSuperviewMargins() textView.autoPinHeightToSuperviewMargins(relation: .lessThanOrEqual) textView.widthAnchor.constraint(greaterThanOrEqualToConstant: 40).isActive = true