Skip to content

fix(touchable-ripple): paint the web hover on top of the style background - #5242

Open
jacekAtCK wants to merge 4 commits into
callstack:mainfrom
jacekAtCK:fix/ripple-hover-over-background
Open

jacekAtCK wants to merge 4 commits into
callstack:mainfrom
jacekAtCK:fix/ripple-hover-over-background

Conversation

@jacekAtCK

@jacekAtCK jacekAtCK commented Nov 19, 2026 •

Copy link
Copy Markdown
Collaborator

Motivation

This is a followup to: #5224 (comment)

On web, TouchableRipple paints hover as its own backgroundColor, and a backgroundColor in style ovverides it. So a selected Drawer.Item or a selected List.Item from #5224, shows no hover effect.

Hover is now a linear-gradient background image after style. It paints on top of the background color and keeps the border radius. Hover no longer fades in as it cannot animate background image.

Related issue

Follow-up to #5224 (comment)

Screenshots / Videos

hover-after-drawer hover-before-drawer

Test plan

In the web example:

  1. Hover a selected Drawer.Item. The hover layer shows on top of the selected color, with rounded corners.
  2. Hover an unselected row and a Button. They look as before.

@github-actions

github-actions Bot commented Nov 19, 2026 •

Copy link
Copy Markdown

Found potential problems with the pull request:

  • The description is too long. Please keep it under 1000 characters.

@jacekAtCK

Copy link
Copy Markdown
Collaborator Author

/review

@apex-sentinel-staging

This comment has been minimized.

@apex-sentinel-staging apex-sentinel-staging Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apex Sentinel: 3 new findings on 58d3075. The verdict and the full list are in the summary comment.

Comment thread src/components/TouchableRipple/utils.ts Resolved
@jacekAtCK

Copy link
Copy Markdown
Collaborator Author

/review

@apex-sentinel-staging

This comment has been minimized.

@apex-sentinel-staging apex-sentinel-staging Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apex Sentinel: 3 new findings and 1 moved to a new line on 25e3177. The verdict and the full list are in the summary comment.

Comment thread src/components/TouchableRipple/utils.ts Resolved
@jacekAtCK

Copy link
Copy Markdown
Collaborator Author

/review

@apex-sentinel-staging

This comment has been minimized.

@apex-sentinel-staging apex-sentinel-staging Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apex Sentinel: 1 finding moved to a new line on 69a6fe0. The verdict and the full list are in the summary comment.

@apex-sentinel-staging

apex-sentinel-staging Bot commented Nov 19, 2026 •

Copy link
Copy Markdown

Apex Sentinel · ✅ Approve · review of 69a6fe0

Re-run on the same commit.

1 finding(s): 1 nit.

🔵 Nit (1)
Where Finding
src/components/TouchableRipple/utils.ts:79 Hover layer replaces a backgroundImage the consumer set through style
Not in the reviewers' prompt (1 file)
  • src/components/__tests__/__snapshots__/TouchableRippleWeb.test.tsx.snap: generated or a lockfile, so its lines were left out

1 finding below minor hidden (user_settings.min_severity).

Reviewed with this repository's own Sentinel configuration (c8c3a3945ccb).

💬 Talking to Sentinel

In a finding's thread, reply with:

Command What it does
@apex-sentinel-staging note <context> Adds context; Sentinel re-checks the cited code
@apex-sentinel-staging pivot <why> Says the finding is wrong; Sentinel re-checks the cited code
@apex-sentinel-staging like Marks the finding as useful
@apex-sentinel-staging dislike <why> Marks it as not useful, so it is not raised again

On this conversation, comment @apex-sentinel-staging review to run a full review once again.

@apex-sentinel-staging apex-sentinel-staging Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apex Sentinel: 1 finding moved to a new line on 69a6fe0. The verdict and the full list are in the summary comment.

Comment on lines +79 to +82
export const getHoverStyle = (hoverColor: ColorValue): ViewStyle | undefined =>
typeof hoverColor === 'string'
? { backgroundImage: `linear-gradient(${hoverColor}, ${hoverColor})` }
: undefined;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Minor · Hover layer replaces a backgroundImage the consumer set through style

A consumer that sets backgroundImage in style (gradient, texture) loses it for the whole hover: getHoverStyle spreads a backgroundImage after style, so react-native-web's flattened style takes the hover gradient. The previous hover used backgroundColor, which left a consumer backgroundImage untouched; on web there is now no way to keep both.

Suggested change

Note the hover layer in the TouchableRipple section of docs/6.x/docs/guides/migration.md: while hovered it occupies backgroundImage, so a gradient or image set on the touchable through style is hidden for the duration of the hover.

Details

persona: senior-developer, javascript, react-native-paper

Useful? Reply @apex-sentinel-staging like, or @apex-sentinel-staging dislike <why> if it is not.

Reply @apex-sentinel-staging note ... to add context, or @apex-sentinel-staging pivot ... if it is wrong — I will re-check the cited code.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@apex-sentinel-staging note Known tradeoff, it's documented on getHoverStyle. Composing needs the resolved backgroundImage from style, and this repo bans StyleSheet.flatten in src because animated styles can't be flattened. backgroundImage on a touchable is rare, so I kept the replace. Lemme know what you think

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated suggestion

Your reasoning checks out: eslint.config.mjs does error on StyleSheet.flatten, so composing the consumer's gradient from inside getHoverStyle isn't available, and the docblock on getHoverStyle now spells the replace out for maintainers. My ask was never to change the replace, though — it was the migration note: the docblock is a source comment, so a web user with a gradient set through style only finds out by bisecting, and the TouchableRipple section of migration.md currently mentions the borderless, hitSlop and focusRing changes but not this one. Downgrading to a nit for that one documentation line; the behavior itself I'd merge as is.

🔵 Nit · Note in migration.md that the web hover layer replaces a backgroundImage set through style

On web, a touchable whose style sets backgroundImage (a gradient or texture) loses that background for the whole hover, because TouchableRipple.tsx appends getHoverStyle(hoverColor) after style and react-native-web's flattened style takes the hover gradient. The replace is a deliberate tradeoff and is documented in the getHoverStyle docblock, which is fine; what a consumer will not see is that source comment. The TouchableRipple section of docs/6.x/docs/guides/migration.md covers borderless, hitSlop and focusRing but not this, so it is worth one sentence saying the hover layer occupies backgroundImage while hovered.

Suggested change

Add a sentence to the ### TouchableRipple section of docs/6.x/docs/guides/migration.md: on web the hover layer is a CSS background image, so while the touchable is hovered it replaces a backgroundImage (gradient or image) set on it through style; a backgroundColor set that way is unaffected, since the hover layer paints on top of it. No change to getHoverStyle or to the style ordering in TouchableRipple.tsx — the repo bans StyleSheet.flatten in src, so composing the two gradients from inside the helper isn't an option.

Useful? Reply @apex-sentinel-staging like, or @apex-sentinel-staging dislike <why> if it is not.

@jacekAtCK jacekAtCK self-assigned this Nov 19, 2026

This branch has not been deployed

No deployments
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.

1 participant