diff --git a/Example/Pods/Target Support Files/Pods-MyTinderSwipingAnimation_Tests/Pods-MyTinderSwipingAnimation_Tests-Info.plist b/Example/Pods/Target Support Files/Pods-MyTinderSwipingAnimation_Tests/Pods-MyTinderSwipingAnimation_Tests-Info.plist
index 7a085d0..a6c435e 100644
--- a/Example/Pods/Target Support Files/Pods-MyTinderSwipingAnimation_Tests/Pods-MyTinderSwipingAnimation_Tests-Info.plist
+++ b/Example/Pods/Target Support Files/Pods-MyTinderSwipingAnimation_Tests/Pods-MyTinderSwipingAnimation_Tests-Info.plist
@@ -15,7 +15,7 @@
CFBundlePackageType
FMWK
CFBundleShortVersionString
- 1.7.3
+ 1.8
CFBundleSignature
????
CFBundleVersion
diff --git a/Example/Tests/Info.plist b/Example/Tests/Info.plist
index f1ae7a2..def723c 100644
--- a/Example/Tests/Info.plist
+++ b/Example/Tests/Info.plist
@@ -15,7 +15,7 @@
CFBundlePackageType
BNDL
CFBundleShortVersionString
- 1.7.3
+ 1.8
CFBundleSignature
????
CFBundleVersion
diff --git a/MyTinderSwipingAnimation.podspec b/MyTinderSwipingAnimation.podspec
index da654fc..c5dbe41 100644
--- a/MyTinderSwipingAnimation.podspec
+++ b/MyTinderSwipingAnimation.podspec
@@ -8,7 +8,7 @@
Pod::Spec.new do |s|
s.name = 'MyTinderSwipingAnimation'
- s.version = '1.7.3'
+ s.version = '1.8'
s.summary = 'TinderSwipingAnimation is an easy to use library written using SwiftUI to simplify the implementation of the tinder swipe animation.'
# This description is used to generate tags and improve search results.
diff --git a/Sources/TinderSwipingAnimation/Components/CustomButton.swift b/Sources/TinderSwipingAnimation/Components/CustomButton.swift
index ae68016..b4ed82d 100644
--- a/Sources/TinderSwipingAnimation/Components/CustomButton.swift
+++ b/Sources/TinderSwipingAnimation/Components/CustomButton.swift
@@ -24,6 +24,8 @@ struct CustomButton: View {
viewModel.goTop = true
case .goBottom:
viewModel.goBottom = true
+ case .undo:
+ viewModel.undo = true
}
}) {
button.image
diff --git a/Sources/TinderSwipingAnimation/Models/ButtonModel.swift b/Sources/TinderSwipingAnimation/Models/ButtonModel.swift
index f0ab742..0debd0b 100644
--- a/Sources/TinderSwipingAnimation/Models/ButtonModel.swift
+++ b/Sources/TinderSwipingAnimation/Models/ButtonModel.swift
@@ -23,5 +23,6 @@ public struct ButtonModel {
case goLeft
case goTop
case goBottom
+ case undo
}
}
diff --git a/Sources/TinderSwipingAnimation/Models/Direction.swift b/Sources/TinderSwipingAnimation/Models/Direction.swift
index eb26e66..426cb25 100644
--- a/Sources/TinderSwipingAnimation/Models/Direction.swift
+++ b/Sources/TinderSwipingAnimation/Models/Direction.swift
@@ -13,12 +13,14 @@ public enum Direction {
case left
case top
case bottom
+ case undo
public var description: String {
switch self {
case .right: return "right"
case .left: return "left"
case .top: return "top"
case .bottom: return "bottom"
+ case .undo: return "undo"
}
}
}
diff --git a/Sources/TinderSwipingAnimation/ViewModels/TinderViewModel.swift b/Sources/TinderSwipingAnimation/ViewModels/TinderViewModel.swift
index adc2bd2..4288375 100644
--- a/Sources/TinderSwipingAnimation/ViewModels/TinderViewModel.swift
+++ b/Sources/TinderSwipingAnimation/ViewModels/TinderViewModel.swift
@@ -19,4 +19,5 @@ class TinderViewModel: ObservableObject {
@Published var goLeft: Bool = false
@Published var goTop: Bool = false
@Published var goBottom: Bool = false
+ @Published var undo: Bool = false
}
diff --git a/Sources/TinderSwipingAnimation/Views/CardView.swift b/Sources/TinderSwipingAnimation/Views/CardView.swift
index e0f18fe..d08e9a4 100644
--- a/Sources/TinderSwipingAnimation/Views/CardView.swift
+++ b/Sources/TinderSwipingAnimation/Views/CardView.swift
@@ -38,6 +38,9 @@ struct CardView: View {
viewModel.$goBottom.sink { _ in
}
.store(in: &subscriptions)
+ viewModel.$undo.sink { _ in
+ }
+ .store(in: &subscriptions)
}
var body: some View {
ZStack {
@@ -45,7 +48,7 @@ struct CardView: View {
Card(card: cards[i], buttons: buttons, viewModel: viewModel, orientation: orientation, backgroundColor: backgroundColor)
.offset(x: self.x[i],y: y[i])
.rotationEffect(.init(degrees: degree[i]))
- .onChange(of: viewModel.goRight || viewModel.goLeft || viewModel.goBottom || viewModel.goTop) {
+ .onChange(of: viewModel.goRight || viewModel.goLeft || viewModel.goBottom || viewModel.goTop || viewModel.undo) {
if viewModel.goRight && abs(degree[i]) != 12 && abs(degree[i]) != 1 {
withAnimation(.default) {
viewModel.goRight = false
@@ -86,6 +89,19 @@ struct CardView: View {
viewModel.cards[i].thumbsUpOpacity = 0
viewModel.cards[i].thumbsDownOpacity = 0
}
+ } else if viewModel.undo {
+ viewModel.undo = false
+ if let lastIndex = degree.firstIndex(where: {abs($0) == 1 || abs($0) == 12}) {
+ withAnimation(.default) {
+ self.x[lastIndex] = 0
+ self.y[lastIndex] = 0
+ self.offset = 0
+ self.degree[lastIndex] = 0
+ viewModel.cardSwiped = (cards[i],Direction.undo)
+ viewModel.cards[i].thumbsUpOpacity = 0
+ viewModel.cards[i].thumbsDownOpacity = 0
+ }
+ }
}
}
.gesture(DragGesture()