-
Notifications
You must be signed in to change notification settings - Fork 0
/
Extensions_AlertViewLibrary.swift
110 lines (95 loc) · 2.57 KB
/
Extensions_AlertViewLibrary.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
//
// IndicatorViewAppearence.swift
// Budget Tracker
//
// Created by Mikhailo Dovhyi on 31.03.2022.
// Copyright © 2022 Misha Dovhiy. All rights reserved.
//
import UIKit
public extension AlertViewLibrary {
func checkUnseenAlerts() {
if let function = viewModel.anshowedAIS.first as? () -> () {
viewModel.anshowedAIS.removeFirst()
function()
}
}
enum ViewKeys:String {
case verticalSeparetor
}
enum ViewType {
/**
- higligting background
*/
case error
/**
- higligting background
*/
case internetError
case succsess
case standard
/**
- error type without higligting background
*/
case standardError
case ai
var isError:Bool {
switch self {
case .error, .internetError, .standardError: return true
default:return false
}
}
}
public struct ButtonData {
public var title: String? = nil
/**
- default: .regular
*/
public var style: ButtonType = .regular
/**
- hides Alert View when UIButton pressed
- default: true
*/
public var close: Bool = true
public var action: (() -> ())? = nil
public static func with(
_ populator: (inout Self) throws -> ()
) rethrows -> Self {
var message = Self()
try populator(&message)
return message
}
}
public enum ButtonType {
case error
case regular
case link
}
}
public extension AlertViewLibrary {
public struct AlertShowMetadata {
public var type: ViewType = .standard
public var image:AIImage? = nil
public var primaryButton:ButtonData? = nil
public var secondaryButton:ButtonData? = nil
public static func with(
_ populator: (inout Self) throws -> ()
) rethrows -> Self {
var message = Self()
try populator(&message)
return message
}
}
public enum AIImage {
case error
case success
case image(UIImage)
case noImage
}
}
public extension AlertViewLibrary.AlertShowMetadata {
static func type(_ type:AlertViewLibrary.ViewType, with:AlertViewLibrary.AlertShowMetadata? = nil) -> AlertViewLibrary.AlertShowMetadata {
var new = with ?? .with({_ in})
new.type = type
return new
}
}