Skip to content

Change linear gradient implementation to CAGradientLayer for iOS new arch#3

Merged
SzymczakJ merged 5 commits into
v3.0.0-alpha.1-discord-1from
szymczak/apply-patch-v3.0.0-alpha.1
Apr 22, 2026
Merged

Change linear gradient implementation to CAGradientLayer for iOS new arch#3
SzymczakJ merged 5 commits into
v3.0.0-alpha.1-discord-1from
szymczak/apply-patch-v3.0.0-alpha.1

Conversation

@SzymczakJ
Copy link
Copy Markdown

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.

@SzymczakJ SzymczakJ merged commit 5c928bf into v3.0.0-alpha.1-discord-1 Apr 22, 2026
5 of 8 checks passed
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