-1

Can anyone explain this strange behavior in SwiftUI?

Dismissing a sheet by dragging it down has some delay until the variable bound to it is set to nil again, but setting the variable directly via button has no delay at all...

Demo

Code to the demo: https://gist.github.com/sanzaru/c16b108c3281859f581e0efd21f6bc47

Sanzaru
  • 79
  • 1
  • 4
  • Does this answer your question https://stackoverflow.com/a/61780031/12299030? – Asperi May 09 '22 at 15:33
  • 3
    What do you find strange from this behavior? When you push the button to dismiss, the variable is directly set to nil and the sheet animates away. When you drag the sheet down, the variable will not be reset until it has been fully closed (since a sheet is meant to behave like a disposable object that can be dragged down and pushed up again until it completely disappeared). The way it behaves in your demo is completely how it should behave. – Björn May 09 '22 at 16:59
  • If you wish to disable the drag option, see here: https://stackoverflow.com/a/67878017/14855422 Or if you wish to add a drag gesture and update the variable to nil immediately as one is starting to drag down, see here: https://www.hackingwithswift.com/quick-start/swiftui/what-is-the-gesturestate-property-wrapper – Björn May 09 '22 at 17:04
  • @Björn I don't agree that this is behavior as it should be. If you don't handle the time the sheet needs to be dismissed and open another one too fast it is dismissed instantly. That's kinda buggy and the click on the button does exactly the same thing without the delay. – Sanzaru May 09 '22 at 22:01
  • @Asperi Not really. As mentioned before, the button does exactly the same and behaves differently. If it's the pure binding they both should behave the same way. – Sanzaru May 09 '22 at 22:03
  • @Sanzaru what behavior do you want to see then? That of the button click or the drag down gesture? It is not common (and actually not preferred by Apple's guidelines) that you close sheets and open up another sheet instantly without any user interaction. It is then better to layer sheets on top of each other instead of closing and opening up sheets after each other. It would be a whole circus of sheets. – Björn May 10 '22 at 14:36
  • @Sanzaru Note by the way that the buggy behavior you are talking about when opening up a sheet while the other is closing, is created since you use one sheet modifier for multiple purposes. Apple guidelines say to use multiple sheet modifiers for each sole View. – Björn May 11 '22 at 09:07

0 Answers0