In SwiftUI, how do you perform a code before the interface rotation animation starts?

I need to execute a code before the device's interface starts rotating but I can't seem to find any viable solution.

I came across UIDevice.orientationDidChangeNotification but couldn't find anything like that to be notified that an orientation change will start.

I tried creating an UIViewControllerRepresentable with a custom UIViewController that overrides func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator), but that function doesn't get invoked at all (I didn't forget to propagate it using super).

Any idea?

May be you could try to send a notification as described here. I did not test.

https://stackoverflow.com/questions/69918095/detect-ios-device-orientation-change-without-rotating-view

@Claude31 Unfortunately I need my code to be performed before the orientation animation happens, not when it already completed.

In SwiftUI, how do you perform a code before the interface rotation animation starts?
 
 
Q