AndreaMiotto / PartialSheet

A SwiftUI Partial Sheet fully customizable with dynamic height
https://github.com/AndreaMiotto/PartialSheet/wiki
MIT License
1.72k stars 192 forks source link

Multiple quick clicks, empty sheet #139

Closed fatcarter closed 2 years ago

fatcarter commented 2 years ago

When the button is in the same position as the cover, an empty sheet may appear if you click it a few times quickly

Like the picture below: image

How to fix it?

fatcarter commented 2 years ago

9F309718-9219-4864-A346-7B31F1955568

eenlars commented 2 years ago

Same issue here. Still can't see a way to fix it. I think it tries to create a new partialsheet, with empty contents. The lifecycle of isPresented might be the problem.

PocketDaniel commented 2 years ago

Had similar issue when I was closing partial sheet right before opening a new one, which resulted in an empty view due to isPresented -> didSet implementation, as it is clearing content to AnyView(EmptyView()) after 0.35 seconds (I believe) delay (for details please refer to PartialSheetManager lines 27-36)

So, you might be calling isPresented = false while quick tapping as you either tap outside the sheet or your taps are recognised as "dismiss gesture".

AndreaMiotto commented 2 years ago

Check it out version 3. And the PSButton. Rage tap can be avoided putting a delay on your button.

baraql commented 2 years ago

For people experiencing this issue and who want to use version 1 which is compatible with previous iOS versions:

I'm pretty sure this can be solved by simply checking if the sheet is still not presented. Here's my fix (lines 27-39 of PartialSheetManager.swift):

@Published var isPresented: Bool = false
    {
        didSet {
            if !isPresented {
                DispatchQueue.main.asyncAfter(deadline: .now() + 0.35) { [weak self] in
                    if !(self?.isPresented ?? true) {
                        self?.content = AnyView(EmptyView())
                        self?.onDismiss = nil
                    }
                }
            }
        }
    }