All Projects → dadalar → Swiftui Cardstackview

dadalar / Swiftui Cardstackview

Licence: mit
A easy-to-use SwiftUI view for Tinder like cards on iOS, macOS & watchOS.

Programming Languages

swift
15916 projects

Projects that are alternatives of or similar to Swiftui Cardstackview

Bluecap
iOS Bluetooth LE framework
Stars: ✭ 669 (+555.88%)
Mutual labels:  swift-framework
Javascriptcoredemo
A Demo of JavaScriptCore in Swift
Stars: ✭ 44 (-56.86%)
Mutual labels:  swift-framework
Emojica
A Swift framework for using custom emoji in strings.
Stars: ✭ 93 (-8.82%)
Mutual labels:  swift-framework
Parade
Parallax Scroll-Jacking Effects Engine for iOS / tvOS
Stars: ✭ 754 (+639.22%)
Mutual labels:  swift-framework
Viewcomposer
Compose views using enums swiftly: `let label: UILabel = [.text("Hello"), .textColor(.red)]`
Stars: ✭ 27 (-73.53%)
Mutual labels:  swift-framework
Keyboardhidemanager
Codeless manager to hide keyboard by tapping on views for iOS written in Swift
Stars: ✭ 57 (-44.12%)
Mutual labels:  swift-framework
Badgehub
A way to quickly add a notification badge icon to any view. Make any view of a full-fledged animated notification center.
Stars: ✭ 592 (+480.39%)
Mutual labels:  swift-framework
Webmidikit
Simplest MIDI Swift library
Stars: ✭ 100 (-1.96%)
Mutual labels:  swift-framework
Swiftlyext
SwiftlyExt is a collection of useful extensions for Swift 3 standard classes and types 🚀
Stars: ✭ 31 (-69.61%)
Mutual labels:  swift-framework
Literoute
LiteRoute is easy transition for your app. Written on Swift 4
Stars: ✭ 90 (-11.76%)
Mutual labels:  swift-framework
Cheatyxml
CheatyXML is a Swift framework designed to manage XML easily
Stars: ✭ 23 (-77.45%)
Mutual labels:  swift-framework
Nantes
Swift TTTAttributedLabel replacement
Stars: ✭ 852 (+735.29%)
Mutual labels:  swift-framework
Loadingshimmer
An easy way to add a shimmering effect to any view with just one line of code. It is useful as an unobtrusive loading indicator.
Stars: ✭ 1,180 (+1056.86%)
Mutual labels:  swift-framework
Koyomi
Simple customizable calendar component in Swift 📆
Stars: ✭ 716 (+601.96%)
Mutual labels:  swift-framework
Defaultskit
Simple, Strongly Typed UserDefaults for iOS, macOS and tvOS
Stars: ✭ 1,343 (+1216.67%)
Mutual labels:  swift-framework
Postal
A Swift framework for working with emails
Stars: ✭ 602 (+490.2%)
Mutual labels:  swift-framework
Framelayoutkit
FrameLayoutKit is a super fast and easy to use autolayout kit
Stars: ✭ 53 (-48.04%)
Mutual labels:  swift-framework
Swift
🥇Swift基础知识大全,🚀Swift学习从简单到复杂,不断地完善与更新, 欢迎Star❤️,欢迎Fork, iOS开发者交流:①群:446310206 ②群:426087546
Stars: ✭ 1,377 (+1250%)
Mutual labels:  swift-framework
Flexlayout
FlexLayout adds a nice Swift interface to the highly optimized facebook/yoga flexbox implementation. Concise, intuitive & chainable syntax.
Stars: ✭ 1,342 (+1215.69%)
Mutual labels:  swift-framework
Markdowngenerator
Swift library to programmatically generate Markdown output and files
Stars: ✭ 76 (-25.49%)
Mutual labels:  swift-framework

🃏 CardStack

Swift Version License Platform

A easy-to-use SwiftUI view for Tinder like cards on iOS, macOS & watchOS.

Alt text

Installation

Xcode 11 & Swift Package Manager

Use the package repository URL in Xcode or SPM package.swift file: https://github.com/dadalar/SwiftUI-CardStackView.git

CocoaPods

CardStack is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod "SwiftUICardStack"

Usage

The usage of this component is similar to SwiftUI's List. A basic implementation would be like this:

@State var cards: [Card] // This is the data to be shown in CardStack

CardStack(
  direction: LeftRight.direction, // See below for directions
  data: cards,
  onSwipe: { card, direction in // Closure to be called when a card is swiped.
    print("Swiped \(card) to \(direction)")
  },
  content: { card, direction, isOnTop in // View builder function
    CardView(card)
  }
)

Direction

CardStack needs to know which directions are available and how a swipe angle can be transformed into that direction. This is a conscious decision to make the component easily extendable while keeping type safety. The argument that needs to be passed to CardStack Initializer is a simple (Double) -> Direction? function. The Double input here is the angle in degrees where 0 points to up and 180 points to down. Direction is a generic type, that means users of this library can use their own types. Return nil from this function to indicate that that angle is not a valid direction (users won't be able to swipe to that direction).

There are the following predefined directions (LeftRight, FourDirections, EightDirections) and each of them define a direction(double:) function which can used in the CardStack Initializer. You can check the example project for a custom direction implementation.

Configuration

CardStack can be configured with SwiftUI's standard environment values. It can be directly set on the CardStack or an encapsulating view of it.

CardStack(
  // Initialize
)
.environment(\.cardStackConfiguration, CardStackConfiguration(
  maxVisibleCards: 3,
  swipeThreshold: 0.1,
  cardOffset: 40,
  cardScale: 0.2,
  animation: .linear
))

Use case: Appending items

It's really easy to load new data and append to the stack. Just make sure the data property is marked as @State and then you can append to the array. Please check the example project for a real case scenario.

struct AddingCards: View {
  @State var data: [Person] // Some initial data

  var body: some View {
    CardStack(
      direction: LeftRight.direction,
      data: data,
      onSwipe: { _, _ in },
      content: { person, _, _ in
        CardView(person: person)
      }
    )
    .navigationBarItems(trailing:
      Button(action: {
        self.data.append(contentsOf: [ /* some new data */ ])
      }) {
        Text("Append")
      }
    )
  }
}

Use case: Reload items

Since the component keeps an internal index of the current card, changing the order of the data or appending/removing items before the current item will break the component. If you want to replace the whole data, you need to force SwiftUI to reconstruct the component by changing the id of the component. Please check the example project for a real case scenario.

struct ReloadCards: View {
  @State var reloadToken = UUID()
  @State var data: [Person] = Person.mock.shuffled()

  var body: some View {
    CardStack(
      direction: LeftRight.direction,
      data: data,
      onSwipe: { _, _ in },
      content: { person, _, _ in
        CardView(person: person)
      }
    )
    .id(reloadToken)
    .navigationBarItems(trailing:
      Button(action: {
        self.reloadToken = UUID()
        self.data = Person.mock.shuffled()
      }) {
        Text("Reload")
      }
    )
  }
}

Author

Deniz Adalar, [email protected]

License

CardStack is available under the MIT license. See the LICENSE file for more info.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].