I would like to find out when the sheet presentation animation concludes in SwiftUI. While in UIKit, this is easily achieved with the present(_:animated:completion:) function. The completion block in the following SwiftUI code seems to trigger only when the sheet is dismissed. Is there a method to determine when the animation for presenting the sheet is completed in SwiftUI?
import SwiftUI
struct SwiftUIView29: View {
@State var show = false
var body: some View {
Button("show") {
withAnimation {
show.toggle()
} completion: {
print("completion!")
}
}
.sheet(isPresented: $show) {
Text("SheetView")
}
}
}
#Preview {
SwiftUIView29()
}
There is an official way, it's:
However, I've tried, and it does not work as expected. The property does not change at all.
I think there is a workaround for this circumstance, you could try this: