GithubHelp home page GithubHelp logo

dmswipecards's Introduction

Version License twitter: @dylan36032

image

Features

  • Swift 3
  • Custom views for the card & overlay
  • Generic
  • Dynamically add new cards on top or on the bottom
  • Lazy view loading

Setup

pod 'DMSwipeCards'

Usage

First import the module:

import DMSwipeCards

Next create an instance of a DMSwipeCardsView:
(Element can be your custom model, or just String)

let swipeView = DMSwipeCardsView<Element>(frame: frame,
                                          viewGenerator: viewGenerator,
                                          overlayGenerator: overlayGenerator)

Views get loaded lazy, so you have to provide DMSwipeCardsView with a ViewGenerator and optionally an OverlayGenerator.

let viewGenerator: (String, CGRect) -> (UIView) = { (element: Element, frame: CGRect) -> (UIView) in
  // return a UIView here
}

let overlayGenerator: (SwipeMode, CGRect) -> (UIView) = { (mode: SwipeMode, frame: CGRect) -> (UIView) in
  // return a UIView here
}

Adding cards

To add new cards, just call the addCards method with an array of the previously defined Element:

swipeView.addCards([Element], onTop: true)

Delegate

DMSwipeCardsView has a delegate property so you can get informed when a card has been swipped. The delegate has to implement following methods:

func swipedLeft(_ object: Any)
func swipedRight(_ object: Any)
func cardTapped(_ object: Any)
func reachedEndOfStack()

The object parameter is guarenteed to have the type Element. Sadly generics don't work here.

Example

For a nice working demo sample, please take a look the Example project.
To run the example, first run pod install in the Example directory.

Credits

Loosly based on TinderSimpleSwipeCards

dmswipecards's People

Contributors

basthomas avatar d-32 avatar kyleishie avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

dmswipecards's Issues

Event when a card is displayed

Hi,

I have to play a bunch of videos retrieved from the internet on cards. This is my view generator.

let viewGenerator: (Video, CGRect) -> (UIView) = { (video: Video, frame: CGRect) -> (UIView) in
      let containerView = UIView(frame: self.view.bounds)
      
      let asset = AVURLAsset(url: URL(string: video.url)!)
      asset.resourceLoader.setDelegate(self, queue: DispatchQueue.main)
      
      let player = AVPlayer(playerItem: AVPlayerItem(asset: asset))
      player.actionAtItemEnd = .none
      
      let playerLayer = AVPlayerLayer(player: player)
      playerLayer.frame = self.view.bounds
      playerLayer.backgroundColor = UIColor.clear.cgColor
      
      containerView.layer.addSublayer(playerLayer)
      
      player.play()
      return containerView
  }

Is there a way to get notified when each card is shown in the screen? A delegate method perhaps.

The reason is, it's a little different than displaying static views or images. Because view/image cards are sort of "preloaded", right? When I add video player cards in the view generator, I have to set it to play player.play() right within the generator. The problem is then all the preloaded videos also get played simultaneously.

If there's a way to get notified when each card is displayed, maybe I could make it play when that happens.

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.