Presenting alert immediately after fullscreen cover results in UIKit error #1278
-
DescriptionNot sure if this is a TCA bug, or something on the application side. However, I am still posting it because I couldn’t find any guidance about this case. In a nutshell: when there is a fullscreen cover, and alert shown immediately after dismissing the fullscreen cover, TCA changes the state such that SwiftUI attempts to present the alert before fullscreen cover is fully dismissed. This results in a UIKit error, and the alert not being shown. Checklist
Expected behaviorInstead of alert, I get the following UIKit error in console.
Actual behaviorThe fullscreen cover dismissal and alert showing should be sequenced in the correct fashion and happen one after another without me having to put in delays or otherwise hack the system. Steps to reproduceExample project to reproduce the correct/incorrect behavior:
Video example of desired behavior: Simulator.Screen.Recording.-.iPhone.13.Pro.-.2022-08-19.15.16.19.mp4The Composable Architecture version informationcfcf8b4 (June 20 2022) Destination operating systemiOS 15.5 Xcode version information13.4 (13F17a) Swift Compiler version informationswift-driver version: 1.45.2 Apple Swift version 5.6.1 (swiftlang-5.6.0.323.66 clang-1316.0.20.12)
Target: x86_64-apple-macosx12.0 |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
The issue is, that you need to wait for .photoPickerDismissed action (system notifying that full screen cover was dismissed) before you can show an alert. One option is to add state variable
When receiving .photoProcessorCompleted, assign to that and on . photoPickerDismissed forward it
|
Beta Was this translation helpful? Give feedback.
-
Just to expand on what @jaanussiim said, I think this should be considered a SwiftUI bug and not something the library should be trying to fix. You can reproduce the problem in this very simple vanilla SwiftUI app: struct ContentView: View {
@State var isFullscreenCoverPresented = false
@State var isAlertPresented = false
var body: some View {
Button("Present") {
self.isFullscreenCoverPresented = true
}
.fullScreenCover(isPresented: self.$isFullscreenCoverPresented) {
Button("Close") {
self.isFullscreenCoverPresented = false
self.isAlertPresented = true
}
}
.alert("Hi", isPresented: self.$isAlertPresented) {
Text("Hello")
}
}
} Since this is not an issue with the library I am going to move it to a discussion. |
Beta Was this translation helpful? Give feedback.
The issue is, that you need to wait for .photoPickerDismissed action (system notifying that full screen cover was dismissed) before you can show an alert.
One option is to add state variable
var maybeAlert: AlertState<PhotoPickerAlertAction>?
When receiving .photoProcessorCompleted, assign to that and on . photoPickerDismissed forward it