A Jetpack Compose library for customizable draggable card stacks with smooth animations.
- 🎯 Smooth spring-based animations
- 🔄 Vertical and horizontal swiping
- 📱 Responsive design
- 🎨 Customizable card alignment & spacing
- 💫 Dynamic elevation & scale animations
- âš¡ Velocity-based swipe detection
- 🔄 Automatic card reordering
dependencies {
implementation("io.github.teddko:cardstack:1.0.1")
}
@Composable
fun CardStackDemo() {
val items = remember { listOf("Card 1", "Card 2", "Card 3") }
DraggableCardStack(
initialItems = items,
height = 200.dp,
cardSpacingRatio = 0.1f,
cardAlignment = CardAlignment.BOTTOM,
dragAlignment = DragAlignment.HORIZONTAL
) { item ->
Card(
modifier = Modifier
.fillMaxSize()
.padding(16.dp)
) {
Text(
text = item,
modifier = Modifier.padding(16.dp)
)
}
}
}
data class CardItem(
val title: String,
val description: String,
val imageUrl: String
)
@Composable
fun AdvancedCardStack() {
val items = remember {
listOf(
CardItem("Title 1", "Description 1", "url1"),
CardItem("Title 2", "Description 2", "url2"),
CardItem("Title 3", "Description 3", "url3")
)
}
DraggableCardStack(
initialItems = items,
height = 200.dp,
cardSpacingRatio = 0.1f,
cardAlignment = CardAlignment.BOTTOM,
dragAlignment = DragAlignment.HORIZONTAL
) { item ->
Card(modifier = Modifier.fillMaxSize()) {
Row(
modifier = Modifier
.fillMaxSize()
.padding(16.dp),
horizontalArrangement = Arrangement.spacedBy(16.dp),
verticalAlignment = Alignment.CenterVertically
) {
AsyncImage(
modifier = Modifier
.size(100.dp)
.clip(CircleShape),
model = item.imageUrl,
contentDescription = item.description,
contentScale = ContentScale.Crop,
)
Column(verticalArrangement = Arrangement.spacedBy(8.dp)) {
Text(text = item.title)
Text(text = item.description)
}
}
}
}
}
CardAlignment.BOTTOM // Bottom center
CardAlignment.BOTTOM_START // Bottom left
CardAlignment.BOTTOM_END // Bottom right
CardAlignment.TOP // Top center
CardAlignment.TOP_START // Top left
CardAlignment.TOP_END // Top right
CardAlignment.START // Center left
CardAlignment.END // Center right
DragAlignment.VERTICAL // Vertical only
DragAlignment.HORIZONTAL // Horizontal only
DragAlignment.NONE // All directions