Skip to content

CarouselStack inside List #78

Description

@kkotar

Describe the bug
If CarouselStack is used within a List, and when swiping a card to the right, the card jumps back to the center, but after the animation is complete, the correct card is selected.

To Reproduce
Minimum amount of code to reproduce:

import SwiftUI
import Combine
import ShuffleIt

struct CarouselStackDemoView: View {
    @Environment(\.dismiss) var dismiss
    @State private var sneaker: Sneaker?
    @State private var isShowItems: Bool = false
    let carouselPublisher = PassthroughSubject<CarouselDirection, Never>()
    let timer = Timer.publish(every: 10, tolerance: 0.1, on: .main, in: .default).autoconnect()
    @Environment(\.horizontalSizeClass) var horizontalSizeClass
    let columns: [GridItem] = .init(repeating: GridItem(.flexible(), spacing: 20, alignment: .leading), count: 2)
    let sneakers: [Sneaker] = .sneakers()
    
    var body: some View {
        List {
            CarouselStack(sneakers, initialIndex: 0) { sneaker, translation in
                SneakerCard(sneaker: sneaker, translation: translation)
            }
            .carouselScale(0.7)
            .carouselPadding(horizontalSizeClass == .compact ? 20 : 40)
            .carouselSpacing(horizontalSizeClass == .compact ? 10 : 30)
            .carouselStyle(.finiteScroll)
        }
        .listStyle(.plain)

        .overlay(alignment: .topTrailing) {
            Button(action: {
                dismiss()
            }) {
                Image(systemName: "xmark.circle.fill")
                    .font(.largeTitle)
                    .foregroundStyle(.white)
                    .background {
                        Circle()
                            .foregroundColor(.black.opacity(0.4))
                            .padding(4)
                    }
            }
            .buttonStyle(.plain)
            .padding(.horizontal, 20)
        }
    }
}

Steps to reproduce the behavior:

  1. Go to 'CaraouselStackDemoView' and replace view with code from above.
  2. Swipe card left or right.
  3. See card jumps back after swipe.

Expected behavior
If card is swiped to the right, the next card should be displayed in the centre.

Screenshots
If applicable, add screenshots to help explain your problem.

Device information (please complete the following information):

  • Device: iPhone/Simulator
  • OS: iOS 17.0
  • Xcode version: Xcode 15

Additional context
Add any other context about the problem here.

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions