85 lines
2.2 KiB
Swift
85 lines
2.2 KiB
Swift
//
|
|
// ACMessageView.swift
|
|
// AutoCat
|
|
//
|
|
// Created by Selim Mustafaev on 29.06.2024.
|
|
// Copyright © 2024 Selim Mustafaev. All rights reserved.
|
|
//
|
|
|
|
import SwiftUI
|
|
|
|
struct ACMessageView: View {
|
|
|
|
enum MessageType {
|
|
|
|
case success
|
|
case warning
|
|
case error
|
|
case info
|
|
}
|
|
|
|
let message: String
|
|
let type: MessageType
|
|
let action: (() -> Void)?
|
|
|
|
var body: some View {
|
|
ZStack(alignment: .center) {
|
|
Rectangle()
|
|
.fill(.black.opacity(0.7))
|
|
.ignoresSafeArea()
|
|
HStack(spacing: 0) {
|
|
Spacer(minLength: 40)
|
|
VStack(spacing: 0) {
|
|
VStack(spacing: 16) {
|
|
Image(systemName: iconName)
|
|
.resizable()
|
|
.frame(width: 48, height: 48)
|
|
.foregroundColor(iconColor)
|
|
Text(message)
|
|
.multilineTextAlignment(.center)
|
|
}
|
|
.padding(20)
|
|
|
|
Divider()
|
|
Button("OK") {
|
|
action?()
|
|
}
|
|
.padding()
|
|
}
|
|
.background(.thickMaterial,
|
|
in: RoundedRectangle(cornerRadius: 16))
|
|
Spacer(minLength: 40)
|
|
}
|
|
}
|
|
}
|
|
|
|
var iconName: String {
|
|
switch type {
|
|
case .success: "checkmark.circle.fill"
|
|
case .warning: "exclamationmark.circle.fill"
|
|
case .error: "xmark.circle.fill"
|
|
case .info: "info.circle.fill"
|
|
}
|
|
}
|
|
|
|
var iconColor: Color {
|
|
switch type {
|
|
case .success: .green
|
|
case .warning: .orange
|
|
case .error: .red
|
|
case .info: .blue
|
|
}
|
|
}
|
|
}
|
|
|
|
#Preview {
|
|
VStack {
|
|
ACMessageView(message: "Some error with long text",
|
|
type: .error,
|
|
action: nil)
|
|
ACMessageView(message: "Some error with very very very very very long text",
|
|
type: .error,
|
|
action: nil)
|
|
}
|
|
}
|