From f0a7453854f167a6017f903bfda6f9b5937168ae Mon Sep 17 00:00:00 2001 From: brownsoo han Date: Mon, 26 Feb 2018 16:31:04 +0900 Subject: [PATCH 01/37] Changed the accessibility of DraggableCardView's contentView --- .../KolodaView/DraggableCardView/DraggableCardView.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Pod/Classes/KolodaView/DraggableCardView/DraggableCardView.swift b/Pod/Classes/KolodaView/DraggableCardView/DraggableCardView.swift index 00330c66..bd716868 100644 --- a/Pod/Classes/KolodaView/DraggableCardView/DraggableCardView.swift +++ b/Pod/Classes/KolodaView/DraggableCardView/DraggableCardView.swift @@ -57,7 +57,7 @@ public class DraggableCardView: UIView, UIGestureRecognizerDelegate { } private var overlayView: OverlayView? - private(set) var contentView: UIView? + public private(set) var contentView: UIView? private var panGestureRecognizer: UIPanGestureRecognizer! private var tapGestureRecognizer: UITapGestureRecognizer! From 1170af005b71d57ab10cccad3e2cccd81a035e94 Mon Sep 17 00:00:00 2001 From: LorenzOliveto Date: Fri, 14 Sep 2018 11:00:54 +0200 Subject: [PATCH 02/37] Added the possibility to have the card stack at the top or at the bottom. --- Pod/Classes/KolodaView/KolodaView.swift | 31 ++++++++++++++++++++----- 1 file changed, 25 insertions(+), 6 deletions(-) diff --git a/Pod/Classes/KolodaView/KolodaView.swift b/Pod/Classes/KolodaView/KolodaView.swift index b42ba115..a1f10dd4 100644 --- a/Pod/Classes/KolodaView/KolodaView.swift +++ b/Pod/Classes/KolodaView/KolodaView.swift @@ -9,6 +9,12 @@ import UIKit import pop +// Direction of visible cards +public enum VisibleCardsDirection: Int { + case top + case bottom +} + //Default values private let defaultCountOfVisibleCards = 3 private let defaultBackgroundCardsTopMargin: CGFloat = 4.0 @@ -96,6 +102,9 @@ open class KolodaView: UIView, DraggableCardDelegate { public var appearanceAnimationDuration = defaultAppearanceAnimationDuration + // Visible cards direction (defaults to bottom) + public var visibleCardsDirection: VisibleCardsDirection = .bottom + public weak var dataSource: KolodaViewDataSource? { didSet { setupDeck() @@ -194,12 +203,22 @@ open class KolodaView: UIView, DraggableCardDelegate { let width = self.frame.width * pow(scalePercent, CGFloat(index)) let xOffset = (self.frame.width - width) / 2 let height = (self.frame.height - bottomOffset - topOffset) * pow(scalePercent, CGFloat(index)) - let multiplier: CGFloat = index > 0 ? 1.0 : 0.0 - let prevCardFrame = index > 0 ? frameForCard(at: max(index - 1, 0)) : .zero - let yOffset = (prevCardFrame.height - height + prevCardFrame.origin.y + defaultBackgroundCardsTopMargin) * multiplier - let frame = CGRect(x: xOffset, y: yOffset, width: width, height: height) - - return frame + + if visibleCardsDirection == .bottom { + let multiplier: CGFloat = index > 0 ? 1.0 : 0.0 + let prevCardFrame = index > 0 ? frameForCard(at: max(index - 1, 0)) : .zero + let yOffset = (prevCardFrame.height - height + prevCardFrame.origin.y + defaultBackgroundCardsTopMargin) * multiplier + let frame = CGRect(x: xOffset, y: yOffset, width: width, height: height) + + return frame + } else { + let multiplier: CGFloat = index < (countOfVisibleCards - 1) ? 1.0 : 0.0 + let nextCardFrame = index < (countOfVisibleCards - 1) ? frameForCard(at: min(index + 1, (countOfVisibleCards - 1))) : .zero + let yOffset = (nextCardFrame.origin.y + defaultBackgroundCardsTopMargin) * multiplier + let frame = CGRect(x: xOffset, y: yOffset, width: width, height: height) + + return frame + } } internal func frameForTopCard() -> CGRect { From 8ad914c603f8a375f071e1d23e18f7e708eb3234 Mon Sep 17 00:00:00 2001 From: Leonardo Herbert Date: Fri, 28 Sep 2018 09:06:51 -0300 Subject: [PATCH 03/37] public defaulValues --- Pod/Classes/KolodaView/KolodaView.swift | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/Pod/Classes/KolodaView/KolodaView.swift b/Pod/Classes/KolodaView/KolodaView.swift index b42ba115..992b82fe 100644 --- a/Pod/Classes/KolodaView/KolodaView.swift +++ b/Pod/Classes/KolodaView/KolodaView.swift @@ -94,8 +94,6 @@ open class KolodaView: UIView, DraggableCardDelegate { public var rotationAngle: CGFloat? public var scaleMin: CGFloat? - public var appearanceAnimationDuration = defaultAppearanceAnimationDuration - public weak var dataSource: KolodaViewDataSource? { didSet { setupDeck() @@ -131,6 +129,13 @@ open class KolodaView: UIView, DraggableCardDelegate { private(set) public var currentCardIndex = 0 private(set) public var countOfCards = 0 public var countOfVisibleCards = defaultCountOfVisibleCards + public var backgroundCardsTopMargin = defaultBackgroundCardsTopMargin + public var backgroundCardsScalePercent = defaultBackgroundCardsScalePercent + public var backgroundCardFrameAnimationDuration = defaultBackgroundCardFrameAnimationDuration + public var appearanceAnimationDuration = defaultAppearanceAnimationDuration + public var reverseAnimationDuration = defaultReverseAnimationDuration + + private var visibleCards = [DraggableCardView]() public var isLoop = false @@ -189,14 +194,14 @@ open class KolodaView: UIView, DraggableCardDelegate { // MARK: Frames open func frameForCard(at index: Int) -> CGRect { let bottomOffset: CGFloat = 0 - let topOffset = defaultBackgroundCardsTopMargin * CGFloat(countOfVisibleCards - 1) - let scalePercent = defaultBackgroundCardsScalePercent + let topOffset = backgroundCardsTopMargin * CGFloat(countOfVisibleCards - 1) + let scalePercent = backgroundCardsScalePercent let width = self.frame.width * pow(scalePercent, CGFloat(index)) let xOffset = (self.frame.width - width) / 2 let height = (self.frame.height - bottomOffset - topOffset) * pow(scalePercent, CGFloat(index)) let multiplier: CGFloat = index > 0 ? 1.0 : 0.0 let prevCardFrame = index > 0 ? frameForCard(at: max(index - 1, 0)) : .zero - let yOffset = (prevCardFrame.height - height + prevCardFrame.origin.y + defaultBackgroundCardsTopMargin) * multiplier + let yOffset = (prevCardFrame.height - height + prevCardFrame.origin.y + backgroundCardsTopMargin) * multiplier let frame = CGRect(x: xOffset, y: yOffset, width: width, height: height) return frame @@ -458,7 +463,7 @@ open class KolodaView: UIView, DraggableCardDelegate { currentCard, scale: cardParameters.scale, frame: cardParameters.frame, - duration: defaultBackgroundCardFrameAnimationDuration, + duration: backgroundCardFrameAnimationDuration, completion: animationCompletion ) } @@ -488,7 +493,7 @@ open class KolodaView: UIView, DraggableCardDelegate { visibleCards.insert(firstCardView, at: 0) animationSemaphore.increment() - animator.applyReverseAnimation(firstCardView, direction: direction, duration: defaultReverseAnimationDuration, completion: { [weak self] _ in + animator.applyReverseAnimation(firstCardView, direction: direction, duration: reverseAnimationDuration, completion: { [weak self] _ in guard let _self = self else { return } @@ -509,7 +514,7 @@ open class KolodaView: UIView, DraggableCardDelegate { card, scale: cardParameters.scale, frame: cardParameters.frame, - duration: defaultBackgroundCardFrameAnimationDuration, + duration: backgroundCardFrameAnimationDuration, completion: nil ) } From 12d73e21cb842d301537fc42e56b3fcd1c1f0c55 Mon Sep 17 00:00:00 2001 From: Max Sysenko Date: Thu, 8 Nov 2018 18:06:16 +0200 Subject: [PATCH 04/37] Add `backgroundCardsTopMargin` property as public --- Pod/Classes/KolodaView/KolodaView.swift | 35 ++++++++++++++----------- 1 file changed, 19 insertions(+), 16 deletions(-) diff --git a/Pod/Classes/KolodaView/KolodaView.swift b/Pod/Classes/KolodaView/KolodaView.swift index f3d74a72..7e9894cd 100644 --- a/Pod/Classes/KolodaView/KolodaView.swift +++ b/Pod/Classes/KolodaView/KolodaView.swift @@ -36,10 +36,10 @@ public extension KolodaViewDataSource { func koloda(_ koloda: KolodaView, viewForCardOverlayAt index: Int) -> OverlayView? { return nil } - + func kolodaSpeedThatCardShouldDrag(_ koloda: KolodaView) -> DragSpeed { - return .default - } + return .default + } } public protocol KolodaViewDelegate: class { @@ -88,14 +88,17 @@ open class KolodaView: UIView, DraggableCardDelegate { public var alphaValueTransparent = defaultAlphaValueTransparent public var alphaValueSemiTransparent = defaultAlphaValueSemiTransparent public var shouldPassthroughTapsWhenNoVisibleCards = false - + public var backgroundCardsTopMargin = defaultBackgroundCardsTopMargin + + public var scaleMin: CGFloat? + //Drag animation constants public var rotationMax: CGFloat? public var rotationAngle: CGFloat? - public var scaleMin: CGFloat? - + + public var appearanceAnimationDuration = defaultAppearanceAnimationDuration - + public weak var dataSource: KolodaViewDataSource? { didSet { setupDeck() @@ -122,7 +125,7 @@ open class KolodaView: UIView, DraggableCardDelegate { } internal var animationSemaphore = KolodaAnimationSemaphore() - + public var isRunOutOfCards: Bool { return visibleCards.isEmpty @@ -147,7 +150,7 @@ open class KolodaView: UIView, DraggableCardDelegate { private func setupDeck() { if let dataSource = dataSource { countOfCards = dataSource.kolodaNumberOfCards(self) - + if countOfCards - currentCardIndex > 0 { let countOfNeededCards = min(countOfVisibleCards, countOfCards - currentCardIndex) @@ -189,14 +192,14 @@ open class KolodaView: UIView, DraggableCardDelegate { // MARK: Frames open func frameForCard(at index: Int) -> CGRect { let bottomOffset: CGFloat = 0 - let topOffset = defaultBackgroundCardsTopMargin * CGFloat(countOfVisibleCards - 1) + let topOffset = backgroundCardsTopMargin * CGFloat(countOfVisibleCards - 1) let scalePercent = defaultBackgroundCardsScalePercent let width = self.frame.width * pow(scalePercent, CGFloat(index)) let xOffset = (self.frame.width - width) / 2 let height = (self.frame.height - bottomOffset - topOffset) * pow(scalePercent, CGFloat(index)) let multiplier: CGFloat = index > 0 ? 1.0 : 0.0 let prevCardFrame = index > 0 ? frameForCard(at: max(index - 1, 0)) : .zero - let yOffset = (prevCardFrame.height - height + prevCardFrame.origin.y + defaultBackgroundCardsTopMargin) * multiplier + let yOffset = (prevCardFrame.height - height + prevCardFrame.origin.y + backgroundCardsTopMargin) * multiplier let frame = CGRect(x: xOffset, y: yOffset, width: width, height: height) return frame @@ -346,19 +349,19 @@ open class KolodaView: UIView, DraggableCardDelegate { let index = currentCardIndex + visibleIndex return delegate?.koloda(self, shouldDragCardAt: index) ?? true } - + func card(cardSwipeSpeed card: DraggableCardView) -> DragSpeed { return dataSource?.kolodaSpeedThatCardShouldDrag(self) ?? DragSpeed.default } - + func card(cardPanBegan card: DraggableCardView) { delegate?.kolodaPanBegan(self, card: card) } - + func card(cardPanFinished card: DraggableCardView) { delegate?.kolodaPanFinished(self, card: card) } - + // MARK: Private private func clear() { currentCardIndex = 0 @@ -386,7 +389,7 @@ open class KolodaView: UIView, DraggableCardDelegate { || (isLoop && realCountOfCards > 0 && realCountOfCards > visibleCards.count) { loadNextCard() } - + if !visibleCards.isEmpty { animateCardsAfterLoadingWithCompletion { [weak self] in guard let _self = self else { From 0cc0922eccee6b56f9595165e0a8c2538ed7e90c Mon Sep 17 00:00:00 2001 From: Max Sysenko Date: Fri, 9 Nov 2018 11:11:52 +0200 Subject: [PATCH 05/37] Add ability to silently swipe a card --- .../DraggableCardView/DraggableCardView.swift | 28 +++++++++---------- Pod/Classes/KolodaView/KolodaView.swift | 13 +++++---- 2 files changed, 21 insertions(+), 20 deletions(-) diff --git a/Pod/Classes/KolodaView/DraggableCardView/DraggableCardView.swift b/Pod/Classes/KolodaView/DraggableCardView/DraggableCardView.swift index fc698d98..d839dcf2 100644 --- a/Pod/Classes/KolodaView/DraggableCardView/DraggableCardView.swift +++ b/Pod/Classes/KolodaView/DraggableCardView/DraggableCardView.swift @@ -19,7 +19,7 @@ public enum DragSpeed: TimeInterval { protocol DraggableCardDelegate: class { func card(_ card: DraggableCardView, wasDraggedWithFinishPercentage percentage: CGFloat, inDirection direction: SwipeResultDirection) - func card(_ card: DraggableCardView, wasSwipedIn direction: SwipeResultDirection) + func card(_ card: DraggableCardView, wasSwipedIn direction: SwipeResultDirection, forced: Bool) func card(_ card: DraggableCardView, shouldSwipeIn direction: SwipeResultDirection) -> Bool func card(cardWasReset card: DraggableCardView) func card(cardWasTapped card: DraggableCardView) @@ -46,7 +46,7 @@ private let cardResetAnimationDuration: TimeInterval = 0.2 internal var cardSwipeActionAnimationDuration: TimeInterval = DragSpeed.default.rawValue public class DraggableCardView: UIView, UIGestureRecognizerDelegate { - + //Drag animation constants public var rotationMax = defaultRotationMax public var rotationAngle = defaultRotationAngle @@ -67,7 +67,7 @@ public class DraggableCardView: UIView, UIGestureRecognizerDelegate { private var dragBegin = false private var dragDistance = CGPoint.zero private var swipePercentageMargin: CGFloat = 0.0 - + //MARK: Lifecycle init() { @@ -108,7 +108,7 @@ public class DraggableCardView: UIView, UIGestureRecognizerDelegate { tapGestureRecognizer.delegate = self tapGestureRecognizer.cancelsTouchesInView = false addGestureRecognizer(tapGestureRecognizer) - + if let delegate = delegate { cardSwipeActionAnimationDuration = delegate.card(cardSwipeSpeed: self).rawValue } @@ -128,11 +128,11 @@ public class DraggableCardView: UIView, UIGestureRecognizerDelegate { } else { self.addSubview(view) } - + self.contentView = view configureContentView() } - + private func configureOverlayView() { if let overlay = self.overlayView { overlay.translatesAutoresizingMaskIntoConstraints = false @@ -249,7 +249,7 @@ public class DraggableCardView: UIView, UIGestureRecognizerDelegate { let rotationAngle = animationDirectionY * self.rotationAngle * rotationStrength let scaleStrength = 1 - ((1 - scaleMin) * abs(rotationStrength)) let scale = max(scaleStrength, scaleMin) - + var transform = CATransform3DIdentity transform = CATransform3DScale(transform, scale, scale, 1) transform = CATransform3DRotate(transform, rotationAngle, 0, 0, 1) @@ -302,7 +302,7 @@ public class DraggableCardView: UIView, UIGestureRecognizerDelegate { return (distance, direction) } return closest - }.direction + }.direction } private var dragPercentage: CGFloat { @@ -324,9 +324,9 @@ public class DraggableCardView: UIView, UIGestureRecognizerDelegate { // check 4 borders for intersection with line between touchpoint and center of card // return smallest percentage of distance to edge point or 0 return rect.perimeterLines - .compactMap { CGPoint.intersectionBetweenLines(targetLine, line2: $0) } - .map { centerDistance / $0.distanceTo(.zero) } - .min() ?? 0 + .compactMap { CGPoint.intersectionBetweenLines(targetLine, line2: $0) } + .map { centerDistance / $0.distanceTo(.zero) } + .min() ?? 0 } } @@ -362,7 +362,7 @@ public class DraggableCardView: UIView, UIGestureRecognizerDelegate { private func swipeAction(_ direction: SwipeResultDirection) { overlayView?.overlayState = direction overlayView?.alpha = 1.0 - delegate?.card(self, wasSwipedIn: direction) + delegate?.card(self, wasSwipedIn: direction, forced: false) let translationAnimation = POPBasicAnimation(propertyNamed: kPOPLayerTranslationXY) translationAnimation?.duration = cardSwipeActionAnimationDuration translationAnimation?.fromValue = NSValue(cgPoint: POPLayerGetTranslationXY(layer)) @@ -418,9 +418,9 @@ public class DraggableCardView: UIView, UIGestureRecognizerDelegate { layer.pop_removeAllAnimations() } - func swipe(_ direction: SwipeResultDirection, completionHandler: @escaping () -> Void) { + func swipe(_ direction: SwipeResultDirection, forced: Bool = false, completionHandler: @escaping () -> Void) { if !dragBegin { - delegate?.card(self, wasSwipedIn: direction) + delegate?.card(self, wasSwipedIn: direction, forced: forced) let swipePositionAnimation = POPBasicAnimation(propertyNamed: kPOPLayerTranslationXY) swipePositionAnimation?.fromValue = NSValue(cgPoint:POPLayerGetTranslationXY(layer)) diff --git a/Pod/Classes/KolodaView/KolodaView.swift b/Pod/Classes/KolodaView/KolodaView.swift index 7e9894cd..69624f8c 100644 --- a/Pod/Classes/KolodaView/KolodaView.swift +++ b/Pod/Classes/KolodaView/KolodaView.swift @@ -304,8 +304,8 @@ open class KolodaView: UIView, DraggableCardDelegate { return delegate?.koloda(self, allowedDirectionsForIndex: index) ?? [.left, .right] } - func card(_ card: DraggableCardView, wasSwipedIn direction: SwipeResultDirection) { - swipedAction(direction) + func card(_ card: DraggableCardView, wasSwipedIn direction: SwipeResultDirection, forced: Bool) { + swipedAction(direction, manually: forced) } func card(cardWasReset card: DraggableCardView) { @@ -374,7 +374,7 @@ open class KolodaView: UIView, DraggableCardDelegate { } // MARK: Actions - private func swipedAction(_ direction: SwipeResultDirection) { + private func swipedAction(_ direction: SwipeResultDirection, manually: Bool = false) { animationSemaphore.increment() visibleCards.removeFirst() @@ -398,12 +398,13 @@ open class KolodaView: UIView, DraggableCardDelegate { _self.visibleCards.last?.isHidden = false _self.animationSemaphore.decrement() - _self.delegate?.koloda(_self, didSwipeCardAt: swipedCardIndex, in: direction) + + if !manually { _self.delegate?.koloda(_self, didSwipeCardAt: swipedCardIndex, in: direction) } _self.delegate?.koloda(_self, didShowCardAt: _self.currentCardIndex) } } else { animationSemaphore.decrement() - delegate?.koloda(self, didSwipeCardAt: swipedCardIndex, in: direction) + if !manually { delegate?.koloda(self, didSwipeCardAt: swipedCardIndex, in: direction) } delegate?.kolodaDidRunOutOfCards(self) } } @@ -593,7 +594,7 @@ open class KolodaView: UIView, DraggableCardDelegate { animationSemaphore.increment() - frontCard.swipe(direction) { + frontCard.swipe(direction, forced: force) { self.animationSemaphore.decrement() } frontCard.delegate = nil From dc5832e36d01cc8ebb994b5fcf6c7d54951dc4dd Mon Sep 17 00:00:00 2001 From: Max Sysenko Date: Mon, 12 Nov 2018 16:49:16 +0200 Subject: [PATCH 06/37] Add willShow method delegate --- Pod/Classes/KolodaView/KolodaView.swift | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Pod/Classes/KolodaView/KolodaView.swift b/Pod/Classes/KolodaView/KolodaView.swift index 69624f8c..a94f6752 100644 --- a/Pod/Classes/KolodaView/KolodaView.swift +++ b/Pod/Classes/KolodaView/KolodaView.swift @@ -55,6 +55,7 @@ public protocol KolodaViewDelegate: class { func koloda(_ koloda: KolodaView, draggedCardWithPercentage finishPercentage: CGFloat, in direction: SwipeResultDirection) func kolodaDidResetCard(_ koloda: KolodaView) func kolodaSwipeThresholdRatioMargin(_ koloda: KolodaView) -> CGFloat? + func koloda(_ koloda: KolodaView, willShow card: UIView, at index: Int) func koloda(_ koloda: KolodaView, didShowCardAt index: Int) func koloda(_ koloda: KolodaView, shouldDragCardAt index: Int ) -> Bool func kolodaPanBegan(_ koloda: KolodaView, card: DraggableCardView) @@ -432,6 +433,7 @@ open class KolodaView: UIView, DraggableCardDelegate { } else { addSubview(lastCard) } + delegate?.koloda(self, willShow: lastCard, at: indexToBeMake) visibleCards.append(lastCard) } From ee64d1d360d6338f248fbca2e18244a9f35779f1 Mon Sep 17 00:00:00 2001 From: Max Sysenko Date: Thu, 15 Nov 2018 14:02:40 +0200 Subject: [PATCH 07/37] Remove restriction for swiping speed --- Pod/Classes/KolodaView/KolodaView.swift | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/Pod/Classes/KolodaView/KolodaView.swift b/Pod/Classes/KolodaView/KolodaView.swift index a94f6752..3c61aa0c 100644 --- a/Pod/Classes/KolodaView/KolodaView.swift +++ b/Pod/Classes/KolodaView/KolodaView.swift @@ -587,20 +587,14 @@ open class KolodaView: UIView, DraggableCardDelegate { } public func swipe(_ direction: SwipeResultDirection, force: Bool = false) { - if !animationSemaphore.isAnimating { - if let frontCard = visibleCards.first { - if visibleCards.count > 1 { - let nextCard = visibleCards[1] - nextCard.alpha = shouldTransparentizeNextCard ? alphaValueSemiTransparent : alphaValueOpaque - } - - animationSemaphore.increment() - - frontCard.swipe(direction, forced: force) { - self.animationSemaphore.decrement() - } - frontCard.delegate = nil + if let frontCard = visibleCards.first { + if visibleCards.count > 1 { + let nextCard = visibleCards[1] + nextCard.alpha = shouldTransparentizeNextCard ? alphaValueSemiTransparent : alphaValueOpaque } + + frontCard.swipe(direction, forced: force) {} + frontCard.delegate = nil } } From 3470c2cbdca7437cd5ec3935fa9d745eb3f180a6 Mon Sep 17 00:00:00 2001 From: Sroik Date: Wed, 5 Dec 2018 17:51:09 +0300 Subject: [PATCH 08/37] little publicity --- Pod/Classes/KolodaView/KolodaView.swift | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/Pod/Classes/KolodaView/KolodaView.swift b/Pod/Classes/KolodaView/KolodaView.swift index b42ba115..fd5d20d9 100644 --- a/Pod/Classes/KolodaView/KolodaView.swift +++ b/Pod/Classes/KolodaView/KolodaView.swift @@ -88,13 +88,16 @@ open class KolodaView: UIView, DraggableCardDelegate { public var alphaValueTransparent = defaultAlphaValueTransparent public var alphaValueSemiTransparent = defaultAlphaValueSemiTransparent public var shouldPassthroughTapsWhenNoVisibleCards = false - + //Drag animation constants public var rotationMax: CGFloat? public var rotationAngle: CGFloat? public var scaleMin: CGFloat? + //Animation durations public var appearanceAnimationDuration = defaultAppearanceAnimationDuration + public var backgroundCardFrameAnimationDuration = defaultBackgroundCardFrameAnimationDuration + public var reverseAnimationDuration = defaultReverseAnimationDuration public weak var dataSource: KolodaViewDataSource? { didSet { @@ -113,6 +116,10 @@ open class KolodaView: UIView, DraggableCardDelegate { } } + public var isAnimating: Bool { + return animationSemaphore.isAnimating + } + private lazy var _animator: KolodaViewAnimator = { return KolodaViewAnimator(koloda: self) }() @@ -458,7 +465,7 @@ open class KolodaView: UIView, DraggableCardDelegate { currentCard, scale: cardParameters.scale, frame: cardParameters.frame, - duration: defaultBackgroundCardFrameAnimationDuration, + duration: backgroundCardFrameAnimationDuration, completion: animationCompletion ) } @@ -488,7 +495,7 @@ open class KolodaView: UIView, DraggableCardDelegate { visibleCards.insert(firstCardView, at: 0) animationSemaphore.increment() - animator.applyReverseAnimation(firstCardView, direction: direction, duration: defaultReverseAnimationDuration, completion: { [weak self] _ in + animator.applyReverseAnimation(firstCardView, direction: direction, duration: reverseAnimationDuration, completion: { [weak self] _ in guard let _self = self else { return } @@ -509,7 +516,7 @@ open class KolodaView: UIView, DraggableCardDelegate { card, scale: cardParameters.scale, frame: cardParameters.frame, - duration: defaultBackgroundCardFrameAnimationDuration, + duration: backgroundCardFrameAnimationDuration, completion: nil ) } @@ -537,7 +544,7 @@ open class KolodaView: UIView, DraggableCardDelegate { } } - private func reconfigureCards() { + public func reconfigureCards() { if dataSource != nil { for (index, card) in visibleCards.enumerated() { var actualIndex = currentCardIndex + index From 6356d029a771f2bf3472b6afb72df6d63eaa519a Mon Sep 17 00:00:00 2001 From: Max Sysenko Date: Mon, 10 Dec 2018 12:55:45 +0200 Subject: [PATCH 09/37] Call `willShow` delegate method upon appearing --- Pod/Classes/KolodaView/KolodaView.swift | 1 + 1 file changed, 1 insertion(+) diff --git a/Pod/Classes/KolodaView/KolodaView.swift b/Pod/Classes/KolodaView/KolodaView.swift index 3c61aa0c..9866f3c3 100644 --- a/Pod/Classes/KolodaView/KolodaView.swift +++ b/Pod/Classes/KolodaView/KolodaView.swift @@ -165,6 +165,7 @@ open class KolodaView: UIView, DraggableCardDelegate { nextCardView.alpha = alphaValueSemiTransparent } visibleCards.append(nextCardView) + if isTop { delegate?.koloda(self, willShow: nextCardView, at: index) } isTop ? addSubview(nextCardView) : insertSubview(nextCardView, belowSubview: visibleCards[index - 1]) } self.delegate?.koloda(self, didShowCardAt: currentCardIndex) From ddeb293b160b35faea3893974fbfe2d06731e1f9 Mon Sep 17 00:00:00 2001 From: rnkyr Date: Tue, 25 Dec 2018 12:14:02 +0200 Subject: [PATCH 10/37] [refactor] re-arrange public fields --- Example/Koloda.xcodeproj/project.pbxproj | 16 ++--- .../xcschemes/Koloda-Example.xcscheme | 2 +- Pod/Classes/KolodaView/KolodaView.swift | 58 +++++++++---------- 3 files changed, 36 insertions(+), 40 deletions(-) diff --git a/Example/Koloda.xcodeproj/project.pbxproj b/Example/Koloda.xcodeproj/project.pbxproj index be195c9e..66be3329 100644 --- a/Example/Koloda.xcodeproj/project.pbxproj +++ b/Example/Koloda.xcodeproj/project.pbxproj @@ -62,11 +62,11 @@ 607FACC71AFB9204008FA782 = { isa = PBXGroup; children = ( - 607FACF51AFB993E008FA782 /* Podspec Metadata */, 607FACD21AFB9204008FA782 /* Example */, - 607FACD11AFB9204008FA782 /* Products */, - AB88095976C7B6CA809587FB /* Pods */, 85B3405D0F2A73D9A709B3FA /* Frameworks */, + AB88095976C7B6CA809587FB /* Pods */, + 607FACF51AFB993E008FA782 /* Podspec Metadata */, + 607FACD11AFB9204008FA782 /* Products */, ); sourceTree = ""; }; @@ -82,18 +82,18 @@ isa = PBXGroup; children = ( 607FACD51AFB9204008FA782 /* AppDelegate.swift */, - 607FACD71AFB9204008FA782 /* ViewController.swift */, 440FB7681B515995009FC9FC /* BackgroundAnimationViewController.swift */, 446BFD081CB0184A00619E78 /* BackgroundKolodaAnimator.swift */, - 4420661E1B4457E800FD4CAD /* ExampleOverlayView.swift */, 440FB7661B51499A009FC9FC /* CustomKolodaView.swift */, 44B5EC281B660C8500895E3D /* CustomOverlayView.swift */, - 607FACD91AFB9204008FA782 /* Main.storyboard */, + 44B5EC2A1B660C9100895E3D /* CustomOverlayView.xib */, + 4420661E1B4457E800FD4CAD /* ExampleOverlayView.swift */, 607FACDC1AFB9204008FA782 /* Images.xcassets */, 607FACDE1AFB9204008FA782 /* LaunchScreen.xib */, + 607FACD91AFB9204008FA782 /* Main.storyboard */, 4420661B1B44577500FD4CAD /* OverlayView.xib */, - 44B5EC2A1B660C9100895E3D /* CustomOverlayView.xib */, 607FACD31AFB9204008FA782 /* Supporting Files */, + 607FACD71AFB9204008FA782 /* ViewController.swift */, ); name = Example; path = Koloda; @@ -111,8 +111,8 @@ isa = PBXGroup; children = ( D6781607B5327BAF503C32E3 /* Koloda.podspec */, - 8C6AF94B3192C604963C53B3 /* README.md */, 5C6DBB80685DABAE785B8715 /* LICENSE */, + 8C6AF94B3192C604963C53B3 /* README.md */, ); name = "Podspec Metadata"; sourceTree = ""; diff --git a/Example/Koloda.xcodeproj/xcshareddata/xcschemes/Koloda-Example.xcscheme b/Example/Koloda.xcodeproj/xcshareddata/xcschemes/Koloda-Example.xcscheme index 3d1759a0..2c9439c8 100644 --- a/Example/Koloda.xcodeproj/xcshareddata/xcschemes/Koloda-Example.xcscheme +++ b/Example/Koloda.xcodeproj/xcshareddata/xcschemes/Koloda-Example.xcscheme @@ -1,6 +1,6 @@ Date: Tue, 25 Dec 2018 12:36:07 +0200 Subject: [PATCH 11/37] Xcode 9 and Xcode 10 Swift version support --- .../DraggableCardView/DraggableCardView.swift | 48 +++++++++---------- 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/Pod/Classes/KolodaView/DraggableCardView/DraggableCardView.swift b/Pod/Classes/KolodaView/DraggableCardView/DraggableCardView.swift index d030292a..a5cb23f5 100644 --- a/Pod/Classes/KolodaView/DraggableCardView/DraggableCardView.swift +++ b/Pod/Classes/KolodaView/DraggableCardView/DraggableCardView.swift @@ -139,34 +139,34 @@ public class DraggableCardView: UIView, UIGestureRecognizerDelegate { let width = NSLayoutConstraint( item: overlay, - attribute: NSLayoutConstraint.Attribute.width, - relatedBy: NSLayoutConstraint.Relation.equal, + attribute: .width, + relatedBy: .equal, toItem: self, - attribute: NSLayoutConstraint.Attribute.width, + attribute: .width, multiplier: 1.0, constant: 0) let height = NSLayoutConstraint( item: overlay, - attribute: NSLayoutConstraint.Attribute.height, - relatedBy: NSLayoutConstraint.Relation.equal, + attribute: .height, + relatedBy: .equal, toItem: self, - attribute: NSLayoutConstraint.Attribute.height, + attribute: .height, multiplier: 1.0, constant: 0) let top = NSLayoutConstraint ( item: overlay, - attribute: NSLayoutConstraint.Attribute.top, - relatedBy: NSLayoutConstraint.Relation.equal, + attribute: .top, + relatedBy: .equal, toItem: self, - attribute: NSLayoutConstraint.Attribute.top, + attribute: .top, multiplier: 1.0, constant: 0) let leading = NSLayoutConstraint ( item: overlay, - attribute: NSLayoutConstraint.Attribute.leading, - relatedBy: NSLayoutConstraint.Relation.equal, + attribute: .leading, + relatedBy: .equal, toItem: self, - attribute: NSLayoutConstraint.Attribute.leading, + attribute: .leading, multiplier: 1.0, constant: 0) addConstraints([width,height,top,leading]) @@ -179,34 +179,34 @@ public class DraggableCardView: UIView, UIGestureRecognizerDelegate { let width = NSLayoutConstraint( item: contentView, - attribute: NSLayoutConstraint.Attribute.width, - relatedBy: NSLayoutConstraint.Relation.equal, + attribute: .width, + relatedBy: .equal, toItem: self, - attribute: NSLayoutConstraint.Attribute.width, + attribute: .width, multiplier: 1.0, constant: 0) let height = NSLayoutConstraint( item: contentView, - attribute: NSLayoutConstraint.Attribute.height, - relatedBy: NSLayoutConstraint.Relation.equal, + attribute: .height, + relatedBy: .equal, toItem: self, - attribute: NSLayoutConstraint.Attribute.height, + attribute: .height, multiplier: 1.0, constant: 0) let top = NSLayoutConstraint ( item: contentView, - attribute: NSLayoutConstraint.Attribute.top, - relatedBy: NSLayoutConstraint.Relation.equal, + attribute: .top, + relatedBy: .equal, toItem: self, - attribute: NSLayoutConstraint.Attribute.top, + attribute: .top, multiplier: 1.0, constant: 0) let leading = NSLayoutConstraint ( item: contentView, - attribute: NSLayoutConstraint.Attribute.leading, - relatedBy: NSLayoutConstraint.Relation.equal, + attribute: .leading, + relatedBy: .equal, toItem: self, - attribute: NSLayoutConstraint.Attribute.leading, + attribute: .leading, multiplier: 1.0, constant: 0) From a4d8dfca42d9ec14f116e644005f02c56202ecca Mon Sep 17 00:00:00 2001 From: rnkyr Date: Tue, 25 Dec 2018 12:36:19 +0200 Subject: [PATCH 12/37] [update] swift to 4.2 --- Example/Koloda.xcodeproj/project.pbxproj | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/Example/Koloda.xcodeproj/project.pbxproj b/Example/Koloda.xcodeproj/project.pbxproj index 66be3329..4257b600 100644 --- a/Example/Koloda.xcodeproj/project.pbxproj +++ b/Example/Koloda.xcodeproj/project.pbxproj @@ -170,7 +170,7 @@ TargetAttributes = { 607FACCF1AFB9204008FA782 = { CreatedOnToolsVersion = 6.3.1; - LastSwiftMigration = 0900; + LastSwiftMigration = 1010; }; }; }; @@ -408,8 +408,7 @@ MODULE_NAME = ExampleApp; PRODUCT_BUNDLE_IDENTIFIER = "com.yalantis.Koloda-Example"; PRODUCT_NAME = "$(TARGET_NAME)"; - SWIFT_SWIFT3_OBJC_INFERENCE = Default; - SWIFT_VERSION = 4.0; + SWIFT_VERSION = 4.2; }; name = Debug; }; @@ -425,8 +424,7 @@ MODULE_NAME = ExampleApp; PRODUCT_BUNDLE_IDENTIFIER = "com.yalantis.Koloda-Example"; PRODUCT_NAME = "$(TARGET_NAME)"; - SWIFT_SWIFT3_OBJC_INFERENCE = On; - SWIFT_VERSION = 4.0; + SWIFT_VERSION = 4.2; }; name = Release; }; From f3391047705cfc62878d4f91e3506d27fb04cbb0 Mon Sep 17 00:00:00 2001 From: rnkyr Date: Tue, 25 Dec 2018 13:03:33 +0200 Subject: [PATCH 13/37] [update] version, changelog --- Koloda.podspec | 2 +- README.md | 14 ++++++-------- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/Koloda.podspec b/Koloda.podspec index 53e300ed..d471cfc3 100644 --- a/Koloda.podspec +++ b/Koloda.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = "Koloda" - s.version = '4.5.1' + s.version = '4.6' s.summary = "KolodaView is a class designed to simplify the implementation of Tinder like cards on iOS. " s.homepage = "https://github.com/Yalantis/Koloda" diff --git a/README.md b/README.md index 0408fef4..c83eff71 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -KolodaView [![Carthage compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat)](https://github.com/Carthage/Carthage) ![Swift 4.2](https://img.shields.io/badge/Swift-4.2-orange.svg) +KolodaView [![cocoapods](https://img.shields.io/cocoapods/v/Koloda.svg)][![Carthage compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat)](https://github.com/Carthage/Carthage) ![Swift 4.2](https://img.shields.io/badge/Swift-4.2-orange.svg) -------------- [![Yalantis](https://raw.githubusercontent.com/Yalantis/PullToMakeSoup/master/PullToMakeSoupDemo/Resouces/badge_dark.png)](https://Yalantis.com/?utm_source=github) @@ -24,13 +24,6 @@ ARC Compatibility KolodaView requires ARC. -Сocoapods version ------------------- - -```ruby -pod 'Koloda', '~> 4.5.1' -``` - Thread Safety -------------- @@ -247,6 +240,11 @@ not move. Release Notes ---------------- +Version 4.6 +- update some properties to be publicitly settable via [@sroik](https://github.com/sroik) and [@leonardoherbert](https://github.com/leonardoherbert) +- Xcode 9 back compatibility via [@seriyvolk83](https://github.com/seriyvolk83) +- added posibility to have the card stack at the top or bottom via [@lorenzOliveto](https://github.com/lorenzOliveto) + Version 4.5 - Swift 4.2 via [@evilmint](https://github.com/evilmint) From 89da17e26dfe8154e393a462ac13fed56f3b6fd7 Mon Sep 17 00:00:00 2001 From: Roman Kyrylenko Date: Tue, 25 Dec 2018 13:05:20 +0200 Subject: [PATCH 14/37] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index c83eff71..8b96edfd 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -KolodaView [![cocoapods](https://img.shields.io/cocoapods/v/Koloda.svg)][![Carthage compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat)](https://github.com/Carthage/Carthage) ![Swift 4.2](https://img.shields.io/badge/Swift-4.2-orange.svg) +KolodaView ![cocoapods](https://img.shields.io/cocoapods/v/Koloda.svg)[![Carthage compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat)](https://github.com/Carthage/Carthage) ![Swift 4.2](https://img.shields.io/badge/Swift-4.2-orange.svg) -------------- [![Yalantis](https://raw.githubusercontent.com/Yalantis/PullToMakeSoup/master/PullToMakeSoupDemo/Resouces/badge_dark.png)](https://Yalantis.com/?utm_source=github) From 2393f5725d1a309168406046089579841ec80cad Mon Sep 17 00:00:00 2001 From: Nicholas Lash Date: Thu, 10 Jan 2019 12:37:21 -0600 Subject: [PATCH 15/37] do not layoutDeck during drag. --- .../KolodaView/DraggableCardView/DraggableCardView.swift | 3 ++- Pod/Classes/KolodaView/KolodaView.swift | 7 ++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/Pod/Classes/KolodaView/DraggableCardView/DraggableCardView.swift b/Pod/Classes/KolodaView/DraggableCardView/DraggableCardView.swift index a5cb23f5..22c7e32a 100644 --- a/Pod/Classes/KolodaView/DraggableCardView/DraggableCardView.swift +++ b/Pod/Classes/KolodaView/DraggableCardView/DraggableCardView.swift @@ -57,6 +57,8 @@ public class DraggableCardView: UIView, UIGestureRecognizerDelegate { configureSwipeSpeed() } } + + internal var dragBegin = false private var overlayView: OverlayView? public private(set) var contentView: UIView? @@ -64,7 +66,6 @@ public class DraggableCardView: UIView, UIGestureRecognizerDelegate { private var panGestureRecognizer: UIPanGestureRecognizer! private var tapGestureRecognizer: UITapGestureRecognizer! private var animationDirectionY: CGFloat = 1.0 - private var dragBegin = false private var dragDistance = CGPoint.zero private var swipePercentageMargin: CGFloat = 0.0 diff --git a/Pod/Classes/KolodaView/KolodaView.swift b/Pod/Classes/KolodaView/KolodaView.swift index aabfa2e9..4c28d264 100644 --- a/Pod/Classes/KolodaView/KolodaView.swift +++ b/Pod/Classes/KolodaView/KolodaView.swift @@ -150,12 +150,17 @@ open class KolodaView: UIView, DraggableCardDelegate { return KolodaViewAnimator(koloda: self) }() private var visibleCards = [DraggableCardView]() + private var cardsDragging: Bool { + return visibleCards.contains { card in + return card.dragBegin + } + } override open func layoutSubviews() { super.layoutSubviews() - if !animationSemaphore.isAnimating { + if !animationSemaphore.isAnimating, !cardsDragging { layoutDeck() } } From 60ca992f41f3e171d88dc64a283da7b83a430a8c Mon Sep 17 00:00:00 2001 From: Nicholas Lash Date: Thu, 10 Jan 2019 13:02:53 -0600 Subject: [PATCH 16/37] remove iterating. --- Pod/Classes/KolodaView/KolodaView.swift | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/Pod/Classes/KolodaView/KolodaView.swift b/Pod/Classes/KolodaView/KolodaView.swift index 4c28d264..c1556a3c 100644 --- a/Pod/Classes/KolodaView/KolodaView.swift +++ b/Pod/Classes/KolodaView/KolodaView.swift @@ -150,17 +150,18 @@ open class KolodaView: UIView, DraggableCardDelegate { return KolodaViewAnimator(koloda: self) }() private var visibleCards = [DraggableCardView]() - private var cardsDragging: Bool { - return visibleCards.contains { card in - return card.dragBegin + + private var cardIsDragging: Bool { + guard let frontCard = visibleCards.first else { + return false } + return frontCard.dragBegin } - override open func layoutSubviews() { super.layoutSubviews() - if !animationSemaphore.isAnimating, !cardsDragging { + if !animationSemaphore.isAnimating, !cardIsDragging { layoutDeck() } } From 034f90f8d57a8252dae825dbcede657f6359a011 Mon Sep 17 00:00:00 2001 From: Daniel Tischenko Date: Fri, 11 Jan 2019 15:07:30 +0200 Subject: [PATCH 17/37] Fix the bug with false-positive choosing a direction --- .../DraggableCardView/DraggableCardView.swift | 14 ++++++++------ .../KolodaView/SwipeResultDirection.swift | 18 ++++++++++++++++++ 2 files changed, 26 insertions(+), 6 deletions(-) diff --git a/Pod/Classes/KolodaView/DraggableCardView/DraggableCardView.swift b/Pod/Classes/KolodaView/DraggableCardView/DraggableCardView.swift index d839dcf2..f6fd67c2 100644 --- a/Pod/Classes/KolodaView/DraggableCardView/DraggableCardView.swift +++ b/Pod/Classes/KolodaView/DraggableCardView/DraggableCardView.swift @@ -296,12 +296,14 @@ public class DraggableCardView: UIView, UIGestureRecognizerDelegate { private var dragDirection: SwipeResultDirection? { //find closest direction let normalizedDragPoint = dragDistance.normalizedDistanceForSize(bounds.size) - return directions.reduce((distance:CGFloat.infinity, direction:nil)) { closest, direction in - let distance = direction.point.distanceTo(normalizedDragPoint) - if distance < closest.distance { - return (distance, direction) - } - return closest + return directions + .reduce((distance:CGFloat.infinity, direction:SwipeResultDirection?.none)) { closest, direction in + guard direction.hasPoint(normalizedDragPoint) else { return closest } + + let distance = direction.point.distanceTo(normalizedDragPoint) + if distance < closest.distance { return (distance, direction) } + + return closest }.direction } diff --git a/Pod/Classes/KolodaView/SwipeResultDirection.swift b/Pod/Classes/KolodaView/SwipeResultDirection.swift index 5afcae98..eb4a0971 100644 --- a/Pod/Classes/KolodaView/SwipeResultDirection.swift +++ b/Pod/Classes/KolodaView/SwipeResultDirection.swift @@ -49,6 +49,24 @@ extension SwipeResultDirection { let h = VerticalPosition.bottom.rawValue - VerticalPosition.top.rawValue return CGRect(x: HorizontalPosition.left.rawValue, y: VerticalPosition.top.rawValue, width: w, height: h) } + + func hasPoint(_ point: CGPoint) -> Bool { + switch self { + case .up: + return point.y < 0 && + (point.x > 0 && point.y < -point.x || point.x < 0 && point.y < point.x) + case .down: + return point.y > 0 && + (point.x > 0 && point.y > point.x || point.x < 0 && point.y > -point.x) + case .left: + return point.x < 0 && + (point.y > 0 && point.y < -point.x || point.y < 0 && point.y > point.x) + case .right: + return point.x > 0 && + (point.y > 0 && point.y < point.x || point.y < 0 && point.y > -point.x) + default: return true + } + } } From 21b0bff3e03ddc768cc3bf9a0dc661d78b543f2b Mon Sep 17 00:00:00 2001 From: Daniel Tischenko Date: Fri, 11 Jan 2019 16:44:19 +0200 Subject: [PATCH 18/37] Fix calling didShowCard too early --- Pod/Classes/KolodaView/KolodaView.swift | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Pod/Classes/KolodaView/KolodaView.swift b/Pod/Classes/KolodaView/KolodaView.swift index 9866f3c3..857faec9 100644 --- a/Pod/Classes/KolodaView/KolodaView.swift +++ b/Pod/Classes/KolodaView/KolodaView.swift @@ -168,7 +168,6 @@ open class KolodaView: UIView, DraggableCardDelegate { if isTop { delegate?.koloda(self, willShow: nextCardView, at: index) } isTop ? addSubview(nextCardView) : insertSubview(nextCardView, belowSubview: visibleCards[index - 1]) } - self.delegate?.koloda(self, didShowCardAt: currentCardIndex) } } } @@ -177,6 +176,9 @@ open class KolodaView: UIView, DraggableCardDelegate { for (index, card) in visibleCards.enumerated() { layoutCard(card, at: index) } + if currentCardIndex == 0 { + delegate?.koloda(self, didShowCardAt: currentCardIndex) + } } private func layoutCard(_ card: DraggableCardView, at index: Int) { From 74afe3c272601e52cc1299e2129a02af70a87b4b Mon Sep 17 00:00:00 2001 From: lixiang1994 <18611401994@163.com> Date: Thu, 17 Jan 2019 21:51:18 +0800 Subject: [PATCH 19/37] Hello, fixed the vulnerability that the card could not respond due to the simultaneous call to swipe(.xx) during the dragging of the card. --- .../DraggableCardView/DraggableCardView.swift | 2 +- Pod/Classes/KolodaView/KolodaView.swift | 10 ++++------ 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/Pod/Classes/KolodaView/DraggableCardView/DraggableCardView.swift b/Pod/Classes/KolodaView/DraggableCardView/DraggableCardView.swift index a5cb23f5..975f6677 100644 --- a/Pod/Classes/KolodaView/DraggableCardView/DraggableCardView.swift +++ b/Pod/Classes/KolodaView/DraggableCardView/DraggableCardView.swift @@ -64,7 +64,7 @@ public class DraggableCardView: UIView, UIGestureRecognizerDelegate { private var panGestureRecognizer: UIPanGestureRecognizer! private var tapGestureRecognizer: UITapGestureRecognizer! private var animationDirectionY: CGFloat = 1.0 - private var dragBegin = false + private(set) var dragBegin = false private var dragDistance = CGPoint.zero private var swipePercentageMargin: CGFloat = 0.0 diff --git a/Pod/Classes/KolodaView/KolodaView.swift b/Pod/Classes/KolodaView/KolodaView.swift index aabfa2e9..2ea33eff 100644 --- a/Pod/Classes/KolodaView/KolodaView.swift +++ b/Pod/Classes/KolodaView/KolodaView.swift @@ -610,15 +610,13 @@ open class KolodaView: UIView, DraggableCardDelegate { public func swipe(_ direction: SwipeResultDirection, force: Bool = false) { let shouldSwipe = delegate?.koloda(self, shouldSwipeCardAt: currentCardIndex, in: direction) ?? true - guard force || shouldSwipe else { - return - } + guard force || shouldSwipe else { return } let validDirection = delegate?.koloda(self, allowedDirectionsForIndex: currentCardIndex).contains(direction) ?? true guard validDirection else { return } if !animationSemaphore.isAnimating { - if let frontCard = visibleCards.first { + if let frontCard = visibleCards.first, !frontCard.dragBegin { if visibleCards.count > 1 { let nextCard = visibleCards[1] @@ -699,7 +697,7 @@ open class KolodaView: UIView, DraggableCardDelegate { cards, completion: { _ in self.removeCards(cards) - } + } ) } else { self.removeCards(cards) @@ -725,7 +723,7 @@ open class KolodaView: UIView, DraggableCardDelegate { insertedCards, completion: { _ in self.animationSemaphore.decrement() - } + } ) } From f663a5cec3aceaf32e0a9e6a2adbe5e8a2672529 Mon Sep 17 00:00:00 2001 From: lixiang1994 <18611401994@163.com> Date: Fri, 18 Jan 2019 14:18:23 +0800 Subject: [PATCH 20/37] Fixed vulnerabilities where gesture limits are invalid --- .../DraggableCardView/DraggableCardView.swift | 33 +++++++++++-------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/Pod/Classes/KolodaView/DraggableCardView/DraggableCardView.swift b/Pod/Classes/KolodaView/DraggableCardView/DraggableCardView.swift index 975f6677..e8d57ee6 100644 --- a/Pod/Classes/KolodaView/DraggableCardView/DraggableCardView.swift +++ b/Pod/Classes/KolodaView/DraggableCardView/DraggableCardView.swift @@ -46,7 +46,7 @@ private let cardResetAnimationDuration: TimeInterval = 0.2 internal var cardSwipeActionAnimationDuration: TimeInterval = DragSpeed.default.rawValue public class DraggableCardView: UIView, UIGestureRecognizerDelegate { - + //Drag animation constants public var rotationMax = defaultRotationMax public var rotationAngle = defaultRotationAngle @@ -67,7 +67,7 @@ public class DraggableCardView: UIView, UIGestureRecognizerDelegate { private(set) var dragBegin = false private var dragDistance = CGPoint.zero private var swipePercentageMargin: CGFloat = 0.0 - + //MARK: Lifecycle init() { @@ -108,7 +108,7 @@ public class DraggableCardView: UIView, UIGestureRecognizerDelegate { tapGestureRecognizer.delegate = self tapGestureRecognizer.cancelsTouchesInView = false addGestureRecognizer(tapGestureRecognizer) - + if let delegate = delegate { cardSwipeActionAnimationDuration = delegate.card(cardSwipeSpeed: self).rawValue } @@ -128,11 +128,11 @@ public class DraggableCardView: UIView, UIGestureRecognizerDelegate { } else { self.addSubview(view) } - + self.contentView = view configureContentView() } - + private func configureOverlayView() { if let overlay = self.overlayView { overlay.translatesAutoresizingMaskIntoConstraints = false @@ -249,7 +249,7 @@ public class DraggableCardView: UIView, UIGestureRecognizerDelegate { let rotationAngle = animationDirectionY * self.rotationAngle * rotationStrength let scaleStrength = 1 - ((1 - scaleMin) * abs(rotationStrength)) let scale = max(scaleStrength, scaleMin) - + var transform = CATransform3DIdentity transform = CATransform3DScale(transform, scale, scale, 1) transform = CATransform3DRotate(transform, rotationAngle, 0, 0, 1) @@ -275,12 +275,17 @@ public class DraggableCardView: UIView, UIGestureRecognizerDelegate { } public func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldReceive touch: UITouch) -> Bool { - if let touchView = touch.view, let _ = touchView as? UIControl { - return false + guard gestureRecognizer == tapGestureRecognizer, touch.view is UIControl else { + return true } - - panGestureRecognizer.isEnabled = delegate?.card(cardShouldDrag: self) ?? true - return true + return false + } + + public override func gestureRecognizerShouldBegin(_ gestureRecognizer: UIGestureRecognizer) -> Bool { + guard gestureRecognizer == panGestureRecognizer else { + return true + } + return delegate?.card(cardShouldDrag: self) ?? true } @objc func tapRecognized(_ recogznier: UITapGestureRecognizer) { @@ -324,9 +329,9 @@ public class DraggableCardView: UIView, UIGestureRecognizerDelegate { // check 4 borders for intersection with line between touchpoint and center of card // return smallest percentage of distance to edge point or 0 return rect.perimeterLines - .compactMap { CGPoint.intersectionBetweenLines(targetLine, line2: $0) } - .map { centerDistance / $0.distanceTo(.zero) } - .min() ?? 0 + .compactMap { CGPoint.intersectionBetweenLines(targetLine, line2: $0) } + .map { centerDistance / $0.distanceTo(.zero) } + .min() ?? 0 } } From 1dfecea5d83c815903efed550f55fd719b52ebf8 Mon Sep 17 00:00:00 2001 From: lixiang1994 <18611401994@163.com> Date: Wed, 23 Jan 2019 11:51:04 +0800 Subject: [PATCH 21/37] some code line breaks be removed. --- .../DraggableCardView/DraggableCardView.swift | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Pod/Classes/KolodaView/DraggableCardView/DraggableCardView.swift b/Pod/Classes/KolodaView/DraggableCardView/DraggableCardView.swift index e8d57ee6..73378073 100644 --- a/Pod/Classes/KolodaView/DraggableCardView/DraggableCardView.swift +++ b/Pod/Classes/KolodaView/DraggableCardView/DraggableCardView.swift @@ -46,7 +46,7 @@ private let cardResetAnimationDuration: TimeInterval = 0.2 internal var cardSwipeActionAnimationDuration: TimeInterval = DragSpeed.default.rawValue public class DraggableCardView: UIView, UIGestureRecognizerDelegate { - + //Drag animation constants public var rotationMax = defaultRotationMax public var rotationAngle = defaultRotationAngle @@ -67,7 +67,7 @@ public class DraggableCardView: UIView, UIGestureRecognizerDelegate { private(set) var dragBegin = false private var dragDistance = CGPoint.zero private var swipePercentageMargin: CGFloat = 0.0 - + //MARK: Lifecycle init() { @@ -108,7 +108,7 @@ public class DraggableCardView: UIView, UIGestureRecognizerDelegate { tapGestureRecognizer.delegate = self tapGestureRecognizer.cancelsTouchesInView = false addGestureRecognizer(tapGestureRecognizer) - + if let delegate = delegate { cardSwipeActionAnimationDuration = delegate.card(cardSwipeSpeed: self).rawValue } @@ -128,11 +128,11 @@ public class DraggableCardView: UIView, UIGestureRecognizerDelegate { } else { self.addSubview(view) } - + self.contentView = view configureContentView() } - + private func configureOverlayView() { if let overlay = self.overlayView { overlay.translatesAutoresizingMaskIntoConstraints = false @@ -249,7 +249,7 @@ public class DraggableCardView: UIView, UIGestureRecognizerDelegate { let rotationAngle = animationDirectionY * self.rotationAngle * rotationStrength let scaleStrength = 1 - ((1 - scaleMin) * abs(rotationStrength)) let scale = max(scaleStrength, scaleMin) - + var transform = CATransform3DIdentity transform = CATransform3DScale(transform, scale, scale, 1) transform = CATransform3DRotate(transform, rotationAngle, 0, 0, 1) From 3077d444248b8db1e9313a3fd7bd35bea9d07393 Mon Sep 17 00:00:00 2001 From: lixiang1994 <18611401994@163.com> Date: Sun, 3 Feb 2019 11:27:58 +0800 Subject: [PATCH 22/37] 1. Optimized position calculation 2. enum SwipeResultDirection add CaseIterable (4.2 later) --- .../DraggableCardView/DraggableCardView.swift | 22 +++++++++++++++---- .../KolodaView/SwipeResultDirection.swift | 4 ++++ 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/Pod/Classes/KolodaView/DraggableCardView/DraggableCardView.swift b/Pod/Classes/KolodaView/DraggableCardView/DraggableCardView.swift index 73378073..f219c388 100644 --- a/Pod/Classes/KolodaView/DraggableCardView/DraggableCardView.swift +++ b/Pod/Classes/KolodaView/DraggableCardView/DraggableCardView.swift @@ -354,10 +354,24 @@ public class DraggableCardView: UIView, UIGestureRecognizerDelegate { } func animationPointForDirection(_ direction: SwipeResultDirection) -> CGPoint { - let point = direction.point - let animatePoint = CGPoint(x: point.x * 4, y: point.y * 4) //should be 2 - let retPoint = animatePoint.screenPointForSize(screenSize) - return retPoint + guard let superview = self.superview else { + return .zero + } + + let superSize = superview.bounds.size + let space = max(screenSize.width, screenSize.height) + switch direction { + case .left, .right: + // Optimize left and right position + let x = direction.point.x * (superSize.width + space) + let y = 0.5 * superSize.height + return CGPoint(x: x, y: y) + + default: + let x = direction.point.x * (superSize.width + space) + let y = direction.point.y * (superSize.height + space) + return CGPoint(x: x, y: y) + } } func animationRotationForDirection(_ direction: SwipeResultDirection) -> CGFloat { diff --git a/Pod/Classes/KolodaView/SwipeResultDirection.swift b/Pod/Classes/KolodaView/SwipeResultDirection.swift index 5afcae98..95d94cd8 100644 --- a/Pod/Classes/KolodaView/SwipeResultDirection.swift +++ b/Pod/Classes/KolodaView/SwipeResultDirection.swift @@ -21,6 +21,10 @@ public enum SwipeResultDirection: String { case bottomRight } +#if swift(>=4.2) +extension SwipeResultDirection: CaseIterable { } +#endif + extension SwipeResultDirection { private var swipeDirection: Direction { From dec1a52541e3f4f07c2a3c470630ce0e0742db1f Mon Sep 17 00:00:00 2001 From: rnkyr Date: Wed, 13 Mar 2019 15:11:26 +0200 Subject: [PATCH 23/37] [update] readme, podspec --- Koloda.podspec | 12 ++++++------ README.md | 5 ++++- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/Koloda.podspec b/Koloda.podspec index d471cfc3..53604218 100644 --- a/Koloda.podspec +++ b/Koloda.podspec @@ -1,12 +1,12 @@ Pod::Spec.new do |s| - s.name = "Koloda" - s.version = '4.6' - s.summary = "KolodaView is a class designed to simplify the implementation of Tinder like cards on iOS. " + s.name = 'Koloda' + s.version = '4.7' + s.summary = 'KolodaView is a class designed to simplify the implementation of Tinder like cards on iOS. ' - s.homepage = "https://github.com/Yalantis/Koloda" + s.homepage = 'https://github.com/Yalantis/Koloda' s.license = 'MIT' - s.author = "Yalantis" - s.source = { :git => "https://github.com/Yalantis/Koloda.git", :tag => s.version } + s.author = 'Yalantis' + s.source = { :git => 'https://github.com/Yalantis/Koloda.git', :tag => s.version } s.social_media_url = 'https://twitter.com/yalantis' s.platform = :ios, '8.0' diff --git a/README.md b/README.md index 8b96edfd..3413d8f8 100644 --- a/README.md +++ b/README.md @@ -239,6 +239,9 @@ not move. Release Notes ---------------- +Version 4.7 +- fixed a bug with card responding during swiping via [@lixiang1994](https://github.com/lixiang1994) +- fixed a bug with inappropriate layouting via [@soundsmitten](https://github.com/soundsmitten) Version 4.6 - update some properties to be publicitly settable via [@sroik](https://github.com/sroik) and [@leonardoherbert](https://github.com/leonardoherbert) @@ -307,7 +310,7 @@ License The MIT License (MIT) -Copyright © 2018 Yalantis +Copyright © 2019 Yalantis Permission is hereby granted free of charge to any person obtaining a copy of this software and associated documentation files (the "Software") to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: From 0799ceeb1a121ab30fc4039168ae6081945cc66c Mon Sep 17 00:00:00 2001 From: Max Cobb Date: Fri, 29 Mar 2019 14:18:04 +0000 Subject: [PATCH 24/37] update framework to Swift 5.0 --- Example/Koloda.xcodeproj/project.pbxproj | 12 ++++++------ .../xcshareddata/xcschemes/Koloda-Example.xcscheme | 2 +- Pod/Classes/KolodaView/KolodaView.swift | 6 +++--- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/Example/Koloda.xcodeproj/project.pbxproj b/Example/Koloda.xcodeproj/project.pbxproj index 4257b600..c361ec79 100644 --- a/Example/Koloda.xcodeproj/project.pbxproj +++ b/Example/Koloda.xcodeproj/project.pbxproj @@ -170,13 +170,13 @@ TargetAttributes = { 607FACCF1AFB9204008FA782 = { CreatedOnToolsVersion = 6.3.1; - LastSwiftMigration = 1010; + LastSwiftMigration = 1020; }; }; }; buildConfigurationList = 607FACCB1AFB9204008FA782 /* Build configuration list for PBXProject "Koloda" */; compatibilityVersion = "Xcode 3.2"; - developmentRegion = English; + developmentRegion = en; hasScannedForEncodings = 0; knownRegions = ( en, @@ -232,7 +232,7 @@ files = ( ); inputPaths = ( - "${SRCROOT}/Pods/Target Support Files/Pods-Koloda_Example/Pods-Koloda_Example-frameworks.sh", + "${PODS_ROOT}/Target Support Files/Pods-Koloda_Example/Pods-Koloda_Example-frameworks.sh", "${BUILT_PRODUCTS_DIR}/Koloda/Koloda.framework", "${BUILT_PRODUCTS_DIR}/pop/pop.framework", ); @@ -243,7 +243,7 @@ ); runOnlyForDeploymentPostprocessing = 0; shellPath = /bin/sh; - shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-Koloda_Example/Pods-Koloda_Example-frameworks.sh\"\n"; + shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-Koloda_Example/Pods-Koloda_Example-frameworks.sh\"\n"; showEnvVarsInLog = 0; }; /* End PBXShellScriptBuildPhase section */ @@ -408,7 +408,7 @@ MODULE_NAME = ExampleApp; PRODUCT_BUNDLE_IDENTIFIER = "com.yalantis.Koloda-Example"; PRODUCT_NAME = "$(TARGET_NAME)"; - SWIFT_VERSION = 4.2; + SWIFT_VERSION = 5.0; }; name = Debug; }; @@ -424,7 +424,7 @@ MODULE_NAME = ExampleApp; PRODUCT_BUNDLE_IDENTIFIER = "com.yalantis.Koloda-Example"; PRODUCT_NAME = "$(TARGET_NAME)"; - SWIFT_VERSION = 4.2; + SWIFT_VERSION = 5.0; }; name = Release; }; diff --git a/Example/Koloda.xcodeproj/xcshareddata/xcschemes/Koloda-Example.xcscheme b/Example/Koloda.xcodeproj/xcshareddata/xcschemes/Koloda-Example.xcscheme index 2c9439c8..afef7db3 100644 --- a/Example/Koloda.xcodeproj/xcshareddata/xcschemes/Koloda-Example.xcscheme +++ b/Example/Koloda.xcodeproj/xcshareddata/xcschemes/Koloda-Example.xcscheme @@ -1,6 +1,6 @@ [SwipeResultDirection] { - let index = currentCardIndex + visibleCards.index(of: card)! + let index = currentCardIndex + visibleCards.firstIndex(of: card)! return delegate?.koloda(self, allowedDirectionsForIndex: index) ?? [.left, .right] } @@ -364,7 +364,7 @@ open class KolodaView: UIView, DraggableCardDelegate { } func card(cardWasTapped card: DraggableCardView) { - guard let visibleIndex = visibleCards.index(of: card) else { return } + guard let visibleIndex = visibleCards.firstIndex(of: card) else { return } let index = currentCardIndex + visibleIndex delegate?.koloda(self, didSelectCardAt: index) @@ -375,7 +375,7 @@ open class KolodaView: UIView, DraggableCardDelegate { } func card(cardShouldDrag card: DraggableCardView) -> Bool { - guard let visibleIndex = visibleCards.index(of: card) else { return true} + guard let visibleIndex = visibleCards.firstIndex(of: card) else { return true} let index = currentCardIndex + visibleIndex return delegate?.koloda(self, shouldDragCardAt: index) ?? true From 0bdc05f46510d538a9e30f16cff84a087d3ee361 Mon Sep 17 00:00:00 2001 From: Maxx Cobb Date: Sun, 31 Mar 2019 09:35:47 +0100 Subject: [PATCH 25/37] bumping the version in swift badge to 5.0 --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 3413d8f8..4abc125d 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -KolodaView ![cocoapods](https://img.shields.io/cocoapods/v/Koloda.svg)[![Carthage compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat)](https://github.com/Carthage/Carthage) ![Swift 4.2](https://img.shields.io/badge/Swift-4.2-orange.svg) +KolodaView ![cocoapods](https://img.shields.io/cocoapods/v/Koloda.svg)[![Carthage compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat)](https://github.com/Carthage/Carthage) ![Swift 5.0](https://img.shields.io/badge/Swift-5.0-orange.svg) -------------- [![Yalantis](https://raw.githubusercontent.com/Yalantis/PullToMakeSoup/master/PullToMakeSoupDemo/Resouces/badge_dark.png)](https://Yalantis.com/?utm_source=github) From 2ba6a2557646260b86f00bc69b8c06c0d1b07f68 Mon Sep 17 00:00:00 2001 From: rnkyr Date: Thu, 2 May 2019 11:21:47 +0300 Subject: [PATCH 26/37] [update] meta files --- .swift-version | 2 +- Koloda.podspec | 2 +- README.md | 4 ++++ 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/.swift-version b/.swift-version index 8012ebbb..6e636605 100644 --- a/.swift-version +++ b/.swift-version @@ -1 +1 @@ -4.2 \ No newline at end of file +5.0 \ No newline at end of file diff --git a/Koloda.podspec b/Koloda.podspec index 53604218..f5a7801d 100644 --- a/Koloda.podspec +++ b/Koloda.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = 'Koloda' - s.version = '4.7' + s.version = '5.0' s.summary = 'KolodaView is a class designed to simplify the implementation of Tinder like cards on iOS. ' s.homepage = 'https://github.com/Yalantis/Koloda' diff --git a/README.md b/README.md index 4abc125d..91705807 100644 --- a/README.md +++ b/README.md @@ -239,6 +239,10 @@ not move. Release Notes ---------------- + +Version 5.0 +- Swift 5.0 via [@maxxfrazer](https://github.com/maxxfrazer) + Version 4.7 - fixed a bug with card responding during swiping via [@lixiang1994](https://github.com/lixiang1994) - fixed a bug with inappropriate layouting via [@soundsmitten](https://github.com/soundsmitten) From 8727fadea4096ce6b19e74cf63bcee6cac4ef720 Mon Sep 17 00:00:00 2001 From: Navka Sergey Date: Tue, 7 Apr 2020 10:09:08 +0300 Subject: [PATCH 27/37] have added `func koloda(_ koloda:, didRewindTo:)` delegate method --- Pod/Classes/KolodaView/KolodaView.swift | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Pod/Classes/KolodaView/KolodaView.swift b/Pod/Classes/KolodaView/KolodaView.swift index ff76e623..d9f0c598 100644 --- a/Pod/Classes/KolodaView/KolodaView.swift +++ b/Pod/Classes/KolodaView/KolodaView.swift @@ -61,6 +61,7 @@ public protocol KolodaViewDelegate: class { func kolodaDidResetCard(_ koloda: KolodaView) func kolodaSwipeThresholdRatioMargin(_ koloda: KolodaView) -> CGFloat? func koloda(_ koloda: KolodaView, didShowCardAt index: Int) + func koloda(_ koloda: KolodaView, didRewindTo index: Int) func koloda(_ koloda: KolodaView, shouldDragCardAt index: Int ) -> Bool func kolodaPanBegan(_ koloda: KolodaView, card: DraggableCardView) func kolodaPanFinished(_ koloda: KolodaView, card: DraggableCardView) @@ -81,6 +82,7 @@ public extension KolodaViewDelegate { func kolodaDidResetCard(_ koloda: KolodaView) {} func kolodaSwipeThresholdRatioMargin(_ koloda: KolodaView) -> CGFloat? { return nil} func koloda(_ koloda: KolodaView, didShowCardAt index: Int) {} + func koloda(_ koloda: KolodaView, didRewindTo index: Int) {} func koloda(_ koloda: KolodaView, shouldDragCardAt index: Int ) -> Bool { return true } func kolodaPanBegan(_ koloda: KolodaView, card: DraggableCardView) {} func kolodaPanFinished(_ koloda: KolodaView, card: DraggableCardView) {} @@ -528,6 +530,7 @@ open class KolodaView: UIView, DraggableCardDelegate { } _self.animationSemaphore.decrement() + _self.delegate?.koloda(_self, didRewindTo: _self.currentCardIndex) _self.delegate?.koloda(_self, didShowCardAt: _self.currentCardIndex) }) } From 8336c823114f1fb653edb83e8706bff4f3fb5f2a Mon Sep 17 00:00:00 2001 From: Navka Sergey Date: Tue, 7 Apr 2020 10:10:11 +0300 Subject: [PATCH 28/37] carthage update versions --- Cartfile.resolved | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cartfile.resolved b/Cartfile.resolved index 311e1cc7..16570dca 100644 --- a/Cartfile.resolved +++ b/Cartfile.resolved @@ -1 +1 @@ -github "facebook/pop" "1.0.9" +github "facebook/pop" "1.0.12" From 65c05e430a62f257011571e0f181cbd55b89cb12 Mon Sep 17 00:00:00 2001 From: Navka Sergey Date: Tue, 7 Apr 2020 10:11:40 +0300 Subject: [PATCH 29/37] [update] changelog --- README.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/README.md b/README.md index 91705807..79c3bf44 100644 --- a/README.md +++ b/README.md @@ -230,6 +230,11 @@ This method is fired after resetting the card. func koloda(_ koloda: KolodaView, didShowCardAt index: Int) ``` This method is called after a card has been shown, after animation is complete +```swift +func koloda(_ koloda: KolodaView, didRewindTo index: Int) +``` +This method is called after a card was rewound, after animation is complete + ```swift func koloda(_ koloda: KolodaView, shouldDragCardAt index: Int) -> Bool ``` @@ -239,6 +244,8 @@ not move. Release Notes ---------------- +Version 5.0.1 +- added posibility to determine index of rewound card Version 5.0 - Swift 5.0 via [@maxxfrazer](https://github.com/maxxfrazer) From b088c618a3f2e30410d62bc8861ebe4c2f2332c9 Mon Sep 17 00:00:00 2001 From: Navka Sergey Date: Wed, 15 Apr 2020 18:15:27 +0300 Subject: [PATCH 30/37] removed force unwrap --- Pod/Classes/KolodaView/KolodaView.swift | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Pod/Classes/KolodaView/KolodaView.swift b/Pod/Classes/KolodaView/KolodaView.swift index d9f0c598..9345f428 100644 --- a/Pod/Classes/KolodaView/KolodaView.swift +++ b/Pod/Classes/KolodaView/KolodaView.swift @@ -333,7 +333,9 @@ open class KolodaView: UIView, DraggableCardDelegate { } func card(cardAllowedDirections card: DraggableCardView) -> [SwipeResultDirection] { - let index = currentCardIndex + visibleCards.firstIndex(of: card)! + guard let firsIndex = visibleCards.firstIndex(of: card) else { return [.left, .right] } + + let index = currentCardIndex + firsIndex return delegate?.koloda(self, allowedDirectionsForIndex: index) ?? [.left, .right] } From 8539e9d4cf2f50600093c1053755f2b079f9b474 Mon Sep 17 00:00:00 2001 From: Navka Sergey Date: Wed, 15 Apr 2020 18:22:54 +0300 Subject: [PATCH 31/37] typo --- Pod/Classes/KolodaView/KolodaView.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Pod/Classes/KolodaView/KolodaView.swift b/Pod/Classes/KolodaView/KolodaView.swift index 9345f428..5fc404a1 100644 --- a/Pod/Classes/KolodaView/KolodaView.swift +++ b/Pod/Classes/KolodaView/KolodaView.swift @@ -333,9 +333,9 @@ open class KolodaView: UIView, DraggableCardDelegate { } func card(cardAllowedDirections card: DraggableCardView) -> [SwipeResultDirection] { - guard let firsIndex = visibleCards.firstIndex(of: card) else { return [.left, .right] } + guard let firstIndex = visibleCards.firstIndex(of: card) else { return [.left, .right] } - let index = currentCardIndex + firsIndex + let index = currentCardIndex + firstIndex return delegate?.koloda(self, allowedDirectionsForIndex: index) ?? [.left, .right] } From be55dc4a2b9f2b83c63af5531762a79eadd6801a Mon Sep 17 00:00:00 2001 From: Navka Sergey Date: Thu, 16 Apr 2020 18:06:55 +0300 Subject: [PATCH 32/37] [update] podspec, readme --- Koloda.podspec | 2 +- README.md | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/Koloda.podspec b/Koloda.podspec index f5a7801d..ba7c78e5 100644 --- a/Koloda.podspec +++ b/Koloda.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = 'Koloda' - s.version = '5.0' + s.version = '5.0.1' s.summary = 'KolodaView is a class designed to simplify the implementation of Tinder like cards on iOS. ' s.homepage = 'https://github.com/Yalantis/Koloda' diff --git a/README.md b/README.md index 79c3bf44..a82e258c 100644 --- a/README.md +++ b/README.md @@ -246,6 +246,7 @@ Release Notes ---------------- Version 5.0.1 - added posibility to determine index of rewound card +- fixed crash after drugging card Version 5.0 - Swift 5.0 via [@maxxfrazer](https://github.com/maxxfrazer) From 27886cd84c5033d830a4fc3527f0c38b9f4989f4 Mon Sep 17 00:00:00 2001 From: sergey-prikhodko Date: Mon, 20 Apr 2020 15:36:49 +0300 Subject: [PATCH 33/37] reload fix https://github.com/Yalantis/Koloda/issues/424 --- Pod/Classes/KolodaView/KolodaView.swift | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Pod/Classes/KolodaView/KolodaView.swift b/Pod/Classes/KolodaView/KolodaView.swift index 5fc404a1..eaa3d961 100644 --- a/Pod/Classes/KolodaView/KolodaView.swift +++ b/Pod/Classes/KolodaView/KolodaView.swift @@ -596,7 +596,9 @@ open class KolodaView: UIView, DraggableCardDelegate { public func reloadData() { guard let numberOfCards = dataSource?.kolodaNumberOfCards(self), numberOfCards > 0 else { + countOfCards = 0 clear() + return } From 134d93b24d64d8531c11a1e6d9be0747bab11682 Mon Sep 17 00:00:00 2001 From: sergey-prikhodko Date: Tue, 21 Apr 2020 11:32:36 +0300 Subject: [PATCH 34/37] fix swipePercentageMargin https://github.com/Yalantis/Koloda/issues/428 --- .../DraggableCardView/DraggableCardView.swift | 17 ++++++----------- Pod/Classes/KolodaView/KolodaView.swift | 2 +- 2 files changed, 7 insertions(+), 12 deletions(-) diff --git a/Pod/Classes/KolodaView/DraggableCardView/DraggableCardView.swift b/Pod/Classes/KolodaView/DraggableCardView/DraggableCardView.swift index d66782a7..d31d700a 100644 --- a/Pod/Classes/KolodaView/DraggableCardView/DraggableCardView.swift +++ b/Pod/Classes/KolodaView/DraggableCardView/DraggableCardView.swift @@ -67,7 +67,12 @@ public class DraggableCardView: UIView, UIGestureRecognizerDelegate { private var tapGestureRecognizer: UITapGestureRecognizer! private var animationDirectionY: CGFloat = 1.0 private var dragDistance = CGPoint.zero - private var swipePercentageMargin: CGFloat = 0.0 + + private var swipePercentageMargin: CGFloat { + let percentage = delegate?.card(cardSwipeThresholdRatioMargin: self) ?? 0.0 + + return percentage != 0.0 ? percentage : 1.0 + } //MARK: Lifecycle @@ -86,16 +91,6 @@ public class DraggableCardView: UIView, UIGestureRecognizerDelegate { setup() } - override public var frame: CGRect { - didSet { - if let ratio = delegate?.card(cardSwipeThresholdRatioMargin: self) , ratio != 0 { - swipePercentageMargin = ratio - } else { - swipePercentageMargin = 1.0 - } - } - } - deinit { removeGestureRecognizer(panGestureRecognizer) removeGestureRecognizer(tapGestureRecognizer) diff --git a/Pod/Classes/KolodaView/KolodaView.swift b/Pod/Classes/KolodaView/KolodaView.swift index eaa3d961..7fefd9ab 100644 --- a/Pod/Classes/KolodaView/KolodaView.swift +++ b/Pod/Classes/KolodaView/KolodaView.swift @@ -80,7 +80,7 @@ public extension KolodaViewDelegate { func kolodaShouldTransparentizeNextCard(_ koloda: KolodaView) -> Bool { return true } func koloda(_ koloda: KolodaView, draggedCardWithPercentage finishPercentage: CGFloat, in direction: SwipeResultDirection) {} func kolodaDidResetCard(_ koloda: KolodaView) {} - func kolodaSwipeThresholdRatioMargin(_ koloda: KolodaView) -> CGFloat? { return nil} + func kolodaSwipeThresholdRatioMargin(_ koloda: KolodaView) -> CGFloat? { return nil } func koloda(_ koloda: KolodaView, didShowCardAt index: Int) {} func koloda(_ koloda: KolodaView, didRewindTo index: Int) {} func koloda(_ koloda: KolodaView, shouldDragCardAt index: Int ) -> Bool { return true } From 16a5004d4da98d66882702a1e6fd6548954d5c0c Mon Sep 17 00:00:00 2001 From: Max Sysenko Date: Sat, 9 Jan 2021 17:00:18 +0200 Subject: [PATCH 35/37] Fix example project --- .../Koloda/BackgroundAnimationViewController.swift | 5 ++++- Example/Koloda/ViewController.swift | 5 ++++- Pod/Classes/KolodaView/KolodaView.swift | 11 +---------- 3 files changed, 9 insertions(+), 12 deletions(-) diff --git a/Example/Koloda/BackgroundAnimationViewController.swift b/Example/Koloda/BackgroundAnimationViewController.swift index ee6f544e..07869ba9 100644 --- a/Example/Koloda/BackgroundAnimationViewController.swift +++ b/Example/Koloda/BackgroundAnimationViewController.swift @@ -49,7 +49,10 @@ class BackgroundAnimationViewController: UIViewController { //MARK: KolodaViewDelegate extension BackgroundAnimationViewController: KolodaViewDelegate { - + func koloda(_ koloda: KolodaView, willShow card: UIView, at index: Int) { + + } + func kolodaDidRunOutOfCards(_ koloda: KolodaView) { kolodaView.resetCurrentCardIndex() } diff --git a/Example/Koloda/ViewController.swift b/Example/Koloda/ViewController.swift index 91e8221c..c670edef 100644 --- a/Example/Koloda/ViewController.swift +++ b/Example/Koloda/ViewController.swift @@ -54,7 +54,10 @@ class ViewController: UIViewController { // MARK: KolodaViewDelegate extension ViewController: KolodaViewDelegate { - + func koloda(_ koloda: KolodaView, willShow card: UIView, at index: Int) { + + } + func kolodaDidRunOutOfCards(_ koloda: KolodaView) { let position = kolodaView.currentCardIndex for i in 1...4 { diff --git a/Pod/Classes/KolodaView/KolodaView.swift b/Pod/Classes/KolodaView/KolodaView.swift index c041440b..81901058 100644 --- a/Pod/Classes/KolodaView/KolodaView.swift +++ b/Pod/Classes/KolodaView/KolodaView.swift @@ -112,7 +112,6 @@ open class KolodaView: UIView, DraggableCardDelegate { public var reverseAnimationDuration = defaultReverseAnimationDuration public var countOfVisibleCards = defaultCountOfVisibleCards - public var backgroundCardsTopMargin = defaultBackgroundCardsTopMargin public var backgroundCardsScalePercent = defaultBackgroundCardsScalePercent // Visible cards direction (defaults to bottom) @@ -151,11 +150,6 @@ open class KolodaView: UIView, DraggableCardDelegate { } internal var animationSemaphore = KolodaAnimationSemaphore() - public var isRunOutOfCards: Bool { - - return visibleCards.isEmpty - } - private lazy var _animator: KolodaViewAnimator = { return KolodaViewAnimator(koloda: self) }() @@ -651,14 +645,11 @@ open class KolodaView: UIView, DraggableCardDelegate { animationSemaphore.increment() - frontCard.swipe(direction) { + frontCard.swipe(direction, forced: force) { self.animationSemaphore.decrement() } frontCard.delegate = nil } - - frontCard.swipe(direction, forced: force) {} - frontCard.delegate = nil } } From 88cff5a7852bfe51b6d8a6e6b414ee0a8ad27d4a Mon Sep 17 00:00:00 2001 From: Max Sysenko Date: Fri, 16 Apr 2021 14:03:08 +0300 Subject: [PATCH 36/37] Fix forced swipe to the restricted direction --- Pod/Classes/KolodaView/KolodaView.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Pod/Classes/KolodaView/KolodaView.swift b/Pod/Classes/KolodaView/KolodaView.swift index 81901058..66c732a6 100644 --- a/Pod/Classes/KolodaView/KolodaView.swift +++ b/Pod/Classes/KolodaView/KolodaView.swift @@ -633,7 +633,7 @@ open class KolodaView: UIView, DraggableCardDelegate { guard force || shouldSwipe else { return } let validDirection = delegate?.koloda(self, allowedDirectionsForIndex: currentCardIndex).contains(direction) ?? true - guard validDirection else { return } + guard force || validDirection else { return } if !animationSemaphore.isAnimating { if let frontCard = visibleCards.first, !frontCard.dragBegin { From 270d8f62a7502e6449bd81192045a0dff4566281 Mon Sep 17 00:00:00 2001 From: Max Sysenko Date: Thu, 29 Apr 2021 11:34:11 +0300 Subject: [PATCH 37/37] Fix forced swipe speed --- Pod/Classes/KolodaView/KolodaView.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Pod/Classes/KolodaView/KolodaView.swift b/Pod/Classes/KolodaView/KolodaView.swift index 66c732a6..9b4dab32 100644 --- a/Pod/Classes/KolodaView/KolodaView.swift +++ b/Pod/Classes/KolodaView/KolodaView.swift @@ -635,7 +635,7 @@ open class KolodaView: UIView, DraggableCardDelegate { let validDirection = delegate?.koloda(self, allowedDirectionsForIndex: currentCardIndex).contains(direction) ?? true guard force || validDirection else { return } - if !animationSemaphore.isAnimating { + if !animationSemaphore.isAnimating || force { if let frontCard = visibleCards.first, !frontCard.dragBegin { if visibleCards.count > 1 {