Coder Social home page Coder Social logo

omarthamri / tinderswipinganimation Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 140 KB

TinderSwipingAnimation is an easy to use library written using SwiftUI to simplify the implementation of the tinder swipe animation.

License: MIT License

Swift 92.14% Ruby 7.86%
swifui tinder-cards tinder-swipe animations ios-animation swipe swiper tinder-swiper ios tinder

tinderswipinganimation's Introduction

TinderSwipingAnimation

TinderSwipingAnimation is an easy to use library written using SwiftUI to simplify the implementation of the tinder swipe animation.

Demo

Simulator Screen Recording - iPhone 15 Pro - 2023-12-02 at 00 28 02

Installation

Swift Package Manager

  • File > Swift Packages > Add Package Dependency
  • Add https://github.com/omarthamri/TinderSwipingAnimation.git
  • Select "Up to Next Major" with "1.9.2"

Cocoapods

target 'MyApp' do
  pod 'MyTinderSwipingAnimation', '~> 1.9'
end

The import statement in this case will be

import MyTinderSwipingAnimation

Xcode 15 made a significant change by setting the default value of the ENABLE_USER_SCRIPT_SANDBOXING Build Setting from NO to YES. As a result, when installing TinderSwipingAnimation with cocoapods we encounters an error related to missing file permissions, which typically manifests as follows: error: Sandbox: rsync.samba(10816) deny(1) file-read-data.

To resolve this issue, it is necessary to manually set the ENABLE_USER_SCRIPT_SANDBOXING setting to NO in Build Settings.

Usage

in the top of your view file add the code below:

import TinderSwipingAnimation

A basic implementation example would be like this:

struct ContentView: View {
    let cards: [CardModel] = [ // This is the data to be shown in Card
        CardModel(name: "Brie", imageName: "brie", age: "34"),
        CardModel(name: "Scarlett", imageName: "scarlett", age: "38"),
        CardModel(name: "Elizabeth", imageName: "elizabeth", age: "33")
    ]
    let buttons: [ButtonModel] = [ // those are the buttons to be shown in the card
        ButtonModel(image: Image(systemName: "xmark"), color: .pink),
        ButtonModel(image: Image(systemName: "heart.fill"), color: .red),
        ButtonModel(image: Image(systemName: "bubble.fill"), color: .purple),
        ButtonModel(image: Image(systemName: "bolt.fill"), color: .blue)
    ]
    var body: some View {
            TinderSwipingAnimation(cards: cards, buttons: buttons) { (cardModel,direction) in // Closure to be called when a card is swiped.
                print("Swiped \(cardModel.name) to \(direction.description)")
            }
        }
}

To Perform a swipe using buttons you just need to pass the action to do in the ButtonModel initializer.There are the following predefined actions .goLeft or .goRight or .goTop or .goBottom or .none. By default buttons are create with .none action.

let buttons: [ButtonModel] = [ // those are the buttons to be shown in the card
        ButtonModel(image: Image(systemName: "xmark"), color: .pink,action: .goLeft), // swipe left when button clicked
        ButtonModel(image: Image(systemName: "heart.fill"), color: .red,action: .goTop), // swipe top when button clicked
        ButtonModel(image: Image(systemName: "bubble.fill"), color: .purple,action: .goBottom), // swipe bottom when button clicked
        ButtonModel(image: Image(systemName: "bolt.fill"), color: .blue,action: .goRight) // swipe right when button clicked
        ]

To return the most recently swiped card to the top of your card stack you just need to pass the action .undo in the ButtonModel initializer.

ButtonModel(image: Image(systemName: "gobackward"), color: .pink,action: .undo)

If you want to modify the colors or fonts in the card

TinderSwipingAnimation(cards: cards, buttons: buttons) { (cardModel,direction) in // Closure to be called when a card is swiped.
            print("Swiped \(cardModel.name) to \(direction.description)")
        }
        .tinderSwipingStyle(titleColor: .red, subtitleColor: .red, titleFont: .largeTitle, subtitleFont: .largeTitle)

If you want to change the orientation of the text inside your card you can use options with .orientation. we got two orientations options .horizontal and .vertical. By default the text orientation inside the card is .vertical. You can also use options with .backgroundColor to change the background color of the card. By default the background color of the card is .white.

TinderSwipingAnimation(
                            cards: cards,
                            buttons: buttons,
                            onSwipe:  { (cardModel,direction) in // Closure to be called when a card is swiped.
                                print("Swiped \(cardModel.name) to \(direction.description)")
                            }, options: [
                                .orientation(.horizontal), // this is setting text orientation inside card to horizontal
                                .backgroundColor(.yellow) // This setting background color inside card to yellow
                            ])

Requirements

  • iOS 17.0+

Author

Omar Thamri, @ThamriOmar

License

TinderSwipingAnimation is released under the MIT license. See LICENSE for details.

tinderswipinganimation's People

Contributors

omarthamri avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.