Skip to content

Commit 27d890a

Browse files
committed
seperate direction into it's own file
1 parent 0923f31 commit 27d890a

File tree

3 files changed

+80
-67
lines changed

3 files changed

+80
-67
lines changed

ZLSwipeableViewSwift/Direction.swift

+76
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
//
2+
// Direction.swift
3+
// ZLSwipeableViewSwift
4+
//
5+
// Created by Andrew Breckenridge on 5/17/16.
6+
// Copyright © 2016 Andrew Breckenridge. All rights reserved.
7+
//
8+
9+
import UIKit
10+
11+
public typealias ZLSwipeableViewDirection = Direction
12+
13+
extension Direction: Equatable {}
14+
public func ==(lhs: Direction, rhs: Direction) -> Bool {
15+
return lhs.rawValue == rhs.rawValue
16+
}
17+
18+
/**
19+
* Swiped direction.
20+
*/
21+
public struct Direction : OptionSetType, CustomStringConvertible {
22+
23+
public var rawValue: UInt
24+
25+
public init(rawValue: UInt) {
26+
self.rawValue = rawValue
27+
}
28+
29+
public static let None = Direction(rawValue: 0b0000)
30+
public static let Left = Direction(rawValue: 0b0001)
31+
public static let Right = Direction(rawValue: 0b0010)
32+
public static let Up = Direction(rawValue: 0b0100)
33+
public static let Down = Direction(rawValue: 0b1000)
34+
public static let Horizontal: Direction = [Left, Right]
35+
public static let Vertical: Direction = [Up, Down]
36+
public static let All: Direction = [Horizontal, Vertical]
37+
38+
public static func fromPoint(point: CGPoint) -> Direction {
39+
switch (point.x, point.y) {
40+
case let (x, y) where abs(x) >= abs(y) && x > 0:
41+
return .Right
42+
case let (x, y) where abs(x) >= abs(y) && x < 0:
43+
return .Left
44+
case let (x, y) where abs(x) < abs(y) && y < 0:
45+
return .Up
46+
case let (x, y) where abs(x) < abs(y) && y > 0:
47+
return .Down
48+
case (_, _):
49+
return .None
50+
}
51+
}
52+
53+
public var description: String {
54+
switch self {
55+
case Direction.None:
56+
return "None"
57+
case Direction.Left:
58+
return "Left"
59+
case Direction.Right:
60+
return "Right"
61+
case Direction.Up:
62+
return "Up"
63+
case Direction.Down:
64+
return "Down"
65+
case Direction.Horizontal:
66+
return "Horizontal"
67+
case Direction.Vertical:
68+
return "Vertical"
69+
case Direction.All:
70+
return "All"
71+
default:
72+
return "Unknown"
73+
}
74+
}
75+
76+
}

ZLSwipeableViewSwift/ZLSwipeableView.swift

-67
Original file line numberDiff line numberDiff line change
@@ -8,73 +8,6 @@
88

99
import UIKit
1010

11-
// MARK: - Helper classes
12-
public typealias ZLSwipeableViewDirection = Direction
13-
14-
public func ==(lhs: Direction, rhs: Direction) -> Bool {
15-
return lhs.rawValue == rhs.rawValue
16-
}
17-
18-
/**
19-
* Swiped direction.
20-
*/
21-
public struct Direction : OptionSetType, CustomStringConvertible {
22-
23-
public var rawValue: UInt
24-
25-
public init(rawValue: UInt) {
26-
self.rawValue = rawValue
27-
}
28-
29-
public static let None = Direction(rawValue: 0b0000)
30-
public static let Left = Direction(rawValue: 0b0001)
31-
public static let Right = Direction(rawValue: 0b0010)
32-
public static let Up = Direction(rawValue: 0b0100)
33-
public static let Down = Direction(rawValue: 0b1000)
34-
public static let Horizontal: Direction = [Left, Right]
35-
public static let Vertical: Direction = [Up, Down]
36-
public static let All: Direction = [Horizontal, Vertical]
37-
38-
public static func fromPoint(point: CGPoint) -> Direction {
39-
switch (point.x, point.y) {
40-
case let (x, y) where abs(x) >= abs(y) && x > 0:
41-
return .Right
42-
case let (x, y) where abs(x) >= abs(y) && x < 0:
43-
return .Left
44-
case let (x, y) where abs(x) < abs(y) && y < 0:
45-
return .Up
46-
case let (x, y) where abs(x) < abs(y) && y > 0:
47-
return .Down
48-
case (_, _):
49-
return .None
50-
}
51-
}
52-
53-
public var description: String {
54-
switch self {
55-
case Direction.None:
56-
return "None"
57-
case Direction.Left:
58-
return "Left"
59-
case Direction.Right:
60-
return "Right"
61-
case Direction.Up:
62-
return "Up"
63-
case Direction.Down:
64-
return "Down"
65-
case Direction.Horizontal:
66-
return "Horizontal"
67-
case Direction.Vertical:
68-
return "Vertical"
69-
case Direction.All:
70-
return "All"
71-
default:
72-
return "Unknown"
73-
}
74-
}
75-
76-
}
77-
7811
// data source
7912
public typealias NextViewHandler = () -> UIView?
8013
public typealias PreviousViewHandler = () -> UIView?

ZLSwipeableViewSwift/ZLSwipeableViewSwift.xcodeproj/project.pbxproj

+4
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,13 @@
77
objects = {
88

99
/* Begin PBXBuildFile section */
10+
466AFFEC1CEB8BA1006FF62A /* Direction.swift in Sources */ = {isa = PBXBuildFile; fileRef = 466AFFEB1CEB8BA1006FF62A /* Direction.swift */; };
1011
46C0F0351C68AC90004BE1B3 /* ZLSwipeableView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 46C0F0341C68AC90004BE1B3 /* ZLSwipeableView.swift */; };
1112
/* End PBXBuildFile section */
1213

1314
/* Begin PBXFileReference section */
1415
460B72511B76D3E600BB5ED8 /* ZLSwipeableViewSwift.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = ZLSwipeableViewSwift.framework; sourceTree = BUILT_PRODUCTS_DIR; };
16+
466AFFEB1CEB8BA1006FF62A /* Direction.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Direction.swift; sourceTree = SOURCE_ROOT; };
1517
46C0F0341C68AC90004BE1B3 /* ZLSwipeableView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ZLSwipeableView.swift; sourceTree = SOURCE_ROOT; };
1618
46C0F0361C68ACA1004BE1B3 /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = SOURCE_ROOT; };
1719
/* End PBXFileReference section */
@@ -47,6 +49,7 @@
4749
isa = PBXGroup;
4850
children = (
4951
46C0F0341C68AC90004BE1B3 /* ZLSwipeableView.swift */,
52+
466AFFEB1CEB8BA1006FF62A /* Direction.swift */,
5053
46C0F0361C68ACA1004BE1B3 /* Info.plist */,
5154
);
5255
path = ZLSwipeableViewSwift;
@@ -131,6 +134,7 @@
131134
buildActionMask = 2147483647;
132135
files = (
133136
46C0F0351C68AC90004BE1B3 /* ZLSwipeableView.swift in Sources */,
137+
466AFFEC1CEB8BA1006FF62A /* Direction.swift in Sources */,
134138
);
135139
runOnlyForDeploymentPostprocessing = 0;
136140
};

0 commit comments

Comments
 (0)