Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Added lock to move the card on an axis #65

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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -227,4 +227,4 @@ We love to hear about apps that use Shuffle - feel free to submit a pull request
---

<p align="center">
Made with ❤️ by <a href="https://github.com/mac-gallagher">Mac Gallagher</a>
Made with ❤️ by <a href="https://github.com/mac-gallagher">Mac Gallagher</a>
3 changes: 1 addition & 2 deletions Shuffle-iOS.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +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" => "[email protected]" }
s.source = { :git => "https://github.com/mac-gallagher/Shuffle.git", :tag => "v0.2.6" }

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}"

Expand Down
4 changes: 4 additions & 0 deletions Shuffle.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
/* End PBXAggregateTarget section */

/* Begin PBXBuildFile section */
65AD978A2481B093008D3A79 /* Axis.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65AD97892481B093008D3A79 /* Axis.swift */; };
387D5E42FEF4A017C5407B1F /* Pods_ShuffleTests.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = AD73382D22D7142EE1082545 /* Pods_ShuffleTests.framework */; };
881FD28C231B78FB003ACA43 /* CardStackAnimationOptionsSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 881FD28B231B78FB003ACA43 /* CardStackAnimationOptionsSpec.swift */; };
904ADE5B4A83DD023287EB73 /* Pods_ShuffleExample.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 91AB74E2E12D2E4C970B6743 /* Pods_ShuffleExample.framework */; };
Expand Down Expand Up @@ -124,6 +125,7 @@
/* End PBXCopyFilesBuildPhase section */

/* Begin PBXFileReference section */
65AD97892481B093008D3A79 /* Axis.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Axis.swift; sourceTree = "<group>"; };
1070E8CB25529479CB067AD3 /* 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 = "<group>"; };
29C7C2F3D3AC996FDD3FFF70 /* 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 = "<group>"; };
604684987DE74002FE435206 /* 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 = "<group>"; };
Expand Down Expand Up @@ -318,6 +320,7 @@
AD18F0DE22B9F874007BACE9 /* Shuffle */ = {
isa = PBXGroup;
children = (
65AD97892481B093008D3A79 /* Axis.swift */,
AD72AC6F2270E6380083E735 /* SwipeDirection.swift */,
AD10982222879C42008CB197 /* SwipeCard */,
ADA444D522AC651B00AFAFFE /* SwipeCardStack */,
Expand Down Expand Up @@ -821,6 +824,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 */,
Expand Down
54 changes: 54 additions & 0 deletions Sources/Shuffle/Axis.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
///
/// 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 {

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)
}
}

public var description: String {
andre991 marked this conversation as resolved.
Show resolved Hide resolved
switch self {
case .vertical:
return "vertical"
case .horizontal:
return "horizontal"
case .all:
return "all"
}
}
}
3 changes: 1 addition & 2 deletions Sources/Shuffle/SwipeCard/CardTransformProvider.swift
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,7 @@ class CardTransformProvider: CardTransformProvidable {

func transform(for card: SwipeCard) -> CGAffineTransform {
let dragTranslation = card.panGestureRecognizer.translation(in: card)
let translation = CGAffineTransform(translationX: dragTranslation.x,
y: dragTranslation.y)
let translation = card.axis.translation(dragTranslation)
let rotation = CGAffineTransform(rotationAngle: rotationAngle(for: card))
return translation.concatenating(rotation)
}
Expand Down
4 changes: 4 additions & 0 deletions Sources/Shuffle/SwipeCard/SwipeView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class CardStackTransformProvider: CardStackTransformProvidable {

let scaleX = (1 - percentage) * currentScale.x + percentage * nextScale.x
let scaleY = (1 - percentage) * currentScale.y + percentage * nextScale.y

return CGAffineTransform(scaleX: scaleX, y: scaleY)
}

Expand Down