mirror of
https://github.com/element-hq/element-x-ios.git
synced 2025-03-10 21:39:12 +00:00
Add indicator after leaving a room (#981)
* Refactor UserIndicatorModalView to support no progress * Add room left indicator in HomeScreenViewModel * Apply PR suggestion
This commit is contained in:
parent
74b36ce870
commit
eba0fe5ce3
@ -14,6 +14,7 @@
|
||||
// limitations under the License.
|
||||
//
|
||||
|
||||
import Combine
|
||||
import Foundation
|
||||
|
||||
enum UserIndicatorType {
|
||||
@ -30,10 +31,24 @@ struct UserIndicator: Equatable, Identifiable {
|
||||
lhs.persistent == rhs.persistent
|
||||
}
|
||||
|
||||
enum LoaderType {
|
||||
case unknownProgress
|
||||
case progress(ProgressPublisher)
|
||||
}
|
||||
|
||||
var id: String = UUID().uuidString
|
||||
var type = UserIndicatorType.toast
|
||||
var title: String
|
||||
var iconName: String?
|
||||
var persistent = false
|
||||
var progressPublisher: ProgressPublisher?
|
||||
var loaderType: LoaderType? = .unknownProgress
|
||||
|
||||
var progressPublisher: AnyPublisher<Double, Never> {
|
||||
switch loaderType {
|
||||
case .none, .unknownProgress:
|
||||
return Empty().eraseToAnyPublisher()
|
||||
case .some(.progress(let progress)):
|
||||
return progress.publisher.eraseToAnyPublisher()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -24,10 +24,10 @@ struct UserIndicatorModalView: View {
|
||||
var body: some View {
|
||||
ZStack {
|
||||
VStack(spacing: 12.0) {
|
||||
if let progressFraction {
|
||||
ProgressView(value: progressFraction)
|
||||
} else {
|
||||
if case .unknownProgress = indicator.loaderType {
|
||||
ProgressView()
|
||||
} else if case .progress = indicator.loaderType {
|
||||
ProgressView(value: progressFraction)
|
||||
}
|
||||
|
||||
HStack {
|
||||
@ -45,7 +45,7 @@ struct UserIndicatorModalView: View {
|
||||
.background(Color.element.quinaryContent)
|
||||
.clipShape(RoundedCornerShape(radius: 12.0, corners: .allCorners))
|
||||
.shadow(color: .black.opacity(0.1), radius: 10.0, y: 4.0)
|
||||
.onReceive(indicator.progressPublisher?.publisher ?? Empty().eraseToAnyPublisher()) { progress in
|
||||
.onReceive(indicator.progressPublisher) { progress in
|
||||
progressFraction = progress
|
||||
}
|
||||
.transition(.opacity)
|
||||
@ -68,9 +68,16 @@ struct UserIndicatorModalView_Previews: PreviewProvider {
|
||||
UserIndicatorModalView(indicator: UserIndicator(type: .modal,
|
||||
title: "Successfully logged in",
|
||||
iconName: "checkmark",
|
||||
progressPublisher: ProgressTracker(initialValue: 0.5))
|
||||
loaderType: .progress(ProgressTracker(initialValue: 0.5)))
|
||||
)
|
||||
.previewDisplayName("Progress Bar")
|
||||
|
||||
UserIndicatorModalView(indicator: UserIndicator(type: .modal,
|
||||
title: "Successfully logged in",
|
||||
iconName: "checkmark",
|
||||
loaderType: .none)
|
||||
)
|
||||
.previewDisplayName("No progress")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -91,7 +91,7 @@ final class BugReportScreenCoordinator: CoordinatorProtocol {
|
||||
type: .modal,
|
||||
title: label,
|
||||
persistent: true,
|
||||
progressPublisher: progressPublisher)
|
||||
loaderType: .progress(progressPublisher))
|
||||
)
|
||||
}
|
||||
|
||||
|
@ -346,6 +346,11 @@ class HomeScreenViewModel: HomeScreenViewModelType, HomeScreenViewModelProtocol
|
||||
case .none, .some(.failure):
|
||||
state.bindings.alertInfo = AlertInfo(id: UUID(), title: L10n.errorUnknown)
|
||||
case .some(.success):
|
||||
ServiceLocator.shared.userIndicatorController.submitIndicator(UserIndicator(id: UUID().uuidString,
|
||||
type: .modal,
|
||||
title: L10n.commonCurrentUserLeftRoom,
|
||||
iconName: "checkmark",
|
||||
loaderType: .none))
|
||||
callback?(.roomLeft(roomIdentifier: roomId))
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user