I've been battling with a bug in my app where after presenting a modal sheet from another one (by changing the state that the .sheet(item:)
binding is connected to) the binding stops receiving .set()
calls which means the backing state never gets reset and the sheets just stop working.
Steps to reproduce:
- You have some .sheet(item😃 call with a binding so some @State (e.g. an enum).
- You set the state to one value to trigger the sheet.
- Something in that sheet (e.g. a button press) changes that state to another value, dismissing the first sheet and presenting the new sheet.
- You dismiss the second sheet.
- Set the state to the first value again - the sheet appears.
- Dismiss the first sheet - this dismissal will not call the binding.set() function leaving the state still on the first value.
- At this point trying to set the state to the first value again will no longer present the sheet because the state is already that value (even though the sheet has been dismissed).
I was able to reproduce this in a brand new SwiftUI project:
https://gist.github.com/lukeredpath/89f6e662265e98912069f51abfdaeb88
The docs suggest that this should work as intended, where a change in the item binding value should trigger a dismissal and new modal sheet - which it does - but once the binding stops receiving .set calls it breaks.