SwiftUI - Using drawingGroup() disables TextField

Viewed 825

I am trying to improve the animation performance of my custom modal view.

By using .drawingGroup(), I've managed to do so, but my TextField got disabled. Like so:

enter image description here

And I get the error: 'Unable to render flattened version of PlatformViewRepresentableAdaptor<>'

Is there a way to fix this?

Note: I am using a standard TextField.

Thanks!

1 Answers

The .drawingGroup converts entire view hierarchy into image, so you cannot use TextField (or any other control) after this as active control, because all you see on-screen is only image.

It works as documented:

/// Composites this view's contents into an offscreen image before final
/// display.
///
/// Views backed by native platform views don't render into the image.
/// Instead, they log a warning and display a placeholder image to highlight
/// the error.
///
/// - Parameters:
///   - opaque: A Boolean value that indicates whether the image is opaque.
///     If `true`, the alpha channel of the image must be one.
///   - colorMode: The working color space and storage format of the image.
/// - Returns: A view that composites this view's contents into an offscreen
///   image before display.
public func drawingGroup(opaque: Bool = false, colorMode: ColorRenderingMode = .nonLinear) -> some View

The solution for this is not use .drawingGroup for active controls, but only for UI elements w/o user interaction.

Related