joogps / SlideOverCard

A SwiftUI card view, made great for setup interactions.
MIT License
1.07k stars 43 forks source link

SlideOverCards being created indefinitely #29

Open JGeek00 opened 5 months ago

JGeek00 commented 5 months ago

Hi. I want to add this card to my application. I'm doing it like I do with a normal .sheet, but I don't know why it is creating cards like on an infinite loop.

Main view code:

    @StateObject private var captureViewModel = CaptureViewModel()

    var body: some View {
        let filteredList = accounts.filter() {
            if codesViewModel.searchText == "" {
                return true
            }
            guard let item = $0.name else { return false }
            return item.lowercased().contains(codesViewModel.searchText.lowercased())
        }
        NavigationView {
            Group {
               ...
            }
            .toolbar(content: {
                ToolbarItem(placement: .topBarTrailing) {
                    HStack {
                        Menu {
                            if (!ProcessInfo.processInfo.isMacCatalystApp) {
                                Button {
                                    captureViewModel.sheetOpen.toggle()  // Opens the slide over card (previously it was a sheet)
                                } label: {
                                    Label("Capture QR code", systemImage: "qrcode.viewfinder")
                                }
                            }
                            ...
                        } label: {
                            Image(systemName: "plus")
                        }
                    }
                }
            })
            .slideOverCard(isPresented: $captureViewModel.sheetOpen) {
                CaptureView(captureViewModel: captureViewModel)
            }
            .sheet(isPresented: $newAccountFormViewModel.sheetOpen, content: {
                NewAccountFormViewIos(newAccountFormViewModel: newAccountFormViewModel)
            })
            .preferredColorScheme(appConfig.theme)
        }
        .navigationViewStyle(StackNavigationViewStyle())
    }

The slide over view:

var body: some View {
        Group {
            ...
        }
        .frame(height: 300)
        .onAppear(perform: {
            ...
        })
    }

Simulator Screenshot - iPhone 15 Pro Max - 2024-04-10 at 18 40 31

joogps commented 5 months ago

Hi @JGeek00! Thank you so much for pointing this out to me. I ran across this issue a few times but I thought I had handled all of the edge cases to fix it. I'll take a look later today!

JGeek00 commented 5 months ago

Great! Let me know if you need more details.

cyrilzakka commented 5 months ago

Having the same issue! Also having a conditional view or animating the opacity of the view causes the new view to disappear and a new sheet to appear ex:

if isConnecting {
    ProgressView()
}

or

 .opacity(isPresented ? 1:0)

summons a new view or draws unlimited new cards

JGeek00 commented 4 months ago

Any news regarding this issue @joogps ?

msn444 commented 3 months ago

I'm seeing this too after upgrading to 3.0.1 from 2.1.0. I have a view that has isPresented fixed at true, so that the SlideOverCard is fixed in place. Any time I do a drag-from-bottom gesture as if switching apps, even if momentary, a new SlideOverCard with the same content slides up over the existing card. This will occur indefinitely. This doesn't happen in 2.1.0. Great work otherwise.

cdigiacinto commented 1 month ago

I'm also having the same problem any news @joogps?