Skip to content

Commit

Permalink
Removing BW prefix from all types, because module namespacing
Browse files Browse the repository at this point in the history
  • Loading branch information
bitwit committed Jul 5, 2016
1 parent 5ae558a commit 3d127d9
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 73 deletions.
24 changes: 12 additions & 12 deletions BWSwipeRevealCell.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@
/* Begin PBXBuildFile section */
752EDC641BF64B5B007ED36D /* BWSwipeRevealCell.h in Headers */ = {isa = PBXBuildFile; fileRef = 752EDC631BF64B5B007ED36D /* BWSwipeRevealCell.h */; settings = {ATTRIBUTES = (Public, ); }; };
752EDC6C1BF65169007ED36D /* README.md in Sources */ = {isa = PBXBuildFile; fileRef = 752EDC6B1BF65169007ED36D /* README.md */; };
752EDC6F1BF654F8007ED36D /* BWSwipeCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 752EDC6D1BF654F8007ED36D /* BWSwipeCell.swift */; };
752EDC701BF654F8007ED36D /* BWSwipeRevealCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 752EDC6E1BF654F8007ED36D /* BWSwipeRevealCell.swift */; };
752EDC6F1BF654F8007ED36D /* SwipeCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 752EDC6D1BF654F8007ED36D /* SwipeCell.swift */; };
752EDC701BF654F8007ED36D /* SwipeRevealCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 752EDC6E1BF654F8007ED36D /* SwipeRevealCell.swift */; };
752EDC781BF65880007ED36D /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 752EDC771BF65880007ED36D /* AppDelegate.swift */; };
752EDC7B1BF65880007ED36D /* BWSwipeRevealCellExample.xcdatamodeld in Sources */ = {isa = PBXBuildFile; fileRef = 752EDC791BF65880007ED36D /* BWSwipeRevealCellExample.xcdatamodeld */; };
752EDC7D1BF65880007ED36D /* MasterViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 752EDC7C1BF65880007ED36D /* MasterViewController.swift */; };
752EDC821BF65880007ED36D /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 752EDC801BF65880007ED36D /* Main.storyboard */; };
752EDC871BF65880007ED36D /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 752EDC851BF65880007ED36D /* LaunchScreen.storyboard */; };
752EDC8D1BF659C7007ED36D /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 752EDC8C1BF659C7007ED36D /* Assets.xcassets */; };
752EDC8F1BF65C68007ED36D /* example.gif in Resources */ = {isa = PBXBuildFile; fileRef = 752EDC8E1BF65C68007ED36D /* example.gif */; };
7563A67C1D09C82400A53142 /* BWSwipeableViewHandler.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7563A67B1D09C82400A53142 /* BWSwipeableViewHandler.swift */; };
7563A67C1D09C82400A53142 /* SwipeViewHandler.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7563A67B1D09C82400A53142 /* SwipeViewHandler.swift */; };
75ABE4201C0F88AD00F42894 /* BWSwipeRevealCell.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 752EDC601BF64B5B007ED36D /* BWSwipeRevealCell.framework */; };
75ABE4221C0F8AF300F42894 /* BWSwipeRevealCell.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 752EDC601BF64B5B007ED36D /* BWSwipeRevealCell.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
/* End PBXBuildFile section */
Expand Down Expand Up @@ -52,8 +52,8 @@
752EDC631BF64B5B007ED36D /* BWSwipeRevealCell.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = BWSwipeRevealCell.h; sourceTree = "<group>"; };
752EDC651BF64B5B007ED36D /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
752EDC6B1BF65169007ED36D /* README.md */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = net.daringfireball.markdown; path = README.md; sourceTree = "<group>"; };
752EDC6D1BF654F8007ED36D /* BWSwipeCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BWSwipeCell.swift; sourceTree = "<group>"; };
752EDC6E1BF654F8007ED36D /* BWSwipeRevealCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BWSwipeRevealCell.swift; sourceTree = "<group>"; };
752EDC6D1BF654F8007ED36D /* SwipeCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SwipeCell.swift; sourceTree = "<group>"; };
752EDC6E1BF654F8007ED36D /* SwipeRevealCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SwipeRevealCell.swift; sourceTree = "<group>"; };
752EDC751BF65880007ED36D /* BWSwipeRevealCellExample.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = BWSwipeRevealCellExample.app; sourceTree = BUILT_PRODUCTS_DIR; };
752EDC771BF65880007ED36D /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
752EDC7A1BF65880007ED36D /* BWSwipeRevealCellExample.xcdatamodel */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcdatamodel; path = BWSwipeRevealCellExample.xcdatamodel; sourceTree = "<group>"; };
Expand All @@ -63,7 +63,7 @@
752EDC881BF65880007ED36D /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
752EDC8C1BF659C7007ED36D /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
752EDC8E1BF65C68007ED36D /* example.gif */ = {isa = PBXFileReference; lastKnownFileType = image.gif; path = example.gif; sourceTree = "<group>"; };
7563A67B1D09C82400A53142 /* BWSwipeableViewHandler.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BWSwipeableViewHandler.swift; sourceTree = "<group>"; };
7563A67B1D09C82400A53142 /* SwipeViewHandler.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SwipeViewHandler.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -108,9 +108,9 @@
752EDC621BF64B5B007ED36D /* BWSwipeRevealCell */ = {
isa = PBXGroup;
children = (
7563A67B1D09C82400A53142 /* BWSwipeableViewHandler.swift */,
752EDC6D1BF654F8007ED36D /* BWSwipeCell.swift */,
752EDC6E1BF654F8007ED36D /* BWSwipeRevealCell.swift */,
7563A67B1D09C82400A53142 /* SwipeViewHandler.swift */,
752EDC6D1BF654F8007ED36D /* SwipeCell.swift */,
752EDC6E1BF654F8007ED36D /* SwipeRevealCell.swift */,
752EDC631BF64B5B007ED36D /* BWSwipeRevealCell.h */,
752EDC651BF64B5B007ED36D /* Info.plist */,
);
Expand Down Expand Up @@ -248,9 +248,9 @@
buildActionMask = 2147483647;
files = (
752EDC6C1BF65169007ED36D /* README.md in Sources */,
7563A67C1D09C82400A53142 /* BWSwipeableViewHandler.swift in Sources */,
752EDC701BF654F8007ED36D /* BWSwipeRevealCell.swift in Sources */,
752EDC6F1BF654F8007ED36D /* BWSwipeCell.swift in Sources */,
7563A67C1D09C82400A53142 /* SwipeViewHandler.swift in Sources */,
752EDC701BF654F8007ED36D /* SwipeRevealCell.swift in Sources */,
752EDC6F1BF654F8007ED36D /* SwipeCell.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,18 @@
import Foundation
import UIKit

@objc public protocol BWSwipeCellDelegate: NSObjectProtocol {
@objc optional func swipeCellDidStartSwiping(_ cell: BWSwipeCell)
@objc optional func swipeCellDidSwipe(_ cell: BWSwipeCell)
@objc optional func swipeCellWillRelease(_ cell: BWSwipeCell)
@objc optional func swipeCellDidCompleteRelease(_ cell: BWSwipeCell)
@objc optional func swipeCellDidChangeState(_ cell: BWSwipeCell)
@objc public protocol SwipeCellDelegate: NSObjectProtocol {
@objc optional func swipeCellDidStartSwiping(_ cell: SwipeCell)
@objc optional func swipeCellDidSwipe(_ cell: SwipeCell)
@objc optional func swipeCellWillRelease(_ cell: SwipeCell)
@objc optional func swipeCellDidCompleteRelease(_ cell: SwipeCell)
@objc optional func swipeCellDidChangeState(_ cell: SwipeCell)
}

public class BWSwipeCell: UITableViewCell {
public class SwipeCell: UITableViewCell {

public private(set) var swipeHandler: BWSwipeViewHandler!
public var delegate: BWSwipeCellDelegate?
public private(set) var swipeHandler: SwipeViewHandler!
public var delegate: SwipeCellDelegate?

override public init(style: UITableViewCellStyle, reuseIdentifier: String?) {

Expand Down Expand Up @@ -54,30 +54,30 @@ public class BWSwipeCell: UITableViewCell {
backgroundView = bv
}

swipeHandler = BWSwipeViewHandler(contentView: contentView, backgroundView: bv)
swipeHandler = SwipeViewHandler(contentView: contentView, backgroundView: bv)
swipeHandler.delegate = self
}
}

extension BWSwipeCell: BWSwipeViewHandlerDelegate {
extension SwipeCell: SwipeViewHandlerDelegate {

public func swipeViewDidStartSwiping(_ handler: BWSwipeViewHandler) {
public func swipeViewDidStartSwiping(_ handler: SwipeViewHandler) {
delegate?.swipeCellDidStartSwiping?(self)
}

public func swipeViewDidSwipe(_ handler: BWSwipeViewHandler) {
public func swipeViewDidSwipe(_ handler: SwipeViewHandler) {
delegate?.swipeCellDidSwipe?(self)
}

public func swipeViewWillRelease(_ handler: BWSwipeViewHandler) {
public func swipeViewWillRelease(_ handler: SwipeViewHandler) {
delegate?.swipeCellWillRelease?(self)
}

public func swipeViewDidCompleteRelease(_ handler: BWSwipeViewHandler) {
public func swipeViewDidCompleteRelease(_ handler: SwipeViewHandler) {
delegate?.swipeCellDidCompleteRelease?(self)
}

public func swipeViewDidChangeState(_ handler: BWSwipeViewHandler) {
public func swipeViewDidChangeState(_ handler: SwipeViewHandler) {
delegate?.swipeCellDidChangeState?(self)
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//
// BWSwipeRevealCell.swift
// BWSwipeCell
// SwipeRevealCell.swift
// SwipeCell
//
// Created by Kyle Newsome on 2015-11-10.
// Copyright © 2015 Kyle Newsome. All rights reserved.
Expand All @@ -9,11 +9,11 @@
import Foundation
import UIKit

@objc public protocol BWSwipeRevealCellDelegate:BWSwipeCellDelegate {
@objc optional func swipeCellActivatedAction(_ cell: BWSwipeCell, isActionLeft: Bool)
@objc public protocol SwipeRevealCellDelegate:SwipeCellDelegate {
@objc optional func swipeCellActivatedAction(_ cell: SwipeCell, isActionLeft: Bool)
}

public class BWSwipeRevealCell: BWSwipeCell {
public class SwipeRevealCell: SwipeCell {

public var backViewbackgroundColor: UIColor = UIColor(white: 0.92, alpha: 1)
private var _backView: UIView?
Expand All @@ -38,7 +38,7 @@ public class BWSwipeRevealCell: BWSwipeCell {
if _leftBackButton == nil {
_leftBackButton = UIButton(frame: CGRect(x: 0, y: 0, width: self.frame.height, height: self.frame.height))
_leftBackButton!.setImage(self.bgViewLeftImage, for: UIControlState())
_leftBackButton!.addTarget(self, action: #selector(BWSwipeRevealCell.leftButtonTapped), for: .touchUpInside)
_leftBackButton!.addTarget(self, action: #selector(SwipeRevealCell.leftButtonTapped), for: .touchUpInside)
_leftBackButton!.tintColor = UIColor.white()
_leftBackButton!.contentMode = .center
self.backView!.addSubview(_leftBackButton!)
Expand All @@ -51,7 +51,7 @@ public class BWSwipeRevealCell: BWSwipeCell {
if _rightBackButton == nil {
_rightBackButton = UIButton(frame: CGRect(x: self.contentView.frame.maxX, y: 0, width: self.frame.height, height: self.frame.height))
_rightBackButton!.setImage(self.bgViewRightImage, for: UIControlState())
_rightBackButton!.addTarget(self, action: #selector(BWSwipeRevealCell.rightButtonTapped), for: .touchUpInside)
_rightBackButton!.addTarget(self, action: #selector(SwipeRevealCell.rightButtonTapped), for: .touchUpInside)
_rightBackButton!.tintColor = UIColor.white()
_rightBackButton!.contentMode = .center
self.backView!.addSubview(_rightBackButton!)
Expand Down Expand Up @@ -91,13 +91,13 @@ public class BWSwipeRevealCell: BWSwipeCell {
super.layoutSubviews()
}

override public func swipeViewDidStartSwiping(_ handler: BWSwipeViewHandler) {
override public func swipeViewDidStartSwiping(_ handler: SwipeViewHandler) {

super.swipeViewDidStartSwiping(handler)
self.backgroundView!.addSubview(self.backView!)
}

override public func swipeViewWillRelease(_ handler: BWSwipeViewHandler) {
override public func swipeViewWillRelease(_ handler: SwipeViewHandler) {

super.swipeViewWillRelease(handler)

Expand All @@ -110,7 +110,7 @@ public class BWSwipeRevealCell: BWSwipeCell {
}
}

override public func swipeViewDidSwipe(_ handler: BWSwipeViewHandler) {
override public func swipeViewDidSwipe(_ handler: SwipeViewHandler) {

super.swipeViewDidSwipe(handler)
//TODO: integrate with content animation
Expand Down Expand Up @@ -211,15 +211,14 @@ public class BWSwipeRevealCell: BWSwipeCell {
public func leftButtonTapped () {
self.shouldCleanUpBackView = true
self.animateCellSpringRelease()
let delegate = self.delegate as? BWSwipeRevealCellDelegate
let delegate = self.delegate as? SwipeRevealCellDelegate
delegate?.swipeCellActivatedAction?(self, isActionLeft: true)
}

public func rightButtonTapped () {
self.shouldCleanUpBackView = true
self.animateCellSpringRelease()
let delegate = self.delegate as? BWSwipeRevealCellDelegate
let delegate = self.delegate as? SwipeRevealCellDelegate
delegate?.swipeCellActivatedAction?(self, isActionLeft: false)
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,47 +2,47 @@ import Foundation
import UIKit


@objc public protocol BWSwipeViewHandlerDelegate: NSObjectProtocol {
@objc optional func swipeViewDidStartSwiping(_ handler: BWSwipeViewHandler)
@objc optional func swipeViewDidSwipe(_ handler: BWSwipeViewHandler)
@objc optional func swipeViewWillRelease(_ handler: BWSwipeViewHandler)
@objc optional func swipeViewDidCompleteRelease(_ handler: BWSwipeViewHandler)
@objc optional func swipeViewDidChangeState(_ handler: BWSwipeViewHandler)
@objc public protocol SwipeViewHandlerDelegate: NSObjectProtocol {
@objc optional func swipeViewDidStartSwiping(_ handler: SwipeViewHandler)
@objc optional func swipeViewDidSwipe(_ handler: SwipeViewHandler)
@objc optional func swipeViewWillRelease(_ handler: SwipeViewHandler)
@objc optional func swipeViewDidCompleteRelease(_ handler: SwipeViewHandler)
@objc optional func swipeViewDidChangeState(_ handler: SwipeViewHandler)
}

//Defines the interaction type of the table cell
public enum BWSwipeCellType: Int {
public enum InteractionType: Int {
case swipeThrough = 0 // swipes with finger and animates through
case springRelease // resists pulling and bounces back
case slidingDoor // swipe to a stopping position where underlying buttons can be revealed
}

public enum BWSwipeCellRevealDirection {
public enum SwipeDirection {
case none
case both
case right
case left
}

public enum BWSwipeCellState {
public enum State {
case normal
case pastThresholdLeft
case pastThresholdRight
}

public class BWSwipeViewHandler: NSObject, UIGestureRecognizerDelegate {
public class SwipeViewHandler: NSObject {

public let backgroundView: UIView
public let contentView: UIView

// The interaction type for this table cell
public var type: BWSwipeCellType = .springRelease
public var type: InteractionType = .springRelease

// The allowable swipe direction(s)
public var revealDirection: BWSwipeCellRevealDirection = .both
public var revealDirection: SwipeDirection = .both

// The current state of the cell (either normal or past a threshold)
public private(set) var state: BWSwipeCellState = .normal
public private(set) var state: State = .normal

// The point at which pan elasticity starts, and `state` changes. Defaults to the height of the `UITableViewCell` (i.e. when it form a perfect square)
public lazy var threshold: CGFloat = {
Expand All @@ -67,9 +67,9 @@ public class BWSwipeViewHandler: NSObject, UIGestureRecognizerDelegate {
public var animationDuration: Double = 0.2

// BWSwipeCell Delegate
public weak var delegate: BWSwipeViewHandlerDelegate?
public weak var delegate: SwipeViewHandlerDelegate?

private lazy var releaseCompletionBlock:((Bool) -> Void)? = {
public lazy var releaseCompletionBlock:((Bool) -> Void)? = {
return {
[weak self] (finished: Bool) in

Expand All @@ -91,7 +91,7 @@ public class BWSwipeViewHandler: NSObject, UIGestureRecognizerDelegate {

super.init()

let panGestureRecognizer: UIPanGestureRecognizer = UIPanGestureRecognizer(target: self, action: #selector(BWSwipeViewHandler.handlePanGesture(_:)))
let panGestureRecognizer: UIPanGestureRecognizer = UIPanGestureRecognizer(target: self, action: #selector(SwipeViewHandler.handlePanGesture(_:)))
panGestureRecognizer.delegate = self
contentView.addGestureRecognizer(panGestureRecognizer)
}
Expand All @@ -102,7 +102,7 @@ public class BWSwipeViewHandler: NSObject, UIGestureRecognizerDelegate {
self.state = .normal
}

func handlePanGesture(_ panGestureRecognizer: UIPanGestureRecognizer) {
public func handlePanGesture(_ panGestureRecognizer: UIPanGestureRecognizer) {
let translation: CGPoint = panGestureRecognizer.translation(in: panGestureRecognizer.view)
var panOffset: CGFloat = translation.x

Expand Down Expand Up @@ -136,7 +136,7 @@ public class BWSwipeViewHandler: NSObject, UIGestureRecognizerDelegate {
}
}

func didStartSwiping() {
public func didStartSwiping() {
delegate?.swipeViewDidStartSwiping?(self)
}

Expand Down Expand Up @@ -181,7 +181,7 @@ public class BWSwipeViewHandler: NSObject, UIGestureRecognizerDelegate {

// MARK: - Reset animations

func animateCellSpringRelease() {
public func animateCellSpringRelease() {
UIView.animate(withDuration: self.animationDuration,
delay: 0,
options: .curveEaseOut,
Expand All @@ -191,7 +191,7 @@ public class BWSwipeViewHandler: NSObject, UIGestureRecognizerDelegate {
completion: self.releaseCompletionBlock)
}

func animateCellSlidingDoor() {
public func animateCellSlidingDoor() {
UIView.animate(withDuration: self.animationDuration,
delay: 0,
options: .allowUserInteraction,
Expand All @@ -206,7 +206,7 @@ public class BWSwipeViewHandler: NSObject, UIGestureRecognizerDelegate {
completion: self.releaseCompletionBlock)
}

func animateCellSwipeThrough() {
public func animateCellSwipeThrough() {
UIView.animate(withDuration: self.animationDuration,
delay: 0,
options: UIViewAnimationOptions.curveLinear,
Expand All @@ -215,12 +215,15 @@ public class BWSwipeViewHandler: NSObject, UIGestureRecognizerDelegate {
self.contentView.frame.origin.x = direction * (self.contentView.bounds.width + self.threshold)
}, completion: self.releaseCompletionBlock)
}


}

extension SwipeViewHandler: UIGestureRecognizerDelegate {

public func gestureRecognizerShouldBegin(_ gestureRecognizer: UIGestureRecognizer) -> Bool {
if gestureRecognizer is UIPanGestureRecognizer && self.revealDirection != .none {
let pan:UIPanGestureRecognizer = gestureRecognizer as! UIPanGestureRecognizer
let translation: CGPoint = pan.translation(in: contentView.superview) //TODO: superview reference may not be accurate
let translation: CGPoint = pan.translation(in: contentView.superview)
return (fabs(translation.x) / fabs(translation.y) > 1) ? true : false
}
return false
Expand Down
Loading

0 comments on commit 3d127d9

Please sign in to comment.