Skip to content

Commit

Permalink
Change the way options are implemented
Browse files Browse the repository at this point in the history
  • Loading branch information
omarthamri committed Dec 3, 2023
1 parent 3064756 commit 9d206c8
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 7 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Example/Tests/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<key>CFBundlePackageType</key>
<string>BNDL</string>
<key>CFBundleShortVersionString</key>
<string>1.9.1</string>
<string>1.9.2</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
Expand Down
2 changes: 1 addition & 1 deletion MyTinderSwipingAnimation.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

Pod::Spec.new do |s|
s.name = 'MyTinderSwipingAnimation'
s.version = '1.9.1'
s.version = '1.9.2'
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.
Expand Down
7 changes: 6 additions & 1 deletion Sources/TinderSwipingAnimation/Models/TextOrientation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,15 @@
// Created by omar thamri on 30/11/2023.
//

import Foundation
import SwiftUI


public enum TextOrientation {
case horizontal
case vertical
}

public enum TinderSwipingAnimationOption: Hashable {
case orientation(TextOrientation)
case backgroundColor(Color)
}
16 changes: 13 additions & 3 deletions Sources/TinderSwipingAnimation/Views/TinderSwipingAnimation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,26 @@ public struct TinderSwipingAnimation: View {

var cards: [CardModel]
var buttons: [ButtonModel]
var options: [String: Any] = ["orientation" : TextOrientation.vertical,"backgroundColor": Color.white]
var options: [TinderSwipingAnimationOption]
var orientation: TextOrientation = .vertical
var backgroundColor: Color = .white
var onSwipe: (_ cardModel: CardModel,_ direction: Direction) -> () = {_,_ in }
private var subscriptions: Set<AnyCancellable> = []
private var viewModel = TinderViewModel()
public init(cards: [CardModel], buttons: [ButtonModel],onSwipe: @escaping (_ cardModel: CardModel,_ direction: Direction) -> (),options: [String: Any] = ["orientation" : TextOrientation.vertical,"backgroundColor": Color.white] ) {
public init(cards: [CardModel], buttons: [ButtonModel],onSwipe: @escaping (_ cardModel: CardModel,_ direction: Direction) -> (),options: [TinderSwipingAnimationOption] = [.orientation(.vertical),.backgroundColor(.white)] ) {
self.cards = cards
self.buttons = buttons
self.options = options
self.onSwipe = onSwipe
viewModel.cards = cards
for i in 0 ..< options.count {
switch options[i] {
case .orientation(let orientation):
self.orientation = orientation
case .backgroundColor(let backgroundColor):
self.backgroundColor = backgroundColor
}
}
viewModel.$cardSwiped.sink { [self] (card,direction) in
guard let card = card, let direction = direction else { return }
self.onSwipe(card,direction)
Expand All @@ -30,7 +40,7 @@ public struct TinderSwipingAnimation: View {
}

public var body: some View {
return CardView(cards: cards, buttons: buttons,viewModel: viewModel, orientation: options["orientation"] as? TextOrientation ?? .vertical,backgroundColor: options["backgroundColor"] as? Color ?? .white)
CardView(cards: cards, buttons: buttons,viewModel: viewModel, orientation: orientation,backgroundColor: backgroundColor)
}


Expand Down

0 comments on commit 9d206c8

Please sign in to comment.