swiftui-navigation icon indicating copy to clipboard operation
swiftui-navigation copied to clipboard

Should re-present when `sheet`/`fullScreenCover`/`popover` identity changes

Open stephencelis opened this issue 2 years ago • 5 comments

Our view modifier overloads currently call down to the isPresented: Binding<Bool> versions, which can lead to some unwanted behavior: for example, if a presented sheet changes to another presented sheet, this change occurs without animation (brought up in discussion #73).

We can fix this by calling down to the item: Binding<Item?> APIs instead. This means making sure that the "item" being presented is identifiable, but we can hopefully create a lightweight wrapper type to represent this info. Rather than requiring the value itself to conform to Identifiable, we can identify based off a combination of:

  • The type of value (ObjectIdentifier(Value.self)).
  • The enum case, where applicable (we can use this enumTag helper or something similar.
  • An underlying identifier by casting Value as? any Identifiable.

If anyone wants to take a shot at supporting this, we'd gladly take a PR! Otherwise we'll try to get to it soon.

stephencelis avatar Jan 30 '23 19:01 stephencelis

Is this the cause of a .sheet being (randomly) presented as a .fullScreenCover (or vice versa) when the case of the unwrapping enum changes from one to another?

Zeta611 avatar Feb 26 '23 14:02 Zeta611

@Zeta611 It shouldn't be! That sounds like a gnarly SwiftUI bug, though, if you want to share a repro and file a feedback with Apple.

stephencelis avatar Feb 26 '23 23:02 stephencelis

@stephencelis I think he's referring to this https://stackoverflow.com/q/69101690 which I've stumbled upon whilst using the nav branch in TCA as well, so yeah I'm pretty sure it's a vanilla SwiftUI bug.

davdroman avatar Feb 27 '23 10:02 davdroman

Is there a workaround for this until this work is done?

Muhammed9991 avatar Oct 23 '23 10:10 Muhammed9991

@Muhammed9991 You should always be able to stagger the updates, e.g. nil out the presentation, sleep 0.3 seconds, and then set state to some other value.

stephencelis avatar Oct 23 '23 15:10 stephencelis