From 3e93ced674b2a11da11d6f2ec59fd09245cc6ad1 Mon Sep 17 00:00:00 2001 From: Justin Mazzocchi <2831158+jzzocc@users.noreply.github.com> Date: Thu, 5 May 2022 19:29:05 -0700 Subject: [PATCH] Fix emoji position on iOS 15 --- Views/UIKit/AnimatedAttachmentLabel.swift | 26 ++++++++++++++--------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/Views/UIKit/AnimatedAttachmentLabel.swift b/Views/UIKit/AnimatedAttachmentLabel.swift index 91402d9..86f6907 100644 --- a/Views/UIKit/AnimatedAttachmentLabel.swift +++ b/Views/UIKit/AnimatedAttachmentLabel.swift @@ -24,20 +24,26 @@ final class AnimatedAttachmentLabel: UILabel, EmojiInsertable { .attachment, in: NSRange(location: 0, length: attributedText.length), options: .longestEffectiveRangeNotRequired) { attachment, _, _ in - guard let animatedAttachment = attachment as? AnimatedTextAttachment, - let imageBounds = animatedAttachment.imageBounds - else { return } + guard let animatedAttachment = attachment as? AnimatedTextAttachment, + let imageBounds = animatedAttachment.imageBounds + else { return } - animatedAttachment.imageView.frame = imageBounds - animatedAttachment.imageView.contentMode = .scaleAspectFit + animatedAttachment.imageView.frame = imageBounds - if animatedAttachment.imageView.superview != self { - addSubview(animatedAttachment.imageView) + // iOS 15 needs this for some inexplicable reason + if #available(iOS 15, *) { + animatedAttachment.imageView.frame.origin.y -= font.lineHeight + } + + animatedAttachment.imageView.contentMode = .scaleAspectFit + + if animatedAttachment.imageView.superview != self { + addSubview(animatedAttachment.imageView) + } + + attachmentImageViews.insert(animatedAttachment.imageView) } - attachmentImageViews.insert(animatedAttachment.imageView) - } - for subview in subviews { guard let attachmentImageView = subview as? SDAnimatedImageView else { continue }