SlideOverCard icon indicating copy to clipboard operation
SlideOverCard copied to clipboard

SlideOverCards being created indefinitely

Open JGeek00 opened this issue 1 year ago • 6 comments

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

JGeek00 avatar Apr 10 '24 16:04 JGeek00

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!

joogps avatar Apr 10 '24 18:04 joogps

Great! Let me know if you need more details.

JGeek00 avatar Apr 10 '24 23:04 JGeek00

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

cyrilzakka avatar Apr 11 '24 21:04 cyrilzakka

Any news regarding this issue @joogps ?

JGeek00 avatar Apr 25 '24 09:04 JGeek00

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.

msn444 avatar May 31 '24 18:05 msn444

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

cdigiacinto avatar Aug 10 '24 00:08 cdigiacinto