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.
This commit is contained in:
Igor Solomennikov 2022-08-30 10:36:41 -07:00 committed by GitHub
parent f8f17e0770
commit b5ee24febe
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 3 additions and 8 deletions

View File

@ -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)

View File

@ -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