From 71415a1758e768e4ae166894a6266c1de24d16c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andre=CC=81=20Santana=20Ferreira?= Date: Thu, 21 May 2020 17:40:54 -0300 Subject: [PATCH 1/6] added print for debug --- Sources/Shuffle/SwipeCard/CardTransformProvider.swift | 4 ++++ .../SwipeCardStack/CardStackTransformProvider.swift | 8 ++++++++ 2 files changed, 12 insertions(+) diff --git a/Sources/Shuffle/SwipeCard/CardTransformProvider.swift b/Sources/Shuffle/SwipeCard/CardTransformProvider.swift index b8037031..269e5094 100644 --- a/Sources/Shuffle/SwipeCard/CardTransformProvider.swift +++ b/Sources/Shuffle/SwipeCard/CardTransformProvider.swift @@ -61,10 +61,14 @@ class CardTransformProvider: CardTransformProvidable { } func transform(for card: SwipeCard) -> CGAffineTransform { + print(#function) let dragTranslation = card.panGestureRecognizer.translation(in: card) let translation = CGAffineTransform(translationX: dragTranslation.x, y: dragTranslation.y) let rotation = CGAffineTransform(rotationAngle: rotationAngle(for: card)) + print("drag translation ", dragTranslation) + print("translation ", translation) + print("ROTATION ", rotation) return translation.concatenating(rotation) } } diff --git a/Sources/Shuffle/SwipeCardStack/CardStackTransformProvider.swift b/Sources/Shuffle/SwipeCardStack/CardStackTransformProvider.swift index 1c4c7799..93ee0879 100644 --- a/Sources/Shuffle/SwipeCardStack/CardStackTransformProvider.swift +++ b/Sources/Shuffle/SwipeCardStack/CardStackTransformProvider.swift @@ -39,6 +39,7 @@ class CardStackTransformProvider: CardStackTransformProvidable { func backgroundCardDragTransform(for cardStack: SwipeCardStack, topCard: SwipeCard, topCardIndex: Int) -> CGAffineTransform { + print(#function) let percentage = backgroundCardTransformPercentage(for: cardStack, topCard: topCard) let currentScale = cardStack.scaleFactor(forCardAtIndex: topCardIndex) @@ -47,12 +48,19 @@ class CardStackTransformProvider: CardStackTransformProvidable { let scaleX = (1 - percentage) * currentScale.x + percentage * nextScale.x let scaleY = (1 - percentage) * currentScale.y + percentage * nextScale.y + print(scaleX) + print(scaleY) return CGAffineTransform(scaleX: scaleX, y: scaleY) } func backgroundCardTransformPercentage(for cardStack: SwipeCardStack, topCard: SwipeCard) -> CGFloat { + print(#function) let panTranslation = topCard.panGestureRecognizer.translation(in: cardStack) let minimumSideLength = min(cardStack.bounds.width, cardStack.bounds.height) + + print(panTranslation) + print(minimumSideLength) + return max(min(2 * abs(panTranslation.x) / minimumSideLength, 1), min(2 * abs(panTranslation.y) / minimumSideLength, 1)) } From 2959fd9f527363da4e4287a904ddbad06e19cce7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andre=CC=81=20Santana=20Ferreira?= Date: Fri, 22 May 2020 16:48:24 -0300 Subject: [PATCH 2/6] Change Translation Y --- Sources/Shuffle/SwipeCard/CardTransformProvider.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/Shuffle/SwipeCard/CardTransformProvider.swift b/Sources/Shuffle/SwipeCard/CardTransformProvider.swift index 269e5094..7440692c 100644 --- a/Sources/Shuffle/SwipeCard/CardTransformProvider.swift +++ b/Sources/Shuffle/SwipeCard/CardTransformProvider.swift @@ -64,7 +64,7 @@ class CardTransformProvider: CardTransformProvidable { print(#function) let dragTranslation = card.panGestureRecognizer.translation(in: card) let translation = CGAffineTransform(translationX: dragTranslation.x, - y: dragTranslation.y) + y: 0) let rotation = CGAffineTransform(rotationAngle: rotationAngle(for: card)) print("drag translation ", dragTranslation) print("translation ", translation) From b57a1115a113c155b354a45e964fe63a7f4660c9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andre=CC=81=20Santana=20Ferreira?= Date: Fri, 22 May 2020 18:13:44 -0300 Subject: [PATCH 3/6] Added Axis in SwipeView to transform in defined axis. --- README.md | 3 +- Shuffle-iOS.podspec | 4 +- Sources/Shuffle/Axis.swift | 55 +++++++++++++++++++ .../SwipeCard/CardTransformProvider.swift | 7 +-- Sources/Shuffle/SwipeCard/SwipeView.swift | 4 ++ .../CardStackTransformProvider.swift | 10 +--- 6 files changed, 65 insertions(+), 18 deletions(-) create mode 100644 Sources/Shuffle/Axis.swift diff --git a/README.md b/README.md index 54cb8fd3..906e915f 100644 --- a/README.md +++ b/README.md @@ -47,6 +47,7 @@ To run the example project, clone the repo and run the `ShuffleExample` target. func card(fromImage image: UIImage) -> SwipeCard { let card = SwipeCard() card.swipeDirections = [.left, .right] + card.axis = .horizontal card.content = UIImageView(image: image) let leftOverlay = UIView() @@ -193,4 +194,4 @@ We love to hear about apps that use Shuffle - feel free to submit a pull request ---

-Made with ❤️ by Mac Gallagher \ No newline at end of file +Made with ❤️ by Mac Gallagher diff --git a/Shuffle-iOS.podspec b/Shuffle-iOS.podspec index 57f419b0..82c7b975 100644 --- a/Shuffle-iOS.podspec +++ b/Shuffle-iOS.podspec @@ -1,7 +1,7 @@ Pod::Spec.new do |s| s.name = "Shuffle-iOS" -s.version = "0.2.2" +s.version = "0.3.0" s.platform = :ios, "9.0" s.summary = "A multi-directional card swiping library inspired by Tinder" @@ -13,7 +13,7 @@ s.homepage = "https://github.com/mac-gallagher/Shuffle" s.documentation_url = "https://github.com/mac-gallagher/Shuffle/tree/master/README.md" s.license = { :type => 'MIT', :file => 'LICENSE' } s.author = { "Mac Gallagher" => "jmgallagher36@gmail.com" } -s.source = { :git => "https://github.com/mac-gallagher/Shuffle.git", :tag => "v0.2.2" } +s.source = { :git => "https://github.com/mac-gallagher/Shuffle.git", :tag => "v0.3.0" } s.swift_version = "5.0" s.source_files = "Sources/**/*.{h,swift}" diff --git a/Sources/Shuffle/Axis.swift b/Sources/Shuffle/Axis.swift new file mode 100644 index 00000000..58c1fe04 --- /dev/null +++ b/Sources/Shuffle/Axis.swift @@ -0,0 +1,55 @@ +/// +/// MIT License +/// +/// Copyright (c) 2020 Mac Gallagher +/// +/// 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: +/// +/// The above copyright notice and this permission notice shall be included in all +/// copies or substantial portions of the Software. +/// +/// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +/// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +/// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +/// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +/// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +/// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +/// SOFTWARE. +/// + +import UIKit + +/// A type representing the axis of a physical drag animation. +@objc public enum Axis: Int, CustomStringConvertible { + + case vertical, horizontal, all + + /// The `Axis` translation represented as a CGAffineTransform + public func translation(_ point: CGPoint) -> CGAffineTransform { + switch self { + case .vertical: + return CGAffineTransform(translationX: 0, y: point.y) + case .horizontal: + return CGAffineTransform(translationX: point.x, y: 0) + case .all: + return CGAffineTransform(translationX: point.x, y: point.y) + } + } + + /// A textual representation of the `Axis`. + public var description: String { + switch self { + case .vertical: + return "vertical" + case .horizontal: + return "horizontal" + case .all: + return "all" + } + } +} diff --git a/Sources/Shuffle/SwipeCard/CardTransformProvider.swift b/Sources/Shuffle/SwipeCard/CardTransformProvider.swift index 7440692c..f7e37b8a 100644 --- a/Sources/Shuffle/SwipeCard/CardTransformProvider.swift +++ b/Sources/Shuffle/SwipeCard/CardTransformProvider.swift @@ -61,14 +61,9 @@ class CardTransformProvider: CardTransformProvidable { } func transform(for card: SwipeCard) -> CGAffineTransform { - print(#function) let dragTranslation = card.panGestureRecognizer.translation(in: card) - let translation = CGAffineTransform(translationX: dragTranslation.x, - y: 0) + let translation = card.axis.translation(dragTranslation) let rotation = CGAffineTransform(rotationAngle: rotationAngle(for: card)) - print("drag translation ", dragTranslation) - print("translation ", translation) - print("ROTATION ", rotation) return translation.concatenating(rotation) } } diff --git a/Sources/Shuffle/SwipeCard/SwipeView.swift b/Sources/Shuffle/SwipeCard/SwipeView.swift index bcb5e6b2..fcaaa5f7 100644 --- a/Sources/Shuffle/SwipeCard/SwipeView.swift +++ b/Sources/Shuffle/SwipeCard/SwipeView.swift @@ -35,6 +35,10 @@ open class SwipeView: UIView { /// Defaults to `SwipeDirection.allDirections`. open var swipeDirections = SwipeDirection.allDirections + /// The axis to be animate card in all axis. Set this variable to ignore certain axis. + /// Defaults to `Axis.all`. + open var axis = Axis.all + /// The pan gesture recognizer attached to the view. public var panGestureRecognizer: UIPanGestureRecognizer { return internalPanGestureRecognizer diff --git a/Sources/Shuffle/SwipeCardStack/CardStackTransformProvider.swift b/Sources/Shuffle/SwipeCardStack/CardStackTransformProvider.swift index 93ee0879..dea79c4e 100644 --- a/Sources/Shuffle/SwipeCardStack/CardStackTransformProvider.swift +++ b/Sources/Shuffle/SwipeCardStack/CardStackTransformProvider.swift @@ -39,7 +39,6 @@ class CardStackTransformProvider: CardStackTransformProvidable { func backgroundCardDragTransform(for cardStack: SwipeCardStack, topCard: SwipeCard, topCardIndex: Int) -> CGAffineTransform { - print(#function) let percentage = backgroundCardTransformPercentage(for: cardStack, topCard: topCard) let currentScale = cardStack.scaleFactor(forCardAtIndex: topCardIndex) @@ -47,20 +46,13 @@ class CardStackTransformProvider: CardStackTransformProvidable { let scaleX = (1 - percentage) * currentScale.x + percentage * nextScale.x let scaleY = (1 - percentage) * currentScale.y + percentage * nextScale.y - - print(scaleX) - print(scaleY) + return CGAffineTransform(scaleX: scaleX, y: scaleY) } func backgroundCardTransformPercentage(for cardStack: SwipeCardStack, topCard: SwipeCard) -> CGFloat { - print(#function) let panTranslation = topCard.panGestureRecognizer.translation(in: cardStack) let minimumSideLength = min(cardStack.bounds.width, cardStack.bounds.height) - - print(panTranslation) - print(minimumSideLength) - return max(min(2 * abs(panTranslation.x) / minimumSideLength, 1), min(2 * abs(panTranslation.y) / minimumSideLength, 1)) } From d2af932e01887f385e66cbb5fe603d2be2c67359 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andre=CC=81=20Santana=20Ferreira?= Date: Fri, 29 May 2020 18:40:47 -0300 Subject: [PATCH 4/6] added Axis in example project. --- Example/TinderExample/TinderViewController.swift | 1 + Shuffle.xcodeproj/project.pbxproj | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/Example/TinderExample/TinderViewController.swift b/Example/TinderExample/TinderViewController.swift index 78cc1a36..21100191 100644 --- a/Example/TinderExample/TinderViewController.swift +++ b/Example/TinderExample/TinderViewController.swift @@ -128,6 +128,7 @@ extension TinderViewController: ButtonStackViewDelegate, SwipeCardStackDataSourc let card = SwipeCard() card.footerHeight = 80 card.swipeDirections = [.left, .up, .right] + card.axis = .all for direction in card.swipeDirections { card.setOverlay(TinderCardOverlay(direction: direction), forDirection: direction) } diff --git a/Shuffle.xcodeproj/project.pbxproj b/Shuffle.xcodeproj/project.pbxproj index 05468702..754db98b 100644 --- a/Shuffle.xcodeproj/project.pbxproj +++ b/Shuffle.xcodeproj/project.pbxproj @@ -8,6 +8,7 @@ /* Begin PBXBuildFile section */ 2FA5AD296FDB91FF5EFDF160 /* Pods_ShuffleExample.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = BEAD69E2973AE33655E1E380 /* Pods_ShuffleExample.framework */; }; + 65AD978A2481B093008D3A79 /* Axis.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65AD97892481B093008D3A79 /* Axis.swift */; }; 881FD28C231B78FB003ACA43 /* CardStackAnimationOptionsSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 881FD28B231B78FB003ACA43 /* CardStackAnimationOptionsSpec.swift */; }; AD0542C02271397900B42353 /* Shuffle.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = AD72AC5D2270E5E20083E735 /* Shuffle.framework */; }; AD10982922879C42008CB197 /* CardAnimationOptions.swift in Sources */ = {isa = PBXBuildFile; fileRef = AD10982322879C42008CB197 /* CardAnimationOptions.swift */; }; @@ -113,6 +114,7 @@ 1BF3810F67E55447192823D9 /* Pods-ShuffleTests.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-ShuffleTests.debug.xcconfig"; path = "Target Support Files/Pods-ShuffleTests/Pods-ShuffleTests.debug.xcconfig"; sourceTree = ""; }; 3A1DBC86C688BB1F0E7FD862 /* Pods-ShuffleTests.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-ShuffleTests.release.xcconfig"; path = "Target Support Files/Pods-ShuffleTests/Pods-ShuffleTests.release.xcconfig"; sourceTree = ""; }; 4CEAEBE96CF9FA466E2206E4 /* Pods-ShuffleExample.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-ShuffleExample.release.xcconfig"; path = "Target Support Files/Pods-ShuffleExample/Pods-ShuffleExample.release.xcconfig"; sourceTree = ""; }; + 65AD97892481B093008D3A79 /* Axis.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Axis.swift; sourceTree = ""; }; 6C08D484FE19F2D4B9F553F2 /* Pods_ShuffleTests.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_ShuffleTests.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 881FD28B231B78FB003ACA43 /* CardStackAnimationOptionsSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CardStackAnimationOptionsSpec.swift; sourceTree = ""; }; A3A4F8A2C0F39A32B57F12BE /* Pods-ShuffleExample.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-ShuffleExample.debug.xcconfig"; path = "Target Support Files/Pods-ShuffleExample/Pods-ShuffleExample.debug.xcconfig"; sourceTree = ""; }; @@ -305,6 +307,7 @@ AD18F0DE22B9F874007BACE9 /* Shuffle */ = { isa = PBXGroup; children = ( + 65AD97892481B093008D3A79 /* Axis.swift */, AD72AC6F2270E6380083E735 /* SwipeDirection.swift */, AD10982222879C42008CB197 /* SwipeCard */, ADA444D522AC651B00AFAFFE /* SwipeCardStack */, @@ -787,6 +790,7 @@ AD52EF8122E5088B0063AE5D /* CardTransformProvider.swift in Sources */, AD514C5B22A08D5600BD8F3E /* CardLayoutProvider.swift in Sources */, AD72AC9A2270FCCE0083E735 /* SwipeDirection.swift in Sources */, + 65AD978A2481B093008D3A79 /* Axis.swift in Sources */, ADA444D922AC658E00AFAFFE /* SwipeCardStackDataSource.swift in Sources */, AD52EF8722E523020063AE5D /* CardStackTransformProvider.swift in Sources */, ADEE86D722ACE5AA00AAE7A1 /* Array+Extensions.swift in Sources */, From 1dd6bc55275cfbeb3e6beee5d78d427a65a2c731 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andre=CC=81=20Santana=20Ferreira?= Date: Sat, 30 May 2020 01:08:48 -0300 Subject: [PATCH 5/6] Fix code review --- Example/TinderExample/TinderViewController.swift | 1 - README.md | 1 - Shuffle-iOS.podspec | 2 +- Sources/Shuffle/Axis.swift | 3 +-- 4 files changed, 2 insertions(+), 5 deletions(-) diff --git a/Example/TinderExample/TinderViewController.swift b/Example/TinderExample/TinderViewController.swift index a7f933c4..dc8ae2dd 100644 --- a/Example/TinderExample/TinderViewController.swift +++ b/Example/TinderExample/TinderViewController.swift @@ -134,7 +134,6 @@ extension TinderViewController: ButtonStackViewDelegate, SwipeCardStackDataSourc let card = SwipeCard() card.footerHeight = 80 card.swipeDirections = [.left, .up, .right] - card.axis = .all for direction in card.swipeDirections { card.setOverlay(TinderCardOverlay(direction: direction), forDirection: direction) } diff --git a/README.md b/README.md index 906e915f..36f0e578 100644 --- a/README.md +++ b/README.md @@ -47,7 +47,6 @@ To run the example project, clone the repo and run the `ShuffleExample` target. func card(fromImage image: UIImage) -> SwipeCard { let card = SwipeCard() card.swipeDirections = [.left, .right] - card.axis = .horizontal card.content = UIImageView(image: image) let leftOverlay = UIView() diff --git a/Shuffle-iOS.podspec b/Shuffle-iOS.podspec index 17d31d6c..d624fa7d 100644 --- a/Shuffle-iOS.podspec +++ b/Shuffle-iOS.podspec @@ -1,7 +1,7 @@ Pod::Spec.new do |s| s.name = "Shuffle-iOS" -s.version = "0.3.0" +s.version = "0.2.5" s.platform = :ios, "9.0" s.summary = "A multi-directional card swiping library inspired by Tinder" diff --git a/Sources/Shuffle/Axis.swift b/Sources/Shuffle/Axis.swift index 58c1fe04..446b9d07 100644 --- a/Sources/Shuffle/Axis.swift +++ b/Sources/Shuffle/Axis.swift @@ -25,7 +25,7 @@ import UIKit /// A type representing the axis of a physical drag animation. -@objc public enum Axis: Int, CustomStringConvertible { +@objc public enum Axis: Int { case vertical, horizontal, all @@ -41,7 +41,6 @@ import UIKit } } - /// A textual representation of the `Axis`. public var description: String { switch self { case .vertical: From 6d241761127eedb094a9e6edb604008e32e6b966 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andre=CC=81=20Santana=20Ferreira?= Date: Sat, 30 May 2020 01:12:52 -0300 Subject: [PATCH 6/6] Removed alterations in .podspec --- Shuffle-iOS.podspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Shuffle-iOS.podspec b/Shuffle-iOS.podspec index d624fa7d..deb01b6d 100644 --- a/Shuffle-iOS.podspec +++ b/Shuffle-iOS.podspec @@ -13,7 +13,7 @@ s.homepage = "https://github.com/mac-gallagher/Shuffle" s.documentation_url = "https://github.com/mac-gallagher/Shuffle/tree/master/README.md" s.license = { :type => 'MIT', :file => 'LICENSE' } s.author = { "Mac Gallagher" => "jmgallagher36@gmail.com" } -s.source = { :git => "https://github.com/mac-gallagher/Shuffle.git", :tag => "v0.3.0" } +s.source = { :git => "https://github.com/mac-gallagher/Shuffle.git", :tag => "v0.2.5" } s.swift_version = "5.0" s.source_files = "Sources/**/*.{h,swift}"