宽窄优行-由【嘉易行】项目成品而来
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
//
//  EKAttributes+Scroll.swift
//  SwiftEntryKit
//
//  Created by Daniel Huri on 4/30/18.
//
 
import Foundation
import CoreGraphics
 
public extension EKAttributes {
    
    /** Describes the event of scroll user interaction */
    enum Scroll {
    
        /** Describes the event when the user leaves the entry after rubber-banding it - How the entry behaves */
        public struct PullbackAnimation {
            public var duration: TimeInterval
            public var damping: CGFloat
            public var initialSpringVelocity: CGFloat
            
            public init(duration: TimeInterval, damping: CGFloat, initialSpringVelocity: CGFloat) {
                self.duration = duration
                self.damping = damping
                self.initialSpringVelocity = initialSpringVelocity
            }
            
            /** The entry is jolted when it's pulled back into the original position */
            public static var jolt: PullbackAnimation {
                return PullbackAnimation(duration: 0.5, damping: 0.3, initialSpringVelocity: 10)
            }
            
            /** The view eases out when it's pulled back into the original position */
            public static var easeOut: PullbackAnimation {
                return PullbackAnimation(duration: 0.3, damping: 1, initialSpringVelocity: 10)
            }
        }
        
        /** The scroll ability is totally disabled */
        case disabled
        
        /** The scroll in the opposite direction to the edge is disabled */
        case edgeCrossingDisabled(swipeable: Bool)
        
        /** The scroll abiliby is enabled */
        case enabled(swipeable: Bool, pullbackAnimation: PullbackAnimation)
        
        var isEnabled: Bool {
            switch self {
            case .disabled:
                return false
            default:
                return true
            }
        }
        
        var isSwipeable: Bool {
            switch self {
            case .edgeCrossingDisabled(swipeable: let swipeable), .enabled(swipeable: let swipeable, pullbackAnimation: _):
                return swipeable
            default:
                return false
            }
        }
        
        var isEdgeCrossingEnabled: Bool {
            switch self {
            case .edgeCrossingDisabled:
                return false
            default:
                return true
            }
        }
    }
}