Skip to content

Add declarative gradient stops and safe resource composition - #40

Draft
jonobr1 wants to merge 1 commit into
mainfrom
fix/declarative-gradients
Draft

jonobr1 wants to merge 1 commit into
mainfrom
fix/declarative-gradients

Conversation

@jonobr1

@jonobr1 jonobr1 commented Oct 22, 2026

Copy link
Copy Markdown
Owner

The documented gradient example currently passes unsupported plain stop objects and uses an invalid callback-ref pattern. This adds declarative stop composition and a direct resource-binding API for both gradient components.

<LinearGradient x1={-100} x2={100} units="userSpaceOnUse">
  {gradient => <>
    <Stop offset={0} color="red" />
    <Stop offset={1} color="blue" />
    <Rectangle width={200} height={200} fill={gradient} />
  </>}
</LinearGradient>
  • Export typed Stop/StopProps/RefStop; support prop updates/resets, keyed reorder, insertion/removal, fragments, and locally updated memoized children.
  • Preserve refs and borrowed Two.Stop[] arrays. Array stops precede JSX stops when combined. Shape children retain the surrounding scene parent.
  • Keep a retired gradient alive while mounted React shapes still use it as fill/stroke. Defer final cleanup through Strict Mode replay, remove SVG definitions, clear renderer effects, and detach stop listeners without globally unbinding borrowed stops. Imperative consumers outside React manage their own resources, as documented.
  • Invalidate Two.js's cached SVG children for equal-length stop reorder/replacement; otherwise the SVG DOM retains stale order.
  • Replace the README example and update the property matrix.

Validation:

  • 262 tests passed across 22 files, including 13 new gradient regressions.
  • npm run lint, npx tsc -b, npm run build:lib, and npm run build:docs passed. Docs retain the existing large-chunk advisory.
  • Executed tests/browser/gradients.html in the in-app browser: linear/radial gradients passed on real SVG, Canvas, and WebGL, checking rendered colors (pixel samples for raster renderers), keyed updates, and cleanup.
  • React best-practices review completed; Jev assisted with bounded requirement-coverage review.

Fixes #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.

[Parity] Add declarative gradient stops and resource composition

1 participant