Skip to content

Repository files navigation

Logo

CardStack

An elegant SwiftUI card stack component for creating beautiful, interactive card stack interfaces.

Basic Usage Demo

Features

  • Display content in a visually appealing card stack layout
  • Support for programmatic and gesture-based navigation
  • Multiple interaction modes: no gestures, standard gestures, and enhanced gestures
  • Highly customizable appearance and behavior
  • Support for iOS 16+, macOS 13+, tvOS 16+, and watchOS 9+

Installation

Add this package to your Xcode project using Swift Package Manager:

  1. In Xcode, select "File" → "Add Packages..."
  2. Enter the repository URL: https://github.com/HanlunWang/CardStack
  3. Follow the prompts to add the package to your project

Quick Start

Basic Usage

Basic Usage Demo

import SwiftUI
import CardStack
// Create a card stack with your data
CardStack(items, currentIndex: $currentIndex){ item in
// Your card content here
Text(item.title).frame(width:300, height:400).background(item.color).cornerRadius(10)}

Enable Swipe Gestures

Swipeable DemoEnhanced Swipeable Demo

// Add swipe gesture support with a simple modifier
CardStack(items, currentIndex: $currentIndex){ item in
// Your card content
}.swipeable()
// Or use enhanced animations
CardStack(items, currentIndex: $currentIndex){ item in
// Your card content
}.enhancedSwipeable()

Add Random Card Angles

Random Card Angles Demo

// Add random rotation angles to cards
CardStack(items, currentIndex: $currentIndex){ item in
// Your card content
}.useRandomAngles(maxAngle:5.0)

Configuration Options

The CardStackConfiguration struct provides extensive customization:

PropertyDescriptionDefault
swipeModeGesture mode (.none, .normal, .enhanced).none
cardPaddingHorizontal spacing between cards35.0
scaleFactorPerCardScale reduction for each card0.1
rotationDegreesPerCardRotation angle for each card2.0
swipeThresholdDistance required to trigger a swipe200.0
springStiffnessAnimation spring stiffness300.0
springDampingAnimation spring damping40.0
swingOutMultiplierExaggeration factor for animations15.0
randomAnglesSettings for random card rotationdisabled

Example Configuration

// Create a custom configuration
varconfig=CardStackConfiguration()
config.swipeMode =.enhanced
config.cardPadding =40
config.scaleFactorPerCard =0.15
config.rotationDegreesPerCard =3.0
config.randomAngles =RandomAnglesSettings(enabled:true, maxAngle:3.0)
// Apply the configuration
CardStack(items, currentIndex: $currentIndex, configuration: config){ item in
// Your card content
}

Gesture Modes

CardStack supports three gesture modes:

  1. No Gestures (.none): Disables all swipe gestures, navigation only through programmatic means.
  2. Standard Gestures (.normal): Enables basic swipe gestures with simple animation effects.
  3. Enhanced Gestures (.enhanced): Enables advanced swipe gestures with more dynamic animation effects, including "fling out" effects.

License

This package is provided under the MIT license.

About

An elegant SwiftUI card stack component for creating beautiful, interactive card stack interfaces.

Topics

Resources

Stars

13 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages