宽窄优行-由【嘉易行】项目成品而来
younger_times
2023-04-06 a1ae6802080a22e6e6ce6d0935e95facb1daca5c
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
//
//  EKAttributes+UserInteraction.swift
//  SwiftEntryKit
//
//  Created by Daniel Huri on 4/21/18.
//  Copyright (c) 2018 huri000@gmail.com. All rights reserved.
//
 
import Foundation
 
public extension EKAttributes {
    
    /** Describes the user interaction events that are triggered as the user taps the entry / screen */
    struct UserInteraction {
        
        /** Code that is executed when the user taps the entry / screen */
        public typealias Action = () -> ()
        
        /** The default event that happens as the user interacts */
        public enum Default {
            
            /** Absorbs touches. The entry / screen does nothing (Swallows the touch) */
            case absorbTouches
            
            /** Touches delay the exit of the entry */
            case delayExit(by: TimeInterval)
            
            /** Taps dismiss the entry immediately */
            case dismissEntry
            
            /** Touches are forwarded to the lower window (In most cases it would be the application main window that will handle it */
            case forward
        }
        
        var isResponsive: Bool {
            switch defaultAction {
            case .forward:
                return false
            default:
                return true
            }
        }
        
        var isDelayExit: Bool {
            switch defaultAction {
            case .delayExit:
                return true
            default:
                return false
            }
        }
        
        /** A default action that is executed when the entry or the screen are interacted by the user */
        public var defaultAction: Default
        
        /** Additional actions that can be customized by the user */
        public var customTapActions: [Action]
        
        public init(defaultAction: Default = .absorbTouches, customTapActions: [Action] = []) {
            self.defaultAction = defaultAction
            self.customTapActions = customTapActions
        }
        
        /** Dismiss action */
        public static var dismiss: UserInteraction {
            return UserInteraction(defaultAction: .dismissEntry)
        }
        
        /** Forward action */
        public static var forward: UserInteraction {
            return UserInteraction(defaultAction: .forward)
        }
        
        /** Absorb touches action */
        public static var absorbTouches: UserInteraction {
            return UserInteraction(defaultAction: .absorbTouches)
        }
        
        /** Delay exit action */
        public static func delayExit(by delay: TimeInterval) -> UserInteraction {
            return UserInteraction(defaultAction: .delayExit(by: delay))
        }
    }
}