diff --git a/Riot/Modules/ContextMenu/ActionProviders/AllChatsEditActionProvider.swift b/Riot/Modules/ContextMenu/ActionProviders/AllChatsEditActionProvider.swift index 2b2c74e4c4..af296a4c27 100644 --- a/Riot/Modules/ContextMenu/ActionProviders/AllChatsEditActionProvider.swift +++ b/Riot/Modules/ContextMenu/ActionProviders/AllChatsEditActionProvider.swift @@ -41,6 +41,7 @@ class AllChatsEditActionProvider { // MARK: - Private + private var rootSpaceCount: Int = 0 private var parentSpace: MXSpace? { didSet { parentName = parentSpace?.summary?.displayname ?? VectorL10n.spaceTag @@ -54,13 +55,16 @@ class AllChatsEditActionProvider { var menu: UIMenu { guard parentSpace != nil else { + var createActions = [ + self.startChatAction, + self.createRoomAction + ] + if rootSpaceCount > 0 { + createActions.append(self.createSpaceAction) + } return UIMenu(title: VectorL10n.allChatsTitle, children: [ self.exploreRoomsAction, - UIMenu(title: "", options: .displayInline, children: [ - self.startChatAction, - self.createRoomAction, - self.createSpaceAction - ]) + UIMenu(title: "", options: .displayInline, children: createActions) ]) } @@ -81,6 +85,19 @@ class AllChatsEditActionProvider { // MARK: - Public + /// Indicates if the context menu should be updated accordingly to the given parameters. + /// + /// If `shouldUpdate()` reutrns `true`, you should update the context menu by calling `updateMenu()`. + /// + /// - Parameters: + /// - session: The current `MXSession` instance + /// - parentSpace: The current parent space (`nil` for home space) + /// - Returns: `true` if the context menu should be updated (call `updateMenu()` in this case). `false` otherwise + func shouldUpdate(with session: MXSession?, parentSpace: MXSpace?) -> Bool { + let rootSpaceCount = session?.spaceService.rootSpaces.count ?? 0 + return parentSpace != self.parentSpace || (rootSpaceCount == 0 && self.rootSpaceCount > 0 || rootSpaceCount > 0 && self.rootSpaceCount == 0) + } + /// Returns an instance of the updated menu accordingly to the given parameters. /// /// Some menu items can be disabled depending on the required power levels of the `parentSpace`. Therefore, `updateMenu()` first returns a temporary context menu @@ -94,6 +111,7 @@ class AllChatsEditActionProvider { /// - Returns: If the `parentSpace` is `nil`, the context menu, the temporary context menu otherwise. func updateMenu(with session: MXSession?, parentSpace: MXSpace?, completion: @escaping (UIMenu) -> Void) -> UIMenu { self.parentSpace = parentSpace + self.rootSpaceCount = session?.spaceService.rootSpaces.count ?? 0 isInviteAvailable = false isAddRoomAvailable = parentSpace == nil diff --git a/Riot/Modules/Home/AllChats/AllChatsViewController.swift b/Riot/Modules/Home/AllChats/AllChatsViewController.swift index fe22bdb40f..1a788b1908 100644 --- a/Riot/Modules/Home/AllChats/AllChatsViewController.swift +++ b/Riot/Modules/Home/AllChats/AllChatsViewController.swift @@ -71,6 +71,9 @@ class AllChatsViewController: HomeViewController { if self.tabBarController?.navigationItem.searchController == nil { self.tabBarController?.navigationItem.searchController = searchController } + + NotificationCenter.default.addObserver(self, selector: #selector(self.spaceListDidChange), name: MXSpaceService.didInitialise, object: nil) + NotificationCenter.default.addObserver(self, selector: #selector(self.spaceListDidChange), name: MXSpaceService.didBuildSpaceGraph, object: nil) } override func viewWillDisappear(_ animated: Bool) { @@ -85,6 +88,14 @@ class AllChatsViewController: HomeViewController { .allChats } + @objc private func spaceListDidChange() { + guard self.editActionProvider.shouldUpdate(with: self.mainSession, parentSpace: self.dataSource?.currentSpace) else { + return + } + + updateUI() + } + @objc private func addFabButton() { // Nothing to do. We don't need FAB } @@ -298,7 +309,9 @@ class AllChatsViewController: HomeViewController { extension AllChatsViewController: SpaceSelectorBottomSheetCoordinatorBridgePresenterDelegate { func spaceSelectorBottomSheetCoordinatorBridgePresenterDidCancel(_ coordinatorBridgePresenter: SpaceSelectorBottomSheetCoordinatorBridgePresenter) { - self.spaceSelectorBridgePresenter = nil + coordinatorBridgePresenter.dismiss(animated: true) { + self.spaceSelectorBridgePresenter = nil + } } func spaceSelectorBottomSheetCoordinatorBridgePresenterDidSelectHome(_ coordinatorBridgePresenter: SpaceSelectorBottomSheetCoordinatorBridgePresenter) { diff --git a/Riot/Modules/TabBar/TabBarCoordinator.swift b/Riot/Modules/TabBar/TabBarCoordinator.swift index f0ee0b435e..615540040b 100644 --- a/Riot/Modules/TabBar/TabBarCoordinator.swift +++ b/Riot/Modules/TabBar/TabBarCoordinator.swift @@ -799,17 +799,17 @@ final class TabBarCoordinator: NSObject, TabBarCoordinatorType { let menu = UIMenu(options: .displayInline, children: actions) - let view = UIView(frame: CGRect(x: 0, y: 0, width: 40, height: 40)) + let view = UIView(frame: CGRect(x: 0, y: 0, width: 36, height: 36)) view.backgroundColor = .clear - let button: UIButton = UIButton(frame: view.frame) + let button: UIButton = UIButton(frame: view.bounds.inset(by: UIEdgeInsets(top: 7, left: 7, bottom: 7, right: 7))) button.setImage(Asset.Images.tabPeople.image, for: .normal) button.menu = menu button.showsMenuAsPrimaryAction = true button.autoresizingMask = [.flexibleHeight, .flexibleWidth] view.addSubview(button) - let avatarView = UserAvatarView(frame: view.frame.inset(by: UIEdgeInsets(top: 6, left: 6, bottom: 6, right: 6))) + let avatarView = UserAvatarView(frame: view.bounds.inset(by: UIEdgeInsets(top: 7, left: 7, bottom: 7, right: 7))) avatarView.isUserInteractionEnabled = false avatarView.update(theme: ThemeService.shared().theme) avatarView.autoresizingMask = [.flexibleHeight, .flexibleWidth] diff --git a/RiotSwiftUI/Modules/Spaces/SpaceSelectorBottomSheet/SpaceSelector/View/SpaceSelector.swift b/RiotSwiftUI/Modules/Spaces/SpaceSelectorBottomSheet/SpaceSelector/View/SpaceSelector.swift index f87f4eff14..11ea3aa0e3 100644 --- a/RiotSwiftUI/Modules/Spaces/SpaceSelectorBottomSheet/SpaceSelector/View/SpaceSelector.swift +++ b/RiotSwiftUI/Modules/Spaces/SpaceSelectorBottomSheet/SpaceSelector/View/SpaceSelector.swift @@ -24,13 +24,6 @@ struct SpaceSelector: View { @Environment(\.theme) private var theme: ThemeSwiftUI - @ViewBuilder - private var rightButton: some View { - Button(VectorL10n.create) { - viewModel.send(viewAction: .createSpace) - } - } - // MARK: Public @ObservedObject var viewModel: SpaceSelectorViewModel.Context @@ -59,9 +52,18 @@ struct SpaceSelector: View { .frame(maxHeight: .infinity) .background(theme.colors.background.edgesIgnoringSafeArea(.all)) .navigationTitle(viewModel.viewState.navigationTitle) - .navigationBarItems( - trailing: rightButton - ) + .toolbar { + ToolbarItem(placement: .confirmationAction) { + Button(VectorL10n.create) { + viewModel.send(viewAction: .createSpace) + } + } + ToolbarItem(placement: .cancellationAction) { + Button(VectorL10n.cancel) { + viewModel.send(viewAction: .cancel) + } + } + } .accentColor(theme.colors.accent) } } diff --git a/changelog.d/6534.bugfix b/changelog.d/6534.bugfix new file mode 100644 index 0000000000..8316a6fee2 --- /dev/null +++ b/changelog.d/6534.bugfix @@ -0,0 +1 @@ +Some UI tweaks for New App Layout