Skip to content

Conversation

iakash-singh
Copy link

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 and others added 2 commits May 14, 2025 01:46
[TextControls] Replace UIGraphicsBeginImageContext with UIGraphicsImageRenderer in MDCTextControlGradientManager
@iakash-singh iakash-singh requested a review from a team as a code owner May 13, 2025 20:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant