johnpatrickmorgan / FlowStacks

FlowStacks allows you to hoist SwiftUI navigation and presentation state into a Coordinator
MIT License
854 stars 66 forks source link

Cover and sheet not working on iOS 14.2 (Sim) #12

Closed tscdl closed 2 years ago

tscdl commented 2 years ago

Hi, let me first say, I love your approach. ViewModifier stack plus array of routes representing it. That is the best and most solid approach I have seen. Really nice when refactoring code.

Problem found: I cannot get the sheets to work in iOS 14.2. It applies to the fullscreen cover, too – however, not in 100% of cases. Problem applies to my own code, but also when I build your example code. Tested only in 14.2, not 14.x so far.

Regards

johnpatrickmorgan commented 2 years ago

Thanks for raising this issue, I'm glad you like the library. I understand there was a bug in SwiftUI in iOS 14 that is fixed in iOS 14.5 upwards:

Resolved Issues

  • You can now apply multiple sheet(isPresented:onDismiss:content:) and fullScreenCover(item:onDismiss:content:) modifiers in the same view hierarchy. (74246633)

I think it makes sense for this library to work around the issue; I'll have a look. Thanks!

tscdl commented 2 years ago

Thanks for the quick reply!

Interesting. I just downloaded the 14.5 simulator runtime. In fact the problem disappears.

johnpatrickmorgan commented 2 years ago

Unfortunately I hit issues when trying to work around this issue. For example, I tried variations on this theme to avoid chaining cover and sheet on the same view:

.cover(
  isPresented: coverBinding,
  onDismiss: nil,
  content: { next }
)
.background(
  Text("").hidden()
    .sheet(
      isPresented: sheetBinding,
      onDismiss: nil,
      content: { next }
    )
)

That works around the issue on iOS 14.4 and below, but introduces a bug (even on iOS 15), where presenting a screen five layers of presentation deep fails with this error:

Attempt to present <_TtGC7SwiftUI29PresentationHostingControllerVS_7AnyView_: 0x7f9f3ef6c7d0> on <_TtGC7SwiftUI29PresentationHostingControllerVS_7AnyView_: 0x7f9f3f91af40> (from <_TtGC7SwiftUI19UIHostingControllerGVS_15ModifiedContentVVS_22_VariadicView_Children7ElementVS_24NavigationColumnModifier__: 0x7f9f3ef489d0>) which is already presenting <_TtGC7SwiftUI29PresentationHostingControllerVS_7AnyView_: 0x7f9f3ef5a6f0>

Instead, conditionally applying only one of the modifiers (#13) seems to work around the issue without introducing any regressions. Sadly, on iOS 14.4 and below, the Attempt to present error still occurs when the number of presentation layers reaches five, but I think that may be a limitation/bug of SwiftUI.

I'll continue to check the solution works well before merging...

zntfdr commented 2 years ago

Thank you for the investigation @johnpatrickmorgan 🙏🏻

johnpatrickmorgan commented 2 years ago

The workaround #12 is now merged in v0.1.4, so both presentation styles should now work as expected on iOS versions below 14.5. I added availability checks to only employ the workaround when the iOS version was less than iOS 14.5. Thanks for raising this issue @tscdl!

tscdl commented 2 years ago

Thanks for solving it!