Skip to content

Commit

Permalink
Add background color option
Browse files Browse the repository at this point in the history
  • Loading branch information
omarthamri committed Dec 1, 2023
1 parent ca27b24 commit 49908c1
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 14 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.7.1</string>
<string>1.7.2</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
Expand Down
4 changes: 2 additions & 2 deletions MyTinderSwipingAnimation.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@

Pod::Spec.new do |s|
s.name = 'MyTinderSwipingAnimation'
s.version = '1.7.1'
s.summary = 'TinderSwipingAnimation is a library written using SwiftUI to simplify the implementation of the tinder swipe animation.'
s.version = '1.7.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.
# * Think: What does it do? Why did you write it? What is the focus?
Expand Down
6 changes: 4 additions & 2 deletions Sources/TinderSwipingAnimation/Views/Card.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,14 @@ struct Card: View {
var card: CardModel
var buttons: [ButtonModel]
var orientation: TextOrientation
var backgroundColor: Color
var viewModel: TinderViewModel
var subscriptions: Set<AnyCancellable> = []
init(card: CardModel, buttons: [ButtonModel], viewModel: TinderViewModel,orientation: TextOrientation) {
init(card: CardModel, buttons: [ButtonModel], viewModel: TinderViewModel,orientation: TextOrientation,backgroundColor: Color) {
self.card = card
self.buttons = buttons
self.orientation = orientation
self.backgroundColor = backgroundColor
self.viewModel = viewModel
self.viewModel.$titleColor.combineLatest(viewModel.$subtitleColor).sink { (_,_) in
}
Expand Down Expand Up @@ -58,7 +60,7 @@ struct Card: View {
ButtonsView(buttons: buttons, viewModel: viewModel)
}
}
.background(.white)
.background(backgroundColor)
.clipShape(RoundedRectangle(cornerRadius: 25))
if orientation == .vertical {
VStack(alignment: .leading,spacing: 12) {
Expand Down
6 changes: 4 additions & 2 deletions Sources/TinderSwipingAnimation/Views/CardView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,15 @@ struct CardView: View {
var cards: [CardModel]
var buttons: [ButtonModel]
var orientation: TextOrientation
var backgroundColor: Color
var subscriptions: Set<AnyCancellable> = []
@StateObject var viewModel: TinderViewModel
var onSwipe : (_ card: CardModel,_ direction: Direction) -> () = { (card,direction) in }
public init(cards: [CardModel], buttons: [ButtonModel],viewModel: TinderViewModel,orientation: TextOrientation) {
public init(cards: [CardModel], buttons: [ButtonModel],viewModel: TinderViewModel,orientation: TextOrientation,backgroundColor: Color) {
self.cards = cards
self.buttons = buttons
self.orientation = orientation
self.backgroundColor = backgroundColor
self._viewModel = StateObject(wrappedValue: viewModel)
viewModel.$goRight.sink { _ in
}
Expand All @@ -40,7 +42,7 @@ struct CardView: View {
var body: some View {
ZStack {
ForEach(0..<cards.count,id: \.self) { i in
Card(card: cards[i], buttons: buttons, viewModel: viewModel, orientation: orientation)
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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ public struct TinderSwipingAnimation: View {

var cards: [CardModel]
var buttons: [ButtonModel]
var options: [String: Any] = ["orientation" : TextOrientation.vertical]
var options: [String: Any] = ["orientation" : TextOrientation.vertical,"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] ) {
public init(cards: [CardModel], buttons: [ButtonModel],onSwipe: @escaping (_ cardModel: CardModel,_ direction: Direction) -> (),options: [String: Any] = ["orientation" : TextOrientation.vertical,"backgroundColor": Color.white] ) {
self.cards = cards
self.buttons = buttons
self.options = options
Expand All @@ -30,10 +30,7 @@ public struct TinderSwipingAnimation: View {
}

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


Expand Down

0 comments on commit 49908c1

Please sign in to comment.