Change linear gradient implementation to CAGradientLayer for iOS new arch#3
Merged
SzymczakJ merged 5 commits intoApr 22, 2026
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Migrated react-native-linear-gradient's iOS implementation from CPU-rasterized UIGraphicsImageRenderer (which drew a CGImage bitmap and set it as layer.contents) to GPU-composited CAGradientLayer.
Benefits
No main-thread rasterization. Old path stalled the main thread on every draw; new path is composited by the render server, which is much faster(40 ms of CPU cost to almost 0 ms) .
Cheap resizes / reflows. Bounds changes (rotation, keyboard, bottom sheet expand, Reanimated layouts) are a single property assignment — no bitmap re-allocation.
No re-raster on prop tweaks. Color or stop changes are metadata updates, not full redraws.
No peak-memory spikes during redraw. Transient CPU bitmap allocations are gone; less allocator churn and heap fragmentation.
Notes on memory
Old implementation had to allocate a lot of memory for CG raster data, now when CAGradientLayer handles everything on GPU that cost is gone(now it just needs small data structures for GPU communication). This gives us ~4MiB memory save on each screen sized gradient.