Skip to content

Latest commit

 

History

History

FB11356997

Severe regression with animating UIHostingController using UIKit animation techniques

  • Area: SwiftUI Framework
  • Type: Incorrect/Unexpected Behavior

When wrapping a SwiftUI view into a UIHostingController, embedding it into a UIKit context, and animating the wrapping UIView using UIKit animation techniques (e.g. UIViewPropertyAnimation), the hosted SwiftUI view is not animated correctly. This behavior seems to be a regression in the current betas of iOS 16 (observed with β6 and β7) as it works perfectly fine with iOS 15.6.

The faulty behavior is demonstrated in the attached sample project. It uses the UIKit app lifecycle and contains a single UIViewController. The view controller embeds a container view which in turn embeds the view of a UIHostingController. The container view uses the old-fashioned frame layout, and the hosting controller’s view is embedded using Auto Layout. We applied coloring to help visualize the issue. The background of the hosting controller’s view is set to gray, and the SwiftUI view is colored red.

When applying a spring animation to the height of the container view via UIViewPropertyAnimator, the expected outcome is that the red rectangle (SwiftUI view) bounces, and the gray background (UIHostingController’s view) is not visible at all. This is exactly what happens on iOS 15.6, as shown in the attached video.

However, on iOS 16 β7, the height of the red rectangle (SwiftUI view) jumps immediately to the final value, and the gray background (UIHostingController’s view) performs the animation in the background. This is shown in the second video. Also, see the results side-by-side in the third video.

iOS 15.6 iOS 16 β7 Comparison
iOS.15.6.iPhone.13.mini.mp4
iOS.16.7.iPhone.8.mp4
Showcase.iOS.15.vs.16.mov

For such a simple example, there are workarounds we could employ. For instance, we could move the whole animation into the SwiftUI context. However, there are spots in UIKit where this isn’t viable, like using the UIHostingController with the UISheetPresentationController.

We believe this is a severe regression that should be addressed before releasing the current iteration of SwiftUI as part of iOS 16.