2022-11-16 15:37:34 +02:00
|
|
|
//
|
2024-09-06 16:34:30 +03:00
|
|
|
// Copyright 2022-2024 New Vector Ltd.
|
2022-11-16 15:37:34 +02:00
|
|
|
//
|
2025-01-06 11:27:37 +01:00
|
|
|
// SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial
|
|
|
|
// Please see LICENSE files in the repository root for full details.
|
2022-11-16 15:37:34 +02:00
|
|
|
//
|
|
|
|
|
2023-02-08 21:52:31 +01:00
|
|
|
import Combine
|
2022-11-16 15:37:34 +02:00
|
|
|
import SwiftUI
|
|
|
|
|
2023-02-14 11:09:55 +01:00
|
|
|
struct UserIndicatorModalView: View {
|
|
|
|
let indicator: UserIndicator
|
2023-06-21 12:53:17 +03:00
|
|
|
@State private var progressFraction = 0.0
|
2023-02-08 21:52:31 +01:00
|
|
|
|
2022-11-16 15:37:34 +02:00
|
|
|
var body: some View {
|
|
|
|
ZStack {
|
|
|
|
VStack(spacing: 12.0) {
|
2023-06-16 17:41:25 +01:00
|
|
|
if case .indeterminate = indicator.progress {
|
2023-02-08 21:52:31 +01:00
|
|
|
ProgressView()
|
2023-06-16 17:41:25 +01:00
|
|
|
} else if case .published = indicator.progress {
|
2023-05-30 12:32:07 +02:00
|
|
|
ProgressView(value: progressFraction)
|
2023-02-08 21:52:31 +01:00
|
|
|
}
|
|
|
|
|
2023-11-14 12:38:38 +00:00
|
|
|
HStack(spacing: 8) {
|
2023-02-14 11:09:55 +01:00
|
|
|
if let iconName = indicator.iconName {
|
2022-11-16 15:37:34 +02:00
|
|
|
Image(systemName: iconName)
|
2023-06-16 17:41:25 +01:00
|
|
|
.font(.compound.bodyLG)
|
|
|
|
.foregroundColor(.compound.iconPrimary)
|
2022-11-16 15:37:34 +02:00
|
|
|
}
|
2023-02-14 11:09:55 +01:00
|
|
|
Text(indicator.title)
|
2023-04-25 16:42:06 +01:00
|
|
|
.font(.compound.bodyLG)
|
2023-06-16 10:49:13 +01:00
|
|
|
.foregroundColor(.compound.textPrimary)
|
2022-11-16 15:37:34 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
.padding()
|
2023-02-09 14:57:55 +01:00
|
|
|
.frame(minWidth: 150.0)
|
|
|
|
.fixedSize(horizontal: true, vertical: false)
|
2023-06-16 10:49:13 +01:00
|
|
|
.background(Color.compound.bgSubtlePrimary)
|
2022-11-16 15:37:34 +02:00
|
|
|
.clipShape(RoundedCornerShape(radius: 12.0, corners: .allCorners))
|
|
|
|
.shadow(color: .black.opacity(0.1), radius: 10.0, y: 4.0)
|
2023-05-30 12:32:07 +02:00
|
|
|
.onReceive(indicator.progressPublisher) { progress in
|
2023-02-08 21:52:31 +01:00
|
|
|
progressFraction = progress
|
|
|
|
}
|
2022-11-16 15:37:34 +02:00
|
|
|
.transition(.opacity)
|
|
|
|
}
|
2023-02-14 11:09:55 +01:00
|
|
|
.id(indicator.id)
|
2022-11-16 15:37:34 +02:00
|
|
|
.frame(maxWidth: .infinity, maxHeight: .infinity)
|
2023-06-28 14:59:57 +03:00
|
|
|
.background {
|
|
|
|
if !indicator.allowsInteraction {
|
|
|
|
Color.black.opacity(0.1)
|
|
|
|
}
|
|
|
|
}
|
2022-11-16 15:37:34 +02:00
|
|
|
.ignoresSafeArea()
|
2023-05-31 12:56:58 +02:00
|
|
|
.interactiveDismissDisabled(indicator.interactiveDismissDisabled)
|
2022-11-16 15:37:34 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-09-20 17:33:31 +02:00
|
|
|
struct UserIndicatorModalView_Previews: PreviewProvider, TestablePreview {
|
2022-11-16 15:37:34 +02:00
|
|
|
static var previews: some View {
|
2023-02-08 21:52:31 +01:00
|
|
|
Group {
|
2023-02-14 11:09:55 +01:00
|
|
|
UserIndicatorModalView(indicator: UserIndicator(type: .modal,
|
|
|
|
title: "Successfully logged in",
|
|
|
|
iconName: "checkmark")
|
2023-02-08 21:52:31 +01:00
|
|
|
)
|
|
|
|
.previewDisplayName("Spinner")
|
2023-06-16 17:41:25 +01:00
|
|
|
|
2023-06-21 12:55:49 +03:00
|
|
|
UserIndicatorModalView(indicator: UserIndicator(type: .modal(progress: .published(CurrentValueSubject<Double, Never>(0.5).asCurrentValuePublisher()),
|
2023-06-28 14:59:57 +03:00
|
|
|
interactiveDismissDisabled: false,
|
|
|
|
allowsInteraction: false),
|
2023-02-14 11:09:55 +01:00
|
|
|
title: "Successfully logged in",
|
2023-06-16 17:41:25 +01:00
|
|
|
iconName: "checkmark")
|
2023-02-08 21:52:31 +01:00
|
|
|
)
|
|
|
|
.previewDisplayName("Progress Bar")
|
2023-05-30 12:32:07 +02:00
|
|
|
|
2023-06-28 14:59:57 +03:00
|
|
|
UserIndicatorModalView(indicator: UserIndicator(type: .modal(progress: .none,
|
|
|
|
interactiveDismissDisabled: false,
|
|
|
|
allowsInteraction: false),
|
2023-05-30 12:32:07 +02:00
|
|
|
title: "Successfully logged in",
|
2023-06-16 17:41:25 +01:00
|
|
|
iconName: "checkmark")
|
2023-05-30 12:32:07 +02:00
|
|
|
)
|
|
|
|
.previewDisplayName("No progress")
|
2022-11-16 15:37:34 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|