material-components-ios icon indicating copy to clipboard operation
material-components-ios copied to clipboard

[TextControls] Replace UIGraphicsBeginImageContext with UIGraphicsImageRenderer in MDCTextControlGradientManager

Open iakash-singh opened this issue 6 months ago • 0 comments

Overview

This PR updates the createImageWithLayer method in MDCTextControlGradientManager.m to use UIGraphicsImageRenderer instead of the deprecated UIGraphicsBeginImageContext API for rendering images from a CALayer. The change modernizes the codebase, improves performance, and aligns with Apple's recommended practices for iOS image rendering.

Changes

  • Replaced UIGraphicsBeginImageContext and related functions with UIGraphicsImageRenderer in MDCTextControlGradientManager.m (method: createImageWithLayer).
  • Ensured compatibility with existing functionality by maintaining the same input (CALayer) and output (UIImage).
  • No changes to public APIs or TextControls component behavior.

Why

  • UIGraphicsBeginImageContext is deprecated in iOS 17+ and generates warnings in modern Xcode versions.
  • UIGraphicsImageRenderer is the recommended API, offering better performance and support for modern iOS features (e.g., wide color, trait collections).

Testing

  • Manual Testing: Verified the updated method in the Catalog example app (Material Catalog). Confirmed that gradient images rendered for TextControls components are identical to the previous implementation.
  • Unit Tests: No existing unit tests were found for createImageWithLayer in MDCTextControlGradientManager. Manual testing was sufficient to validate the change.
  • Snapshot Tests: Confirmed that snapshot tests for TextControls components pass, ensuring no visual regressions.

Issues

  • No related GitHub issues identified.

iakash-singh avatar May 13 '25 20:05 iakash-singh