diff --git a/Riot/Modules/Home/HomeViewController.m b/Riot/Modules/Home/HomeViewController.m index f2b2ae96d..a24aa1206 100644 --- a/Riot/Modules/Home/HomeViewController.m +++ b/Riot/Modules/Home/HomeViewController.m @@ -673,12 +673,14 @@ - (UIContextMenuConfiguration *)collectionView:(UICollectionView *)collectionView contextMenuConfigurationForItemAtIndexPath:(NSIndexPath *)indexPath point:(CGPoint)point API_AVAILABLE(ios(13.0)) { + id cellData = [recentsDataSource cellDataAtIndexPath:[NSIndexPath indexPathForRow:indexPath.item inSection:collectionView.tag]]; MXRoom *room = [self.dataSource getRoomAtIndexPath:[NSIndexPath indexPathForRow:indexPath.row inSection:collectionView.tag]]; NSString *roomId = room.roomId; - return [UIContextMenuConfiguration configurationWithIdentifier:roomId - previewProvider:nil - actionProvider:^UIMenu * _Nullable(NSArray * _Nonnull suggestedActions) { + return [UIContextMenuConfiguration configurationWithIdentifier:roomId previewProvider:^UIViewController * _Nullable { + // Add a preview using the cell's data to prevent the avatar and displayname from changing with a room list update. + return [[RoomPreviewViewController alloc] initWithCellData:cellData]; + } actionProvider:^UIMenu * _Nullable(NSArray * _Nonnull suggestedActions) { MXWeakify(self); BOOL isDirect = room.isDirect; diff --git a/Riot/Modules/Home/RoomContextPreviewViewController.swift b/Riot/Modules/Home/RoomContextPreviewViewController.swift new file mode 100644 index 000000000..646f6bc2c --- /dev/null +++ b/Riot/Modules/Home/RoomContextPreviewViewController.swift @@ -0,0 +1,55 @@ +// +// Copyright 2021 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 + +/// A view controller that provides a preview of a room for use in context menus. +@objcMembers +class RoomPreviewViewController: UIViewController { + + // MARK: - Constants + private enum Constants { + static let size = CGSize(width: 80, height: 115) + } + + // MARK: - Private + + private var cellData: MXKCellData + + // MARK: - Setup + + init(cellData: MXKCellData) { + self.cellData = cellData + super.init(nibName: nil, bundle: nil) + } + + required init?(coder: NSCoder) { + fatalError("init(coder:) has not been implemented") + } + + // MARK: - Lifecyle + + override func viewDidLoad() { + super.viewDidLoad() + + let cell = RoomCollectionViewCell(frame: CGRect(origin: .zero, size: Constants.size)) + cell.render(cellData) + view.vc_addSubViewMatchingParent(cell) + + preferredContentSize = Constants.size + } + +} diff --git a/Riot/SupportingFiles/Riot-Bridging-Header.h b/Riot/SupportingFiles/Riot-Bridging-Header.h index 165321909..e8df17d7f 100644 --- a/Riot/SupportingFiles/Riot-Bridging-Header.h +++ b/Riot/SupportingFiles/Riot-Bridging-Header.h @@ -50,6 +50,7 @@ #import "PlainRoomTimelineCellProvider.h" #import "BubbleRoomTimelineCellProvider.h" #import "RoomSelectedStickerBubbleCell.h" +#import "RoomCollectionViewCell.h" // MatrixKit common imports, shared with all targets #import "MatrixKit-Bridging-Header.h" diff --git a/changelog.d/4883.bugfix b/changelog.d/4883.bugfix index 86b8bb879..99989d18a 100644 --- a/changelog.d/4883.bugfix +++ b/changelog.d/4883.bugfix @@ -1 +1 @@ -Fix bugs when building with Xcode 13: bar appearance / header padding / space avatar content size \ No newline at end of file +Fix bugs when building with Xcode 13: bar appearance / header padding / space avatar content size. Additionally, use UIKit context menus on the home screen. \ No newline at end of file