-
Notifications
You must be signed in to change notification settings - Fork 45
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
A ToastUI triggering while a SwiftUI Menu is active can sometimes later cause sheets to fail to open. #21
Comments
Can you provide a minimal reproducible example of your bug here? I attach Here's my full example for reference. struct ContentView: View {
@State var selectedText: String = ""
@State var showQRCode: Bool = false
@State var isLocked: Bool = false
var body: some View {
TextField("TextField", text: $selectedText)
Menu {
Button {
UIPasteboard.general.string = selectedText
} label: {
Label("Copy", systemImage: "doc.on.doc")
}
} label: {
Image(systemName: "ellipsis")
.imageScale(.large)
.padding()
}
.onReceive(NotificationCenter.default.publisher(for: UIApplication.willResignActiveNotification)) { _ in
isLocked = true
}
.onReceive(NotificationCenter.default.publisher(for: UIApplication.willEnterForegroundNotification)) { _ in
isLocked = false
}
.toast(isPresented: $isLocked) {
ToastView("Screen is locked")
}
.sheet(isPresented: $showQRCode) {
Text("QR Code")
}
}
} |
Thank you for looking at this. The code: ToastDemoapp.swift:
ContentView.swift: // import SwiftUI struct QRCode: View { struct LockScreen: View { struct ContentView: View {
} struct ContentView_Previews: PreviewProvider { Reproduction procedure:
2021-07-13 01:13:04.253733+0200 ToastDemo[11444:184732] [Presentation] Attempt to present <TtGC7SwiftUI29PresentationHostingControllerVS_7AnyView: 0x7fddfb034aa0> on <TtGC7SwiftUI19UIHostingControllerGVS_15ModifiedContentVS_7AnyViewVS_12RootModifier_: 0x7fddf9607ca0> (from <TtGC7SwiftUI19UIHostingControllerGVS_15ModifiedContentVS_7AnyViewVS_12RootModifier_: 0x7fddf9607ca0>) which is already presenting <_UIContextMenuActionsOnlyViewController: 0x7fddfb021d30>. I can reproduce both on device and in simulator with the above code. |
I'm able to reproduce the error, albeit a little bit difficult as it is a race condition bug. Upon investigation, I also found other bugs related to handling the view presentation, such as the toast might not be shown if the binding changes during the presentation. In your case, it would result in the toast might not be shown even if the application is in the background. Thanks for your report. I will release the fix soon. |
Sounds promising. I also found that dismissing the view on binding changes will fail sometimes. It would be great if you would release the fix? |
Quick update on this, I will release the new version when Xcode 13.0 is released. I want to test it thoroughly to make sure it works properly on the official build. Xcode 13.0 RC is weird as its SDK removes lots of new SwiftUI features that were existed in previous versions. I hope this is just a temporary issue. |
My apologies for delays. I fixed the issue in the latest |
Verified fixed with 3.0.0 |
Pre-requisites:
Expected Behavior
Current Behavior
Possible Solution
A workaround is to use .contextMenu instead of Menu.
Steps to Reproduce
With this activated:
Menu {
Button() {
UIPasteboard.general.string = selectedText
} label: {
Image(systemName: "doc.on.doc")
Text("Copy")
}
}
label:
{
Image(systemName: "ellipsis")
.imageScale(.large)
.padding()
}
And concurrently triggering a Toast:
.toast(isPresented: $isLocked) {
LockScreen()
}
And then later calling sheet(), for instance:
.sheet(isPresented: $showQRCode) {
QRCode(showQRCode: self.$showQRCode)
}
Will generate the following error:
2021-07-09 23:21:11.290959+0200 AppName[10762:4800555] [Presentation] Attempt to present <TtGC7SwiftUI29PresentationHostingControllerVS_7AnyView: 0x113507a20> on <TtGC7SwiftUI19UIHostingControllerGVS_15ModifiedContentVS_7AnyViewVS_12RootModifier_: 0x111d08800> (from <TtGC7SwiftUI19UIHostingControllerVS_14_ViewList_View: 0x111d2ca80>) which is already presenting <_UIContextMenuActionsOnlyViewController: 0x1137095f0>.
Context
I am using Toast to present a LockScreen that triggers when moving an app to the background.
It works great with all other kinds of dialogs, like sheets or contextMenus, but using Menu causes the above issue.
I am using XCode 12.5.1
iOS 14.6,
iPhone 12 Pro Max
The text was updated successfully, but these errors were encountered: