Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
tscdl opened this issue Jan 18, 2022 · 6 comments
Closed

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

tscdl opened this issue Jan 18, 2022 · 6 comments

Comments

@tscdl
Copy link

tscdl commented Jan 18, 2022

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
Copy link
Owner

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
Copy link
Author

tscdl commented Jan 18, 2022

Thanks for the quick reply!

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

@johnpatrickmorgan
Copy link
Owner

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
Copy link
Contributor

zntfdr commented Jan 27, 2022

Thank you for the investigation @johnpatrickmorgan 🙏🏻

@johnpatrickmorgan
Copy link
Owner

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
Copy link
Author

tscdl commented Feb 11, 2022

Thanks for solving it!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants