宽窄优行-由【嘉易行】项目成品而来
younger_times
2023-07-05 0d8f5fc8a516bfd07e425909e4a4432600572ee7
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
//
//  YYAlertKit.swift
//  WashCar
//
//  Created by alvin_y on 2020/7/9.
//  Copyright © 2020 yangwang. All rights reserved.
//
 
import Foundation
import SwiftEntryKit
import UIKit
class YYAlertKit {
    
    static func dismiss() {
        SwiftEntryKit.dismiss()
    }
    
    static func display(message: String?) {
        
        guard let message = message else { return }
        
        let view = MessageView(string: message, textColor: .white)
        
        var attributes = EKAttributes()
        attributes = .float
        attributes.position = .center
        attributes.windowLevel = .alerts
        attributes.displayDuration = .init(1.7)
        
        attributes.entranceAnimation = .init(translate: .init(duration: 0.3, spring: .init(damping: 0.9, initialVelocity: 0)),
                                             scale: .init(from: 0.8, to: 1, duration: 0.3, spring: .init(damping: 0.8, initialVelocity: 0)),
                                             fade: .init(from: 0.7, to: 1, duration: 0.3))
        attributes.exitAnimation = .init(translate: .init(duration: 0.3),
                                         scale: .init(from: 1, to: 0.8, duration: 0.3),
                                         fade: .init(from: 1, to: 0, duration: 0.3))
        
        attributes.entryInteraction = .dismiss
        attributes.screenInteraction = .forward
        
        attributes.entryBackground = .visualEffect(style: .dark)
        attributes.shadow = .active(with: .init(color: .black, opacity: 0.3, radius: 6))
        attributes.roundCorners = .all(radius: 5)
        attributes.positionConstraints.size = .init(width: .intrinsic, height: .intrinsic)
        attributes.positionConstraints.maxSize = .init(width: .offset(value: 20), height: .constant(value: 200))
        
        SwiftEntryKit.display(entry: view, using: attributes)
    }
    
    static func display(position: EKAttributes.Position,message: String?) {
        
        guard let message = message else { return }
        
        let view = MessageView(string: message, textColor: .white)
        
        var attributes = EKAttributes()
        attributes = .float
        attributes.position = position
        attributes.windowLevel = .alerts
        attributes.displayDuration = .init(2)
        
        attributes.entranceAnimation = .init(translate: .init(duration: 0.3, spring: .init(damping: 0.9, initialVelocity: 0)),
                                             scale: .init(from: 0.8, to: 1, duration: 0.3, spring: .init(damping: 0.8, initialVelocity: 0)),
                                             fade: .init(from: 0.7, to: 1, duration: 0.3))
        attributes.exitAnimation = .init(translate: .init(duration: 0.3),
                                         scale: .init(from: 1, to: 0.8, duration: 0.3),
                                         fade: .init(from: 1, to: 0, duration: 0.3))
        
        attributes.entryInteraction = .dismiss
        attributes.screenInteraction = .forward
        
        attributes.entryBackground = .visualEffect(style: .dark)
        attributes.shadow = .active(with: .init(color: .black, opacity: 0.3, radius: 6))
        attributes.roundCorners = .all(radius: 5)
        attributes.positionConstraints.size = .init(width: .intrinsic, height: .intrinsic)
        attributes.positionConstraints.maxSize = .init(width: .offset(value: 20), height: .constant(value: 200))
        
        SwiftEntryKit.display(entry: view, using: attributes)
    }
    
    static func displayActivity() {
        
        let view = ActivityView(color: .white)
        
        var attributes = EKAttributes()
        attributes = .centerFloat
        attributes.displayDuration = .infinity
        attributes.windowLevel = .alerts
        
        attributes.entranceAnimation = .init(translate: nil,
                                             scale: nil,
                                             fade: .init(from: 0, to: 1, duration: 0.3))
        attributes.exitAnimation = .init(translate: nil,
                                         scale: nil,
                                         fade: .init(from: 1, to: 0, duration: 0.3))
        attributes.popBehavior = .animated(animation: .init(translate: nil,
                                                            scale: nil,
                                                            fade: .init(from: 1, to: 0, duration: 0.3)))
            
        attributes.screenInteraction = .absorbTouches
        attributes.entryInteraction = .absorbTouches
        
        attributes.screenBackground = .color(color: EKColor.init(light: #colorLiteral(red: 0, green: 0, blue: 0, alpha: 0.4), dark: #colorLiteral(red: 0, green: 0, blue: 0, alpha: 0.4)))
        attributes.entryBackground = .visualEffect(style: .dark)
        attributes.positionConstraints.size = .init(width: .constant(value: 80), height: .constant(value: 80))
        
        SwiftEntryKit.display(entry: view, using: attributes)
        
    }
    static func displayActivityWithDismiss(dely:CGFloat=1.7) {
        
        let view = ActivityView(color: .white)
        
        var attributes = EKAttributes()
        attributes = .centerFloat
        attributes.displayDuration = .infinity
        attributes.windowLevel = .alerts
        
        attributes.entranceAnimation = .init(translate: nil,
                                             scale: nil,
                                             fade: .init(from: 0, to: 1, duration: 0.3))
        attributes.exitAnimation = .init(translate: nil,
                                         scale: nil,
                                         fade: .init(from: 1, to: 0, duration: 0.3))
        attributes.popBehavior = .animated(animation: .init(translate: nil,
                                                            scale: nil,
                                                            fade: .init(from: 1, to: 0, duration: 0.3)))
            
        attributes.screenInteraction = .absorbTouches
        attributes.entryInteraction = .absorbTouches
        
        attributes.screenBackground = .color(color: EKColor.init(light: #colorLiteral(red: 0, green: 0, blue: 0, alpha: 0.4), dark: #colorLiteral(red: 0, green: 0, blue: 0, alpha: 0.4)))
        attributes.entryBackground = .visualEffect(style: .dark)
        attributes.positionConstraints.size = .init(width: .constant(value: 80), height: .constant(value: 80))
        
        SwiftEntryKit.display(entry: view, using: attributes)
        DispatchQueue.main.asyncAfter(deadline: DispatchTime.now()+1.7) {
            self.dismiss()
        }
        
    }
    static func displayActionSheet(actions: [Action]) {
        
        let vc = ActionSheetViewController(actions: actions)
        
        var attributes = EKAttributes()
        attributes = .bottomNote
        attributes.windowLevel = .alerts
        attributes.position = .bottom
        attributes.displayDuration = .infinity
        
        attributes.entranceAnimation = .init(translate: EKAttributes.Animation.Translate.init(duration: 0.25),
                                             scale: nil,
                                             fade: nil)
        attributes.exitAnimation = .init(translate: EKAttributes.Animation.Translate.init(duration: 0.25),
                                         scale: nil,
                                         fade: nil)
        
        attributes.entryInteraction = .absorbTouches
        attributes.screenInteraction = .dismiss
        
        attributes.screenBackground = .color(color: EKColor.init(light: #colorLiteral(red: 0, green: 0, blue: 0, alpha: 0.4), dark: #colorLiteral(red: 0, green: 0, blue: 0, alpha: 0.4)))
        attributes.entryBackground = .color(color: EKColor.init(light: #colorLiteral(red: 1.0, green: 1.0, blue: 1.0, alpha: 1.0), dark: #colorLiteral(red: 1.0, green: 1.0, blue: 1.0, alpha: 1.0)))
        attributes.shadow = .active(with: .init(color: .black, opacity: 0.3, radius: 6))
        attributes.roundCorners = .top(radius: 20)
        attributes.positionConstraints.size = .init(width: .fill, height: .intrinsic)
        attributes.positionConstraints.maxSize = .init(width: .fill, height: .intrinsic)
        
        SwiftEntryKit.display(entry: vc, using: attributes)
    }
    
    static func displayTopFloat(by vc: UIViewController, backgroundColor: UIColor = .white) {
        
        var attributes = EKAttributes()
        attributes = .topFloat
        attributes.windowLevel = .alerts
        attributes.position = .top
        attributes.displayDuration = .infinity
        
        attributes.entranceAnimation = .init(translate: EKAttributes.Animation.Translate.init(duration: 0.25),
                                             scale: nil,
                                             fade: nil)
        attributes.exitAnimation = .init(translate: EKAttributes.Animation.Translate.init(duration: 0.25),
                                         scale: nil,
                                         fade: nil)
        
        attributes.entryInteraction = .absorbTouches
        attributes.screenInteraction = .dismiss
        
        attributes.screenBackground = .color(color: EKColor.init(light: #colorLiteral(red: 0, green: 0, blue: 0, alpha: 0.4), dark: #colorLiteral(red: 0, green: 0, blue: 0, alpha: 0.4)))
        attributes.entryBackground = .color(color: EKColor.init(light: backgroundColor, dark: backgroundColor))
        attributes.shadow = .active(with: .init(color: .black, opacity: 0.3, radius: 6))
        attributes.roundCorners = .all(radius: 6)
        attributes.positionConstraints.size = .init(width: .fill, height: .intrinsic)
        attributes.positionConstraints.maxSize = .init(width: .fill, height: .intrinsic)
        
        SwiftEntryKit.display(entry: vc, using: attributes)
    }
    
    static func displayCenterFloat(by vc: UIViewController, backgroundColor: UIColor = .white) {
        
        var attributes = EKAttributes()
        attributes = .centerFloat
        attributes.windowLevel = .alerts
        attributes.position = .center
        attributes.displayDuration = .infinity
        
        attributes.entranceAnimation = .init(translate: EKAttributes.Animation.Translate.init(duration: 0.25),
                                             scale: nil,
                                             fade: nil)
        attributes.exitAnimation = .init(translate: EKAttributes.Animation.Translate.init(duration: 0.25),
                                         scale: nil,
                                         fade: nil)
        
        attributes.entryInteraction = .absorbTouches
        attributes.screenInteraction = .dismiss
        
        attributes.screenBackground = .color(color: EKColor.init(light: #colorLiteral(red: 0, green: 0, blue: 0, alpha: 0.4), dark: #colorLiteral(red: 0, green: 0, blue: 0, alpha: 0.4)))
        attributes.entryBackground = .color(color: EKColor.init(light: backgroundColor, dark: backgroundColor))
        attributes.shadow = .active(with: .init(color: .black, opacity: 0.3, radius: 6))
        attributes.roundCorners = .all(radius: 20)
        attributes.positionConstraints.size = .init(width: .fill, height: .intrinsic)
        attributes.positionConstraints.maxSize = .init(width: .fill, height: .intrinsic)
        
        SwiftEntryKit.display(entry: vc, using: attributes)
    }
    
    static func displayBottomNote(by vc: UIViewController, backgroundColor: UIColor = .white, isEnqueue: Bool = false) {
        
        var attributes = EKAttributes()
        attributes = .bottomNote
        attributes.windowLevel = .alerts
        attributes.position = .bottom
        attributes.displayDuration = .infinity
        attributes.precedence = isEnqueue == true ? .enqueue(priority: .normal) : .override(priority: .normal, dropEnqueuedEntries: false)
        
        attributes.entranceAnimation = .init(translate: EKAttributes.Animation.Translate.init(duration: 0.25),
                                             scale: nil,
                                             fade: nil)
        attributes.exitAnimation = .init(translate: EKAttributes.Animation.Translate.init(duration: 0.25),
                                         scale: nil,
                                         fade: nil)
        
        attributes.entryInteraction = .absorbTouches
        attributes.screenInteraction = .dismiss
        
        attributes.screenBackground = .color(color: EKColor.init(light: #colorLiteral(red: 0, green: 0, blue: 0, alpha: 0.4), dark: #colorLiteral(red: 0, green: 0, blue: 0, alpha: 0.4)))
        attributes.entryBackground = .color(color: EKColor.init(light: backgroundColor, dark: backgroundColor))
        attributes.shadow = .active(with: .init(color: .black, opacity: 0.3, radius: 6))
        attributes.roundCorners = .top(radius: 20)
        attributes.positionConstraints.size = .init(width: .fill, height: .intrinsic)
        attributes.positionConstraints.maxSize = .init(width: .fill, height: .intrinsic)
        
        SwiftEntryKit.display(entry: vc, using: attributes)
    }
    
//    static func displayAlertView(title: String = "提示", message: String, cancelTitle: String = "取消", cancelHandler: @escaping () -> Void = {}, doneTitle: String = "确定", doneHandler: @escaping () -> Void) {
//
//        // Generate textual content
//        let title = EKProperty.LabelContent(text: title, style: .init(font: UIFont.boldSystemFont(ofSize: 18), color: .black, alignment: .center))
//        let description = EKProperty.LabelContent(text: message, style: .init(font: UIFont.italicSystemFont(ofSize: 13), color: .black, alignment: .center))
//        let simpleMessage = EKSimpleMessage(title: title, description: description)
//
//        // Generate buttons content
//        let buttonFont = UIFont.systemFont(ofSize: 16)
//
//        // Close button
//        let closeButtonLabelStyle = EKProperty.LabelStyle(font: buttonFont, color: #colorLiteral(red: 0, green: 0, blue: 0, alpha: 0.4))
//        let closeButtonLabel = EKProperty.LabelContent(text: cancelTitle, style: closeButtonLabelStyle)
//        let closeButton = EKProperty.ButtonContent(label: closeButtonLabel, backgroundColor: .clear, highlightedBackgroundColor:  UIColor.gray.withAlphaComponent(0.05)) {
//            SwiftEntryKit.dismiss()
//            cancelHandler()
//        }
//
//        // Ok Button
//        let okButtonLabelStyle = EKProperty.LabelStyle(font: buttonFont, color: .red)
//        let okButtonLabel = EKProperty.LabelContent(text: doneTitle, style: okButtonLabelStyle)
//        let okButton = EKProperty.ButtonContent(label: okButtonLabel, backgroundColor: .clear, highlightedBackgroundColor:  UIColor.red.withAlphaComponent(0.05)) {
//            SwiftEntryKit.dismiss()
//            doneHandler()
//        }
//
//        // Generate the content
//        let buttonsBarContent = EKProperty.ButtonBarContent(with: closeButton, okButton, separatorColor: .lightGray, expandAnimatedly: false)
//
//        let alertMessage = EKAlertMessage(simpleMessage: simpleMessage, buttonBarContent: buttonsBarContent)
//
//        // Setup the view itself
//        let contentView = EKAlertMessageView(with: alertMessage)
//
//        var attributes = EKAttributes()
//        attributes = .centerFloat
//        attributes.windowLevel = .alerts
//        attributes.hapticFeedbackType = .success
//        attributes.screenInteraction = .absorbTouches
//        attributes.entryInteraction = .absorbTouches
//        attributes.scroll = .disabled
//        attributes.screenBackground = .color(color: #colorLiteral(red: 0, green: 0, blue: 0, alpha: 0.4))
//        attributes.entryBackground = .color(color: .white)
//        attributes.entranceAnimation = .init(scale: .init(from: 0.9, to: 1, duration: 0.4, spring: .init(damping: 1, initialVelocity: 0)), fade: .init(from: 0, to: 1, duration: 0.3))
//        attributes.exitAnimation = .init(fade: .init(from: 1, to: 0, duration: 0.2))
//        attributes.displayDuration = .infinity
//        attributes.shadow = .active(with: .init(color: .black, opacity: 0.3, radius: 5))
//        attributes.positionConstraints.maxSize = .init(width: .constant(value: 300), height: .intrinsic)
//
//        SwiftEntryKit.display(entry: contentView, using: attributes)
//    }
//
//    static func displayTipsAlertView(title: String = "提示", message: String, doneTitle: String = "确定", doneHandler: @escaping () -> Void) {
//
//        // Generate textual content
//        let title = EKProperty.LabelContent(text: title, style: .init(font: UIFont.boldSystemFont(ofSize: 18), color: .black, alignment: .center))
//        let description = EKProperty.LabelContent(text: message, style: .init(font: UIFont.italicSystemFont(ofSize: 13), color: .black, alignment: .center))
//        let simpleMessage = EKSimpleMessage(title: title, description: description)
//
//        // Generate buttons content
//        let buttonFont = UIFont.systemFont(ofSize: 16)
//
//        // Ok Button
//        let okButtonLabelStyle = EKProperty.LabelStyle(font: buttonFont, color: #colorLiteral(red: 1, green: 0, blue: 0.2470588235, alpha: 1))
//        let okButtonLabel = EKProperty.LabelContent(text: doneTitle, style: okButtonLabelStyle)
//        let okButton = EKProperty.ButtonContent(label: okButtonLabel, backgroundColor: .clear, highlightedBackgroundColor:  UIColor.red.withAlphaComponent(0.05)) {
//            SwiftEntryKit.dismiss()
//            doneHandler()
//        }
//
//
//
//        // Generate the content
//        let buttonsBarContent = EKProperty.ButtonBarContent(with: okButton, separatorColor: .lightGray, expandAnimatedly: false)
//
//        let alertMessage = EKAlertMessage(simpleMessage: simpleMessage, buttonBarContent: buttonsBarContent)
//
//        // Setup the view itself
//        let contentView = EKAlertMessageView(with: alertMessage)
//
//        var attributes = EKAttributes()
//        attributes = .centerFloat
//        attributes.windowLevel = .alerts
//        attributes.hapticFeedbackType = .success
//        attributes.screenInteraction = .absorbTouches
//        attributes.entryInteraction = .absorbTouches
//        attributes.scroll = .disabled
//        attributes.screenBackground = .color(color: #colorLiteral(red: 0, green: 0, blue: 0, alpha: 0.4))
//        attributes.entryBackground = .color(color: .white)
//        attributes.entranceAnimation = .init(scale: .init(from: 0.9, to: 1, duration: 0.4, spring: .init(damping: 1, initialVelocity: 0)), fade: .init(from: 0, to: 1, duration: 0.3))
//        attributes.exitAnimation = .init(fade: .init(from: 1, to: 0, duration: 0.2))
//        attributes.displayDuration = .infinity
//        attributes.shadow = .active(with: .init(color: .black, opacity: 0.3, radius: 5))
//        attributes.positionConstraints.maxSize = .init(width: .constant(value: 300), height: .intrinsic)
//
//        SwiftEntryKit.display(entry: contentView, using: attributes)
//    }
//
//    static func displayTextFieldAlertView(title: String?, placeholder: String?, doneTitle: String?, text: @escaping (String) -> Void) {
//
//        let title = EKProperty.LabelContent(text: title ?? "", style: .init(font: UIFont.systemFont(ofSize: 16), color: .darkGray, alignment: .center))
//        let textField = EKProperty.TextFieldContent(keyboardType: .numberPad,
//                                                    placeholder: .init(text: placeholder ?? "", style: .init(font: UIFont.systemFont(ofSize: 14), color: .lightGray)),
//                                                    textStyle: EKProperty.LabelStyle.init(font: UIFont.systemFont(ofSize: 16), color: .darkGray),
//                                                    isSecure: false,
//                                                    leadingImage: nil,
//                                                    bottomBorderColor: #colorLiteral(red: 0.9647058824, green: 0.9647058824, blue: 0.9647058824, alpha: 1))
//        let textFields = [textField]
//
//        let button = EKProperty.ButtonContent(label: .init(text: doneTitle ?? "", style: .init(font: UIFont.systemFont(ofSize: 16), color: .white)), backgroundColor: #colorLiteral(red: 1, green: 0.3215686275, blue: 0.3215686275, alpha: 1), highlightedBackgroundColor: #colorLiteral(red: 1, green: 0.3215686275, blue: 0.3215686275, alpha: 1).withAlphaComponent(0.8)) {
//
//            text(textField.textContent)
//
//            SwiftEntryKit.dismiss()
//        }
//
//        let contentView = EKFormMessageView(with: title, textFieldsContent: textFields, buttonContent: button)
//
//        var attributes = EKAttributes()
//        attributes = .float
//        attributes.windowLevel = .normal
//        attributes.position = .center
//        attributes.displayDuration = .infinity
//
//        attributes.entranceAnimation = .init(translate: .init(duration: 0.65, anchorPosition: .bottom,  spring: .init(damping: 1, initialVelocity: 0)))
//        attributes.exitAnimation = .init(translate: .init(duration: 0.65, anchorPosition: .bottom, spring: .init(damping: 1, initialVelocity: 0)))
//        attributes.popBehavior = .animated(animation: .init(translate: .init(duration: 0.65, spring: .init(damping: 1, initialVelocity: 0))))
//
//        attributes.entryInteraction = .absorbTouches
//        attributes.screenInteraction = .dismiss
//
//        attributes.entryBackground = .color(color: .white)
//        attributes.screenBackground = .color(color: #colorLiteral(red: 0, green: 0, blue: 0, alpha: 0.4))
//
//        attributes.border = .value(color: UIColor(white: 0.6, alpha: 1), width: 1)
//        attributes.shadow = .active(with: .init(color: .black, opacity: 0.3, radius: 3))
//        attributes.scroll = .enabled(swipeable: false, pullbackAnimation: .jolt)
//        attributes.statusBar = .light
//
//        attributes.positionConstraints.keyboardRelation = .bind(offset: .init(bottom: 15, screenEdgeResistance: 0))
//        attributes.positionConstraints.maxSize = .init(width: .constant(value: UIScreen.main.bounds.width), height: .intrinsic)
//
//        attributes.lifecycleEvents.didAppear = {
//            contentView.becomeFirstResponder(with: 0)
//        }
//
//        SwiftEntryKit.display(entry: contentView, using: attributes)
//    }
    
}
 
extension YYAlertKit {
    
    struct Action {
        
        let title: String
        let style: Style
        let action: (() -> Void)?
        
        enum Style {
            case plain
            case cancel
        }
    }
    
}