AndreaMiotto / PartialSheet

A SwiftUI Partial Sheet fully customizable with dynamic height

Home Page:https://github.com/AndreaMiotto/PartialSheet/wiki

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Multiple quick clicks, empty sheet

fatcarter opened this issue · comments

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?

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.

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".

commented

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

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
                    }
                }
            }
        }
    }