Skip to content

Commit

Permalink
Implement the new Space selector bottom sheet #6410
Browse files Browse the repository at this point in the history
- update after code review
  • Loading branch information
gileluard committed Aug 4, 2022
1 parent 6b82b00 commit f573a69
Show file tree
Hide file tree
Showing 17 changed files with 52 additions and 219 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"version" : 1
},
"properties" : {
"preserves-vector-representation" : true,
"template-rendering-intent" : "template"
}
}
165 changes: 0 additions & 165 deletions Riot/Modules/Common/Recents/RecentsViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -1118,171 +1118,6 @@ - (void)dataSource:(MXKDataSource *)dataSource didCellChange:(id)changes

#pragma mark - Swipe actions

- (void)tableView:(UITableView*)tableView didEndEditingRowAtIndexPath:(NSIndexPath *)indexPath
{
[self cancelEditionMode:isRefreshPending];
}

- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath
{
return UITableViewCellEditingStyleNone;
}

- (nullable UISwipeActionsConfiguration *)tableView:(UITableView *)tableView trailingSwipeActionsConfigurationForRowAtIndexPath:(NSIndexPath *)indexPath
{
if (BuildSettings.newAppLayoutEnabled)
{
return nil;
}

MXRoom *room = [self.dataSource getRoomAtIndexPath:indexPath];

if (!room)
{
return nil;
}

// Display no action for the invited room
if (room.summary.membership == MXMembershipInvite)
{
return nil;
}

// Store the identifier of the room related to the edited cell.
editedRoomId = room.roomId;

UIColor *selectedColor = ThemeService.shared.theme.tintColor;
UIColor *unselectedColor = ThemeService.shared.theme.tabBarUnselectedItemTintColor;
UIColor *actionBackgroundColor = ThemeService.shared.theme.baseColor;

NSString* title = @" ";

// Direct chat toggle

BOOL isDirect = room.isDirect;

UIContextualAction *directChatAction = [UIContextualAction contextualActionWithStyle:UIContextualActionStyleDestructive
title:title
handler:^(UIContextualAction * _Nonnull action, __kindof UIView * _Nonnull sourceView, void (^ _Nonnull completionHandler)(BOOL)) {
[self makeDirectEditedRoom:!isDirect];
completionHandler(YES);
}];
directChatAction.backgroundColor = actionBackgroundColor;

UIImage *directChatImage = AssetImages.roomActionDirectChat.image;
directChatImage = [directChatImage vc_tintedImageUsingColor:isDirect ? selectedColor : unselectedColor];
directChatAction.image = [directChatImage vc_notRenderedImage];

// Notification toggle

BOOL isMuted = room.isMute || room.isMentionsOnly;

UIContextualAction *muteAction = [UIContextualAction contextualActionWithStyle:UIContextualActionStyleDestructive
title:title
handler:^(UIContextualAction * _Nonnull action, __kindof UIView * _Nonnull sourceView, void (^ _Nonnull completionHandler)(BOOL)) {

if ([BuildSettings showNotificationsV2])
{
[self changeEditedRoomNotificationSettings];
}
else
{
[self muteEditedRoomNotifications:!isMuted];
}


completionHandler(YES);
}];
muteAction.backgroundColor = actionBackgroundColor;

UIImage *notificationImage;
if([BuildSettings showNotificationsV2] && isMuted)
{
notificationImage = AssetImages.roomActionNotificationMuted.image;
}
else
{
notificationImage = AssetImages.roomActionNotification.image;
}

notificationImage = [notificationImage vc_tintedImageUsingColor:isMuted ? unselectedColor : selectedColor];
muteAction.image = [notificationImage vc_notRenderedImage];

// Favorites management

MXRoomTag* currentTag = nil;

// Get the room tag (use only the first one).
if (room.accountData.tags)
{
NSArray<MXRoomTag*>* tags = room.accountData.tags.allValues;
if (tags.count)
{
currentTag = tags[0];
}
}

BOOL isFavourite = (currentTag && [kMXRoomTagFavourite isEqualToString:currentTag.name]);

UIContextualAction *favouriteAction = [UIContextualAction contextualActionWithStyle:UIContextualActionStyleDestructive
title:title
handler:^(UIContextualAction * _Nonnull action, __kindof UIView * _Nonnull sourceView, void (^ _Nonnull completionHandler)(BOOL)) {
NSString *favouriteTag = isFavourite ? nil : kMXRoomTagFavourite;
[self updateEditedRoomTag:favouriteTag];
completionHandler(YES);
}];
favouriteAction.backgroundColor = actionBackgroundColor;

UIImage *favouriteImage = AssetImages.roomActionFavourite.image;
favouriteImage = [favouriteImage vc_tintedImageUsingColor:isFavourite ? selectedColor : unselectedColor];
favouriteAction.image = [favouriteImage vc_notRenderedImage];

// Priority toggle

BOOL isInLowPriority = (currentTag && [kMXRoomTagLowPriority isEqualToString:currentTag.name]);

UIContextualAction *priorityAction = [UIContextualAction contextualActionWithStyle:UIContextualActionStyleDestructive
title:title
handler:^(UIContextualAction * _Nonnull action, __kindof UIView * _Nonnull sourceView, void (^ _Nonnull completionHandler)(BOOL)) {
NSString *priorityTag = isInLowPriority ? nil : kMXRoomTagLowPriority;
[self updateEditedRoomTag:priorityTag];
completionHandler(YES);
}];
priorityAction.backgroundColor = actionBackgroundColor;

UIImage *priorityImage = isInLowPriority ? AssetImages.roomActionPriorityHigh.image : AssetImages.roomActionPriorityLow.image;
priorityImage = [priorityImage vc_tintedImageUsingColor:unselectedColor];
priorityAction.image = [priorityImage vc_notRenderedImage];

// Leave action

UIContextualAction *leaveAction = [UIContextualAction contextualActionWithStyle:UIContextualActionStyleDestructive
title:title
handler:^(UIContextualAction * _Nonnull action, __kindof UIView * _Nonnull sourceView, void (^ _Nonnull completionHandler)(BOOL)) {
[self leaveEditedRoom];
completionHandler(YES);
}];
leaveAction.backgroundColor = actionBackgroundColor;

UIImage *leaveImage = AssetImages.roomActionLeave.image;
leaveImage = [leaveImage vc_tintedImageUsingColor:unselectedColor];
leaveAction.image = [leaveImage vc_notRenderedImage];

// Create swipe action configuration

NSArray<UIContextualAction*> *actions = @[
leaveAction,
priorityAction,
favouriteAction,
muteAction,
directChatAction
];

UISwipeActionsConfiguration *swipeActionConfiguration = [UISwipeActionsConfiguration configurationWithActions:actions];
swipeActionConfiguration.performsFirstActionWithFullSwipe = NO;
return swipeActionConfiguration;
}

- (void)leaveEditedRoom
{
if (editedRoomId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ enum AllChatsEditActionProviderOption {
}

protocol AllChatsEditActionProviderDelegate: AnyObject {
func allChatsEditActionProvider(_ ationProvider: AllChatsEditActionProvider, didSelect option: AllChatsEditActionProviderOption)
func allChatsEditActionProvider(_ actionProvider: AllChatsEditActionProvider, didSelect option: AllChatsEditActionProviderOption)
}

/// `AllChatsEditActionProvider` provides the menu for accessing edit screens according to the current parent space
Expand Down Expand Up @@ -111,8 +111,7 @@ class AllChatsEditActionProvider {

private var exploreRoomsAction: UIAction {
UIAction(title: VectorL10n.spacesExploreRooms,
image: parentSpace == nil ? UIImage(systemName: "list.bullet") : UIImage(systemName: "square.fill.text.grid.1x2"),
discoverabilityTitle: VectorL10n.spacesExploreRooms) { [weak self] action in
image: parentSpace == nil ? UIImage(systemName: "list.bullet") : UIImage(systemName: "square.fill.text.grid.1x2")) { [weak self] action in
guard let self = self else { return }

self.delegate?.allChatsEditActionProvider(self, didSelect: .exploreRooms)
Expand All @@ -122,7 +121,6 @@ class AllChatsEditActionProvider {
private var createRoomAction: UIAction {
UIAction(title: parentSpace == nil ? VectorL10n.roomRecentsCreateEmptyRoom : VectorL10n.spacesAddRoom,
image: UIImage(systemName: "number"),
discoverabilityTitle: VectorL10n.roomRecentsCreateEmptyRoom,
attributes: isAddRoomAvailable ? [] : .disabled) { [weak self] action in
guard let self = self else { return }

Expand All @@ -132,8 +130,7 @@ class AllChatsEditActionProvider {

private var startChatAction: UIAction {
UIAction(title: VectorL10n.roomRecentsStartChatWith,
image: UIImage(systemName: "person"),
discoverabilityTitle: VectorL10n.roomRecentsStartChatWith) { [weak self] action in
image: UIImage(systemName: "person")) { [weak self] action in
guard let self = self else { return }

self.delegate?.allChatsEditActionProvider(self, didSelect: .startChat)
Expand All @@ -143,7 +140,6 @@ class AllChatsEditActionProvider {
private var createSpaceAction: UIAction {
UIAction(title: parentSpace == nil ? VectorL10n.spacesCreateSpaceTitle : VectorL10n.spacesCreateSubspaceTitle,
image: UIImage(systemName: "plus"),
discoverabilityTitle: VectorL10n.spacesCreateSpaceTitle,
attributes: isAddRoomAvailable ? [] : .disabled) { [weak self] action in
guard let self = self else { return }

Expand All @@ -154,7 +150,6 @@ class AllChatsEditActionProvider {
private var invitePeopleAction: UIAction {
UIAction(title: VectorL10n.spacesInvitePeople,
image: UIImage(systemName: "person.badge.plus"),
discoverabilityTitle: VectorL10n.spacesInvitePeople,
attributes: isInviteAvailable ? [] : .disabled) { [weak self] action in
guard let self = self else { return }

Expand All @@ -164,8 +159,7 @@ class AllChatsEditActionProvider {

private var spaceMembersAction: UIAction {
UIAction(title: VectorL10n.roomDetailsPeople,
image: UIImage(systemName: "person.3"),
discoverabilityTitle: VectorL10n.roomDetailsPeople) { [weak self] action in
image: UIImage(systemName: "person.3")) { [weak self] action in
guard let self = self else { return }

self.delegate?.allChatsEditActionProvider(self, didSelect: .spaceMembers)
Expand All @@ -174,8 +168,7 @@ class AllChatsEditActionProvider {

private var spaceSettingsAction: UIAction {
UIAction(title: VectorL10n.allChatsEditMenuSpaceSettings,
image: UIImage(systemName: "gearshape"),
discoverabilityTitle: VectorL10n.sideMenuActionSettings) { [weak self] action in
image: UIImage(systemName: "gearshape")) { [weak self] action in
guard let self = self else { return }

self.delegate?.allChatsEditActionProvider(self, didSelect: .spaceSettings)
Expand All @@ -185,7 +178,6 @@ class AllChatsEditActionProvider {
private var leaveSpaceAction: UIAction {
UIAction(title: VectorL10n.allChatsEditMenuLeaveSpace(parentName),
image: UIImage(systemName: "rectangle.portrait.and.arrow.right.fill"),
discoverabilityTitle: VectorL10n.leave,
attributes: .destructive) { [weak self] action in
guard let self = self else { return }

Expand Down
12 changes: 5 additions & 7 deletions Riot/Modules/Home/AllChats/AllChatsViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ class AllChatsViewController: HomeViewController {
private let editActionProvider = AllChatsEditActionProvider()

private var spaceSelectorBridgePresenter: SpaceSelectorBottomSheetCoordinatorBridgePresenter?
private var createSpaceCoordinator: SpaceCreationCoordinator?

private var childCoordinators: [Coordinator] = []

Expand Down Expand Up @@ -107,7 +106,7 @@ class AllChatsViewController: HomeViewController {
// MARK: - Actions

@objc private func showSpaceSelectorAction(sender: AnyObject) {
let currentSpaceId = self.dataSource.currentSpace?.spaceId ?? SpaceSelectorListItemDataHomeSpaceId
let currentSpaceId = self.dataSource.currentSpace?.spaceId ?? SpaceSelectorConstants.homeSpaceId
let spaceSelectorBridgePresenter = SpaceSelectorBottomSheetCoordinatorBridgePresenter(session: self.mainSession, selectedSpaceId: currentSpaceId, showHomeSpace: true)
spaceSelectorBridgePresenter.present(from: self, animated: true)
spaceSelectorBridgePresenter.delegate = self
Expand Down Expand Up @@ -176,8 +175,8 @@ class AllChatsViewController: HomeViewController {
return
}

self.createSpaceCoordinator?.toPresentable().dismiss(animated: true) {
self.createSpaceCoordinator = nil
coordinator.toPresentable().dismiss(animated: true) {
self.remove(childCoordinator: coordinator)
switch result {
case .cancel:
break
Expand All @@ -186,9 +185,8 @@ class AllChatsViewController: HomeViewController {
}
}
}
add(childCoordinator: coordinator)
coordinator.start()

self.createSpaceCoordinator = coordinator
}

private func switchSpace(withId spaceId: String?) {
Expand Down Expand Up @@ -357,7 +355,7 @@ extension AllChatsViewController: UIAdaptivePresentationControllerDelegate {
// MARK: - AllChatsEditActionProviderDelegate
extension AllChatsViewController: AllChatsEditActionProviderDelegate {

func allChatsEditActionProvider(_ ationProvider: AllChatsEditActionProvider, didSelect option: AllChatsEditActionProviderOption) {
func allChatsEditActionProvider(_ actionProvider: AllChatsEditActionProvider, didSelect option: AllChatsEditActionProviderOption) {
switch option {
case .exploreRooms:
joinARoom()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
//

import SwiftUI
import CommonKit

enum SpaceSelectorBottomSheetCoordinatorResult {
case cancel
Expand Down Expand Up @@ -58,7 +57,6 @@ final class SpaceSelectorBottomSheetCoordinator: Coordinator, Presentable {

// MARK: - Setup

@available(iOS 14.0, *)
init(parameters: SpaceSelectorBottomSheetCoordinatorParameters,
navigationRouter: NavigationRouterType = NavigationRouter(navigationController: RiotNavigationController())) {
self.parameters = parameters
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,7 @@ final class SpaceSelectorBottomSheetCoordinatorBridgePresenter: NSObject {
coordinator.toPresentable().dismiss(animated: animated) {
self.coordinator = nil

if let completion = completion {
completion()
}
completion?()
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ final class SpaceSelectorCoordinator: Coordinator, Presentable {

// MARK: - Setup

@available(iOS 14.0, *)
init(parameters: SpaceSelectorCoordinatorParameters) {
self.parameters = parameters
let service = SpaceSelectorService(session: parameters.session, parentSpaceId: parameters.parentSpaceId, showHomeSpace: parameters.showHomeSpace, selectedSpaceId: parameters.selectedSpaceId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import SwiftUI

/// Using an enum for the screen allows you define the different state cases with
/// the relevant associated data for each case.
@available(iOS 14.0, *)
enum MockSpaceSelectorScreenState: MockScreenState, CaseIterable {
// A case for each state you want to represent
// with specific, minimal associated data that will allow you
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import Foundation
import Combine
import MatrixSDK

@available(iOS 14.0, *)
class SpaceSelectorService: SpaceSelectorServiceProtocol {

// MARK: - Properties
Expand All @@ -30,7 +29,7 @@ class SpaceSelectorService: SpaceSelectorServiceProtocol {
private let showHomeSpace: Bool

private var spaceList: [SpaceSelectorListItemData] {
var itemList = showHomeSpace && parentSpaceId == nil ? [SpaceSelectorListItemData(id: SpaceSelectorListItemDataHomeSpaceId, icon: Asset.Images.sideMenuActionIconFeedback.image, displayName: VectorL10n.allChatsTitle)] : []
var itemList = showHomeSpace && parentSpaceId == nil ? [SpaceSelectorListItemData(id: SpaceSelectorConstants.homeSpaceId, icon: Asset.Images.sideMenuActionIconFeedback.image, displayName: VectorL10n.allChatsTitle)] : []

let notificationCounter = session.spaceService.notificationCounter

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,9 @@ import Foundation
import Combine
import UIKit

@available(iOS 14.0, *)
class MockSpaceSelectorService: SpaceSelectorServiceProtocol {

static let homeItem = SpaceSelectorListItemData(id: SpaceSelectorListItemDataHomeSpaceId, avatar: nil, icon: UIImage(systemName: "house"), displayName: "All Chats", notificationCount: 0, highlightedNotificationCount: 0, hasSubItems: false)
static let homeItem = SpaceSelectorListItemData(id: SpaceSelectorConstants.homeSpaceId, avatar: nil, icon: UIImage(systemName: "house"), displayName: "All Chats", notificationCount: 0, highlightedNotificationCount: 0, hasSubItems: false)
static let defaultSpaceList = [
homeItem,
SpaceSelectorListItemData(id: "!aaabaa:matrix.org", avatar: nil, icon: UIImage(systemName: "number"), displayName: "Default Space", notificationCount: 0, highlightedNotificationCount: 0, hasSubItems: false),
Expand All @@ -34,7 +33,7 @@ class MockSpaceSelectorService: SpaceSelectorServiceProtocol {
var parentSpaceNameSubject: CurrentValueSubject<String?, Never>
var selectedSpaceId: String?

init(spaceList: [SpaceSelectorListItemData] = defaultSpaceList, parentSpaceName: String? = nil, selectedSpaceId: String = SpaceSelectorListItemDataHomeSpaceId) {
init(spaceList: [SpaceSelectorListItemData] = defaultSpaceList, parentSpaceName: String? = nil, selectedSpaceId: String = SpaceSelectorConstants.homeSpaceId) {
self.spaceListSubject = CurrentValueSubject(spaceList)
self.parentSpaceNameSubject = CurrentValueSubject(parentSpaceName)
self.selectedSpaceId = selectedSpaceId
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import Foundation
import Combine

@available(iOS 14.0, *)
protocol SpaceSelectorServiceProtocol {
var spaceListSubject: CurrentValueSubject<[SpaceSelectorListItemData], Never> { get }
var parentSpaceNameSubject: CurrentValueSubject<String?, Never> { get }
Expand Down
Loading

0 comments on commit f573a69

Please sign in to comment.