Skip to content

feat: support pseudo selectors on SVG elements on Android#9796

Merged
MatiPl01 merged 5 commits into
mainfrom
@matipl01/svg-pseudo-selectors-android
Jul 1, 2026
Merged

feat: support pseudo selectors on SVG elements on Android#9796
MatiPl01 merged 5 commits into
mainfrom
@matipl01/svg-pseudo-selectors-android

Conversation

@MatiPl01

@MatiPl01 MatiPl01 commented Jul 1, 2026

Copy link
Copy Markdown
Member

react-native-svg renders elements as virtual nodes on the SvgView's canvas, so their tags don't resolve to independently touchable Android views. As a result, :active/:hover pseudo selectors on SVG elements worked on iOS and web but not on Android.

This attaches the :active/:active-deepest touch listener to the nearest ReactCompoundView ancestor (the SvgView) and resolves the pressed element via reactTagForTouch, and matches :hover by react tag in the hit-test path. Normal views are unchanged. The web-only labels on the SVG :active examples are dropped, and an overlapping-SVG :hover example is added.

Verified on Android: single and overlapping SVG elements resolve correctly (on overlap the front/top-most element wins); iOS and web already worked.

react-native-svg renders elements as virtual nodes drawn on the SvgView
canvas, so an element's tag does not resolve to an independently touchable
Android view. Attach the :active/:active-deepest touch listener to the
nearest ReactCompoundView ancestor (the SvgView) and resolve the pressed
element per touch via reactTagForTouch; match :hover by react tag in the
hit-test path. Normal views are unchanged.

Drop the web-only labels from the SVG :active examples.
@MatiPl01 MatiPl01 self-assigned this Jul 1, 2026
MatiPl01 added 4 commits July 1, 2026 10:27
Demonstrates that hit-testing resolves the top-most element for stacked
react-native-svg children: hovering the overlap highlights only the front
circle, matching the existing overlapping-views example for plain views.
The window observer and the per-view touch listener both reconciled :hover
on touch-down. For overlapping SVG elements the first reconcile applied the
front element's :hover fill, which invalidates its RNSVG path, so the second
reconcile hit-tested the element behind it and the wrong element won.

Record the downTime of the gesture the window observer reconciled and skip
the per-view reconcile for that same gesture, keeping the per-view path only
as a fallback for windows the observer does not see (e.g. Modals).
@MatiPl01 MatiPl01 requested a review from wisniewskij July 1, 2026 11:55
@MatiPl01 MatiPl01 added this pull request to the merge queue Jul 1, 2026
Merged via the queue into main with commit 143cd82 Jul 1, 2026
13 checks passed
@MatiPl01 MatiPl01 deleted the @matipl01/svg-pseudo-selectors-android branch July 1, 2026 12:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants