mirror of
https://github.com/vector-im/element-ios.git
synced 2024-09-28 23:32:41 +00:00
Add a preview provider to the context menu.
This commit is contained in:
parent
50de0dc36c
commit
26e30bedf7
4 changed files with 62 additions and 4 deletions
|
@ -673,12 +673,14 @@
|
|||
|
||||
- (UIContextMenuConfiguration *)collectionView:(UICollectionView *)collectionView contextMenuConfigurationForItemAtIndexPath:(NSIndexPath *)indexPath point:(CGPoint)point API_AVAILABLE(ios(13.0))
|
||||
{
|
||||
id<MXKRecentCellDataStoring> 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<UIMenuElement *> * _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<UIMenuElement *> * _Nonnull suggestedActions) {
|
||||
MXWeakify(self);
|
||||
|
||||
BOOL isDirect = room.isDirect;
|
||||
|
|
55
Riot/Modules/Home/RoomContextPreviewViewController.swift
Normal file
55
Riot/Modules/Home/RoomContextPreviewViewController.swift
Normal file
|
@ -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
|
||||
}
|
||||
|
||||
}
|
|
@ -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"
|
||||
|
|
|
@ -1 +1 @@
|
|||
Fix bugs when building with Xcode 13: bar appearance / header padding / space avatar content size
|
||||
Fix bugs when building with Xcode 13: bar appearance / header padding / space avatar content size. Additionally, use UIKit context menus on the home screen.
|
Loading…
Reference in a new issue