From 90f48e93039b172e47e554d9ed88df0f66fb0893 Mon Sep 17 00:00:00 2001 From: Alfonso Grillo Date: Wed, 31 May 2023 12:56:58 +0200 Subject: [PATCH] Add UserIndicator.disableInteractiveDismiss (#993) --- .../Other/UserIndicator/UserIndicator.swift | 17 +++++++++++++++-- .../UserIndicator/UserIndicatorModalView.swift | 1 + .../CreateRoom/CreateRoomViewModel.swift | 2 +- .../RoomDetailsEditScreenViewModel.swift | 10 ++++++++-- 4 files changed, 25 insertions(+), 5 deletions(-) diff --git a/ElementX/Sources/Other/UserIndicator/UserIndicator.swift b/ElementX/Sources/Other/UserIndicator/UserIndicator.swift index 3561328f9..1dd727909 100644 --- a/ElementX/Sources/Other/UserIndicator/UserIndicator.swift +++ b/ElementX/Sources/Other/UserIndicator/UserIndicator.swift @@ -17,9 +17,13 @@ import Combine import Foundation -enum UserIndicatorType { +enum UserIndicatorType: Equatable { case toast - case modal + case modal(interactiveDismissDisabled: Bool) + + static var modal: Self { + .modal(interactiveDismissDisabled: false) + } } struct UserIndicator: Equatable, Identifiable { @@ -51,4 +55,13 @@ struct UserIndicator: Equatable, Identifiable { return progress.publisher.eraseToAnyPublisher() } } + + var interactiveDismissDisabled: Bool { + switch type { + case .toast: + return false + case .modal(let interactiveDismissDisabled): + return interactiveDismissDisabled + } + } } diff --git a/ElementX/Sources/Other/UserIndicator/UserIndicatorModalView.swift b/ElementX/Sources/Other/UserIndicator/UserIndicatorModalView.swift index a697c7ed3..8acc3aa7a 100644 --- a/ElementX/Sources/Other/UserIndicator/UserIndicatorModalView.swift +++ b/ElementX/Sources/Other/UserIndicator/UserIndicatorModalView.swift @@ -54,6 +54,7 @@ struct UserIndicatorModalView: View { .frame(maxWidth: .infinity, maxHeight: .infinity) .background(.black.opacity(0.1)) .ignoresSafeArea() + .interactiveDismissDisabled(indicator.interactiveDismissDisabled) } } diff --git a/ElementX/Sources/Screens/CreateRoom/CreateRoomViewModel.swift b/ElementX/Sources/Screens/CreateRoom/CreateRoomViewModel.swift index 2af703571..3a37ad4d7 100644 --- a/ElementX/Sources/Screens/CreateRoom/CreateRoomViewModel.swift +++ b/ElementX/Sources/Screens/CreateRoom/CreateRoomViewModel.swift @@ -168,7 +168,7 @@ class CreateRoomViewModel: CreateRoomViewModelType, CreateRoomViewModelProtocol private func showLoadingIndicator() { userIndicatorController?.submitIndicator(UserIndicator(id: Self.loadingIndicatorIdentifier, - type: .modal, + type: .modal(interactiveDismissDisabled: true), title: L10n.commonLoading, persistent: true)) } diff --git a/ElementX/Sources/Screens/RoomDetailsEditScreen/RoomDetailsEditScreenViewModel.swift b/ElementX/Sources/Screens/RoomDetailsEditScreen/RoomDetailsEditScreenViewModel.swift index ef94b3ff9..bac9f249b 100644 --- a/ElementX/Sources/Screens/RoomDetailsEditScreen/RoomDetailsEditScreenViewModel.swift +++ b/ElementX/Sources/Screens/RoomDetailsEditScreen/RoomDetailsEditScreenViewModel.swift @@ -80,7 +80,10 @@ class RoomDetailsEditScreenViewModel: RoomDetailsEditScreenViewModelType, RoomDe defer { userIndicatorController.retractIndicatorWithId(userIndicatorID) } - userIndicatorController.submitIndicator(UserIndicator(id: userIndicatorID, type: .modal, title: L10n.commonLoading, persistent: true)) + userIndicatorController.submitIndicator(UserIndicator(id: userIndicatorID, + type: .modal(interactiveDismissDisabled: true), + title: L10n.commonLoading, + persistent: true)) let mediaResult = await mediaPreprocessor.processMedia(at: url) @@ -101,7 +104,10 @@ class RoomDetailsEditScreenViewModel: RoomDetailsEditScreenViewModelType, RoomDe defer { userIndicatorController.retractIndicatorWithId(userIndicatorID) } - userIndicatorController.submitIndicator(UserIndicator(id: userIndicatorID, type: .modal, title: L10n.screenRoomDetailsUpdatingRoom, persistent: true)) + userIndicatorController.submitIndicator(UserIndicator(id: userIndicatorID, + type: .modal(interactiveDismissDisabled: true), + title: L10n.screenRoomDetailsUpdatingRoom, + persistent: true)) do { try await withThrowingTaskGroup(of: Void.self) { group in