material-components-ios
material-components-ios copied to clipboard
[TextControls] Replace UIGraphicsBeginImageContext with UIGraphicsImageRenderer in MDCTextControlGradientManager
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
UIGraphicsBeginImageContextand related functions withUIGraphicsImageRendererinMDCTextControlGradientManager.m(method:createImageWithLayer). - Ensured compatibility with existing functionality by maintaining the same input (
CALayer) and output (UIImage). - No changes to public APIs or
TextControlscomponent behavior.
Why
UIGraphicsBeginImageContextis deprecated in iOS 17+ and generates warnings in modern Xcode versions.UIGraphicsImageRendereris 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
Catalogexample app (Material Catalog). Confirmed that gradient images rendered forTextControlscomponents are identical to the previous implementation. - Unit Tests: No existing unit tests were found for
createImageWithLayerinMDCTextControlGradientManager. Manual testing was sufficient to validate the change. - Snapshot Tests: Confirmed that snapshot tests for
TextControlscomponents pass, ensuring no visual regressions.
Issues
- No related GitHub issues identified.