Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix for issue 15 #28

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added .DS_Store
Binary file not shown.
Binary file added Example/.DS_Store
Binary file not shown.
Binary file added Sources/.DS_Store
Binary file not shown.
52 changes: 33 additions & 19 deletions Sources/SwipyCell/SwipyCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ open class SwipyCell: UITableViewCell, SwipyCellTriggerPointEditable {
var firstLeftTrigger: CGFloat!
var firstRightTrigger: CGFloat!

// MARK: - Initialization
// MARK: - Initialization

override public init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
super.init(style: style, reuseIdentifier: reuseIdentifier)
Expand Down Expand Up @@ -113,10 +113,11 @@ open class SwipyCell: UITableViewCell, SwipyCellTriggerPointEditable {
addSubview(contentScreenshotView!)
}

// MARK: - Public Interface
// MARK: - Public Interface

public func addSwipeTrigger(forState state: SwipyCellState, withMode mode: SwipyCellMode, swipeView view: UIView, swipeColor color: UIColor, completion block: SwipyCellTriggerBlock?) {
triggers[state] = SwipyCellTrigger(mode: mode, color: color, view: view, block: block)
checkEmptyTrigger()
}

public func setCompletionBlock(forState state: SwipyCellState, _ block: @escaping SwipyCellTriggerBlock) {
Expand All @@ -130,9 +131,9 @@ open class SwipyCell: UITableViewCell, SwipyCellTriggerPointEditable {
triggers[trigger.key]?.block = block
}
}


// MARK: - Prepare reuse

// MARK: - Prepare reuse

override open func prepareForReuse() {
super.prepareForReuse()
Expand All @@ -155,8 +156,8 @@ open class SwipyCell: UITableViewCell, SwipyCellTriggerPointEditable {
contentScreenshotView!.removeFromSuperview()
contentScreenshotView = nil
}

// MARK: - Gesture Recognition
// MARK: - Gesture Recognition

@objc func handlePanGesture(_ gesture: UIPanGestureRecognizer) {
if shouldDrag == false || isExited == true {
Expand Down Expand Up @@ -229,8 +230,8 @@ open class SwipyCell: UITableViewCell, SwipyCellTriggerPointEditable {

return false
}

// MARK: - Percentage calculations
// MARK: - Percentage calculations

func swipeOffset(withPercentage percentage: CGFloat, relativeToWidth width: CGFloat) -> CGFloat {
var offset = percentage * width
Expand All @@ -255,8 +256,8 @@ open class SwipyCell: UITableViewCell, SwipyCellTriggerPointEditable {

return percentage
}

// MARK: - Animation calculations
// MARK: - Animation calculations

func viewAnimationDuration(withVelocity velocity: CGPoint) -> TimeInterval {
let width = bounds.width
Expand All @@ -271,8 +272,8 @@ open class SwipyCell: UITableViewCell, SwipyCellTriggerPointEditable {

return TimeInterval(SwipyCellConstants.durationHighLimit + SwipyCellConstants.durationLowLimit - fabs(Double(horizontalVelocity / width) * animationDurationDiff))
}

// MARK: - State calculations
// MARK: - State calculations

func swipeDirection(withPercentage percentage: CGFloat) -> SwipyCellDirection {
if percentage < 0 {
Expand Down Expand Up @@ -342,7 +343,7 @@ open class SwipyCell: UITableViewCell, SwipyCellTriggerPointEditable {
return alpha
}

// MARK: - Trigger handling
// MARK: - Trigger handling

func updateTriggerDirections() {
triggerDirections = []
Expand All @@ -363,7 +364,7 @@ open class SwipyCell: UITableViewCell, SwipyCellTriggerPointEditable {
firstRightTrigger = firstTrigger(forDirection: .right)
}

// MARK: - Animations / View movement
// MARK: - Animations / View movement

func animate(withOffset offset: CGFloat) {
let percentage = swipePercentage(withOffset: offset, relativeToWidth: bounds.width)
Expand All @@ -379,7 +380,7 @@ open class SwipyCell: UITableViewCell, SwipyCellTriggerPointEditable {
let color = swipeColor(withSwipeState: state)
colorIndicatorView.backgroundColor = color
}

func slideSwipeView(withPercentage percentage: CGFloat, view: UIView?, isDragging: Bool) {
guard let view = view else { return }

Expand Down Expand Up @@ -412,7 +413,7 @@ open class SwipyCell: UITableViewCell, SwipyCellTriggerPointEditable {
} else if direction == .left {
position.x = min(position.x, bounds.width - view.bounds.width - swipeViewPadding / 2.0)
}

let activeViewSize = view.bounds.size
var activeViewFrame = CGRect(x: position.x - activeViewSize.width / 2.0,
y: position.y - activeViewSize.height / 2.0,
Expand Down Expand Up @@ -470,7 +471,7 @@ open class SwipyCell: UITableViewCell, SwipyCellTriggerPointEditable {
})
}

// MARK: - View setup
// MARK: - View setup

func setView(ofSlidingView view: UIView) {
let subviews = slidingView.subviews
Expand All @@ -479,8 +480,8 @@ open class SwipyCell: UITableViewCell, SwipyCellTriggerPointEditable {
}
slidingView.addSubview(view)
}

// MARK: - Utilities
// MARK: - Utilities

func image(withView view: UIView) -> UIImage {
let scale = UIScreen.main.scale
Expand Down Expand Up @@ -522,4 +523,17 @@ open class SwipyCell: UITableViewCell, SwipyCellTriggerPointEditable {
return false
}


// MARK: - Empty Trigger Configure
func checkEmptyTrigger() {
if triggers[SwipyCellState.state(1, .left)]?.view != nil,
triggers[SwipyCellState.state(0, .left)]?.view == nil {
triggers[SwipyCellState.state(0, .left)] = triggers[SwipyCellState.state(1, .left)]
}

if triggers[SwipyCellState.state(0, .right)]?.view != nil,
triggers[SwipyCellState.state(1, .right)]?.view == nil {
triggers[SwipyCellState.state(1, .right)] = triggers[SwipyCellState.state(0, .right)]
}
}
}