diff --git a/Riot/Categories/UITextView.swift b/Riot/Categories/UITextView.swift new file mode 100644 index 0000000000..56b19047ab --- /dev/null +++ b/Riot/Categories/UITextView.swift @@ -0,0 +1,29 @@ +// +// Copyright 2022 New Vector Ltd +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +import UIKit + +extension UITextView { + /// Invalidates display for all text attachment inside the text view. + @objc func vc_invalidateTextAttachmentsDisplay() { + self.attributedText.enumerateAttribute( + .attachment, + in: NSRange(location: 0, length: self.attributedText.length), + options: []) { _, range, _ in + self.layoutManager.invalidateDisplay(forCharacterRange: range) + } + } +} diff --git a/Riot/Modules/MatrixKit/Views/MXKMessageTextView.m b/Riot/Modules/MatrixKit/Views/MXKMessageTextView.m index 219816214d..74132c23f0 100644 --- a/Riot/Modules/MatrixKit/Views/MXKMessageTextView.m +++ b/Riot/Modules/MatrixKit/Views/MXKMessageTextView.m @@ -71,6 +71,12 @@ - (void)setAttributedText:(NSAttributedString *)attributedText [self flushPills]; } [super setAttributedText:attributedText]; + + if (@available(iOS 15.0, *)) { + // Fixes an iOS 16 issue where attachment are not drawn properly by + // forcing the layoutManager to redraw the glyphs at all NSAttachment positions. + [self vc_invalidateTextAttachmentsDisplay]; + } } - (void)registerPillView:(UIView *)pillView diff --git a/Riot/Modules/Room/Views/InputToolbar/RoomInputToolbarView.m b/Riot/Modules/Room/Views/InputToolbar/RoomInputToolbarView.m index cd57bd0edd..1aa20adf94 100644 --- a/Riot/Modules/Room/Views/InputToolbar/RoomInputToolbarView.m +++ b/Riot/Modules/Room/Views/InputToolbar/RoomInputToolbarView.m @@ -173,6 +173,13 @@ - (void)setAttributedTextMessage:(NSAttributedString *)attributedTextMessage } self.textView.attributedText = attributedTextMessage; + + if (@available(iOS 15.0, *)) { + // Fixes an iOS 16 issue where attachment are not drawn properly by + // forcing the layoutManager to redraw the glyphs at all NSAttachment positions. + [self.textView vc_invalidateTextAttachmentsDisplay]; + } + [self updateUIWithAttributedTextMessage:attributedTextMessage animated:YES]; [self textViewDidChange:self.textView]; } diff --git a/RiotShareExtension/target.yml b/RiotShareExtension/target.yml index bf2a032f59..29dfe514df 100644 --- a/RiotShareExtension/target.yml +++ b/RiotShareExtension/target.yml @@ -57,6 +57,7 @@ targets: - path: ../Riot/Categories/UISearchBar.swift - path: ../Riot/Categories/String.swift - path: ../Riot/Categories/UIView.swift + - path: ../Riot/Categories/UITextView.swift - path: ../Riot/Modules/Common/Recents/Model/RecentCellData.m - path: ../Riot/PropertyWrappers/UserDefaultsBackedPropertyWrapper.swift - path: ../Riot/Generated/Strings.swift diff --git a/changelog.d/6442.bugfix b/changelog.d/6442.bugfix new file mode 100644 index 0000000000..f0ca643fef --- /dev/null +++ b/changelog.d/6442.bugfix @@ -0,0 +1 @@ +Fix mention pills display on iOS 16