147 lines
3.7 KiB
Swift

//
// MessageView.swift
// Browse
//
// Created by Javier Cicchelli on 15/12/2022.
// Copyright © 2022 Röck+Cöde. All rights reserved.
//
import DataModels
import SwiftUI
struct MessageView: View {
// MARK: Properties
let type: MessageType
let action: ActionClosure
// MARK: Body
var body: some View {
VStack(spacing: 72) {
Image.warning
.resizable()
.scaledToFit()
.frame(width: 120, height: 120)
VStack(spacing: 48) {
Text(
type.firstText,
bundle: .module
)
.font(.title)
.fontWeight(.semibold)
Text(
type.secondText,
bundle: .module
)
.font(.title2)
.fontWeight(.regular)
}
.multilineTextAlignment(.center)
Button(action: action) {
Text(
type.button,
bundle: .module
)
.font(.body)
.fontWeight(.semibold)
.frame(maxWidth: .infinity)
}
.tint(.red)
.buttonStyle(.borderedProminent)
.buttonBorderShape(.roundedRectangle(radius: 8))
.controlSize(.large)
}
.padding(.horizontal, 48)
.ignoresSafeArea()
}
}
// MARK: - Enumerations
extension MessageView {
enum MessageType {
case noCredentials
case notSupported
case empty
case error
}
}
private extension MessageView.MessageType {
var firstText: LocalizedStringKey {
switch self {
case .noCredentials:
return "message.type_no_credentials.text.first"
case .notSupported:
return "message.type_not_supported.text.first"
case .empty:
return "message.type_empty.text.first"
case .error:
return "message.type_error.text.first"
}
}
var secondText: LocalizedStringKey {
switch self {
case .noCredentials:
return "message.type_no_credentials.text.second"
case .notSupported:
return "message.type_not_supported.text.second"
case .empty:
return "message.type_empty.text.second"
case .error:
return "message.type_error.text.second"
}
}
var button: LocalizedStringKey {
switch self {
case .noCredentials:
return "message.type_no_credentials.button.text"
case .notSupported:
return "message.type_not_supported.button.text"
case .empty:
return "message.type_empty.button.text"
case .error:
return "message.type_error.button.text"
}
}
}
// MARK: - Image+Constants
private extension Image {
static let warning = Image(systemName: "exclamationmark.circle.fill")
}
// MARK: - Previews
struct MessageView_Previews: PreviewProvider {
static var previews: some View {
MessageView(type: .noCredentials) {
// action closure.
}
.previewDisplayName("View of type no credentials")
MessageView(type: .notSupported) {
// action closure.
}
.previewDisplayName("View of type not supported")
MessageView(type: .empty) {
// action closure.
}
.previewDisplayName("View of type empty")
MessageView(type: .error) {
// action closure.
}
.previewDisplayName("View of type error")
}
}