-
Notifications
You must be signed in to change notification settings - Fork 780
/
InteractiveGestureType.swift
executable file
·70 lines (63 loc) · 1.9 KB
/
InteractiveGestureType.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
//
// Created by Jake Lin on 3/3/16.
// Copyright © 2016 IBAnimatable. All rights reserved.
//
import Foundation
/**
Interactive gesture type: used to pop or dismiss view controller for transitons.
*/
public enum InteractiveGestureType {
case none
case `default` /// The default interactive gesture type from `AnimatedTransitioning`
case pan(from: GestureDirection)
case screenEdgePan(from: GestureDirection)
case pinch(direction: GestureDirection)
var stringValue: String {
return String(describing: self)
}
/// Returns the string value without qualification
public var stringValueWithoutQualification: String {
let namespace = "IBAnimatable." + String(describing: InteractiveGestureType.self) + "." + String(describing: GestureDirection.self) + "."
return String(describing: self).replacingOccurrences(of: namespace, with: "")
}
/**
GestureDirection: Used to specify the direction in `InteractiveGestureType`
*/
public enum GestureDirection: String {
case horizontal
case vertical
case left
case right
case top
case bottom
case close
case open
}
}
extension InteractiveGestureType: IBEnum {
public init(string: String?) {
guard let string = string else {
self = .none
return
}
guard let (name, params) = string.extractNameAndParams() else {
self = .none
return
}
switch name {
case "default":
self = .default
case "pan":
let direction = GestureDirection(raw: params.toString(0), defaultValue: .left)
self = .pan(from: direction)
case "screenedgepan":
let direction = GestureDirection(raw: params.toString(0), defaultValue: .left)
self = .screenEdgePan(from: direction)
case "pinch":
let direction = GestureDirection(raw: params.toString(0), defaultValue: .open)
self = .pinch(direction: direction)
default:
self = .none
}
}
}