Skip to content

Commit

Permalink
Merge pull request #6666 from vector-im/aringenbach/6442_fix_ios_16_m…
Browse files Browse the repository at this point in the history
…ention_pills

Fix mention pills display on iOS 16
  • Loading branch information
aringenbach committed Sep 2, 2022
2 parents a87eb94 + 516712f commit b0dd477
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 0 deletions.
29 changes: 29 additions & 0 deletions Riot/Categories/UITextView.swift
Original file line number Diff line number Diff line change
@@ -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)
}
}
}
6 changes: 6 additions & 0 deletions Riot/Modules/MatrixKit/Views/MXKMessageTextView.m
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions Riot/Modules/Room/Views/InputToolbar/RoomInputToolbarView.m
Original file line number Diff line number Diff line change
Expand Up @@ -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];
}
Expand Down
1 change: 1 addition & 0 deletions RiotShareExtension/target.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions changelog.d/6442.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix mention pills display on iOS 16

0 comments on commit b0dd477

Please sign in to comment.