Skip to content

feat(touchable-ripple)!: state-layer opacity via ripple alpha (#4972) - #5177

Merged
Doberjohn merged 7 commits into
callstack:mainfrom
Priyanshu0007:feat/remove-state-layer-pressed
Dec 6, 2026
Merged

Doberjohn merged 7 commits into
callstack:mainfrom
Priyanshu0007:feat/remove-state-layer-pressed

Conversation

@Priyanshu0007

@Priyanshu0007 Priyanshu0007 commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

Motivation

Closes #4972. Removes theme.colors.stateLayerPressed for 6.0. TouchableRipple now applies the MD3 pressed opacity (0.10) itself: as android_ripple.alpha on RN 0.86+ (baked into the color on 0.85 and older), on the iOS highlight, and in the color on web, where the hover is 0.08. Ripple colors should be opaque. Button, IconButton, FAB and FAB.Menu pass their content color.

Visible change: the FAB and the FAB.Menu trigger (and its close button while open) draw their state layer in their content color, per MD3, instead of onSurface.

Thanks to adrcotfas for the first draft in #4997.

Test Evidence

Android iOS Web
android_ripple.mp4
ios_ripple.mp4
web_ripple.mp4

@Doberjohn

Copy link
Copy Markdown
Collaborator

We'd like this PR to carry the stateLayerPressed removal for 6.0, in place of #4997. A few things before the review:

  • It conflicts with main, so CI hasn't run yet. Could you rebase it?
  • The description is over the 1000 characters the PR checks ask for. A shorter one, with a short video or screenshots of the pressed state on Android, iOS and web, would help.
  • Please credit adrcotfas, whose feat(touchable-ripple): MD3 state-layer opacity via android_ripple alpha #4997 did the same in an earlier draft; a line in the description is enough.
  • On Android the 0.10 alpha is now added to any ripple color a component passes. Button in feat(button)!: modernize Button to MD3 Expressive #5097 still bakes the pressed alpha into the color it passes to TouchableRipple, so once both are in, Button's ripple would end up near 1%. Whichever of the two lands second should have Button pass its opaque label color. Could you note that in the description?

@Priyanshu0007

Copy link
Copy Markdown
Contributor Author

Hi @Doberjohn, i have made changes requested by you.

@alpharius-ck

Copy link
Copy Markdown
Collaborator

@Priyanshu0007 hey! could you please resolve merge conflicts and verify that your solution is still working?

@alpharius-ck

Copy link
Copy Markdown
Collaborator

/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: 9 new findings on 502cb52. The verdict and the full list are in the summary comment.

Comment thread src/components/FAB/Menu.tsx Resolved
Comment thread src/components/TouchableRipple/types.ts Resolved
Comment thread src/components/TouchableRipple/utils.ts Resolved
@Priyanshu0007
Priyanshu0007 force-pushed the feat/remove-state-layer-pressed branch from 502cb52 to 8c1aed5 Compare December 4, 2026 10:44
@alpharius-ck

Copy link
Copy Markdown
Collaborator

/review

@apex-sentinel-staging

Copy link
Copy Markdown

Apex Sentinel · ✅ Approve · review of 8c1aed5

Since the review of 502cb52: 1 new · 0 still open · 9 no longer raised

1 finding(s): 1 minor.

🟡 Minor (1)

Where Finding
src/components/TouchableRipple/utils.ts:130 🆕 Ripple fallback hand-copies the onSurface-to-palette mapping instead of deriving it
Not in the reviewers' scope (2 files)
  • src/components/__tests__/__snapshots__/ListSection.test.tsx.snap: generated or a lockfile, so its lines were left out
  • src/components/__tests__/__snapshots__/TouchableRipple.test.tsx.snap: generated or a lockfile, so its lines were left out

2 findings below minor hidden (user_settings.min_severity).

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

💬 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 new finding on 8c1aed5. The verdict and the full list are in the summary comment.

Comment thread src/components/TouchableRipple/utils.ts Resolved
@alpharius-ck

Copy link
Copy Markdown
Collaborator

Review and manual testing of feat/remove-state-layer-pressed

Thanks for the update. I reviewed the code and tested it by hand on web, iOS and Android. Overall the approach works: the ripple color is now opaque, and the 0.1 pressed opacity is applied where the ripple is drawn. Lint, typecheck and all 1811 tests pass on the branch.

One issue should be fixed before merge (1 below). The rest are a scope question and nits.

What's good

  • Approach: the ripple color stays opaque and the opacity is applied where the ripple is drawn: as android_ripple.alpha on RN 0.86+, as the underlay's opacity on iOS, and inside the color on web. Dynamic-theme PlatformColors now work on Android and iOS.
  • RN 0.85 and older: the opacity is baked into string colors, and a PlatformColor falls back to the default theme's onSurface. This matches the docs.
  • background.alpha: a null or undefined value still gets 0.1, because the code uses ??. A value the user sets, like 0.5, is kept.
  • No double opacity: Button, IconButton and the FAB.Menu items pass their plain content color, so the ~1% problem from the Button MD3 Expressive change is gone.
  • Hover: the web hover uses state.opacity.hovered (0.08).
  • Docs: the migration guide has a clear diff for 5.x users who passed translucent colors and a short note for 6.0-alpha users. ripple-effect.md is updated.
  • Tests: good coverage of RN 0.86 vs 0.85, a background's own alpha, the 0.85 PlatformColor fallback, and unit tests for the new helpers.

Issues

1. Web: a theme with a CSS-variable onSurface gets a fully opaque ripple and hover. Should fix.

getWebStateLayerColor falls back to theme.colors.onSurface. If that can't be parsed either (for example var(--on-surface)), it returns the raw rippleColor with no opacity. The hover and the pressed ripple then cover the content completely. On main this can't happen, because stateLayerPressed was computed in buildScheme.

Suggestion: end the fallback chain on the neutral palette tone, the same as the Android path (getFallbackRippleColor). Then the last step always parses. Please also add a test for it:

return (
  multiplyAlpha(rippleColor, opacity) ??
  multiplyAlpha(theme.colors.onSurface, opacity) ??
  multiplyAlpha(getFallbackRippleColor(theme), opacity)
);

Another option is CSS color-mix(in srgb, <color> <opacity>%, transparent), which keeps the variable working.

2. FAB Shell rippleColor={colors.content}. Scope question.

This is correct per MD3 and covered by FAB.test, but it's a visible change beyond removing the token. The earlier review raised unrelated FAB changes, so this is better split out, or at least called out in the PR description.

3. FAB.Menu: the close button uses the trigger's ripple color while the menu is open.

MorphingTrigger always passes the trigger's variant and contentColor to Shell. While the menu is open, the close button sits on the primary container with a white icon, but its ripple is onPrimaryContainer. On web with LightTheme that's a dark ripple on a dark container. This isn't worse than main (which used onSurface), but it doesn't yet follow the content color when the menu is open.

4. Nit: iOS underlay opacity still depends on underlayColor == null.

That check lives in the component, separate from the util that picks the color. It works, but it's the coupling the earlier review pointed out. Consider returning the opacity from the same helper.

5. Nit: ?? rippleColor at the end of getAndroidRippleColor can never run.

The fallback palette tone always parses, so this branch can be removed.

6. Nit: test gaps.

  • There are no explicit iOS tests for a custom rippleColor or underlayColor; only snapshots cover them.
  • There's no test for background: { alpha: null }.
  • There's no test for a CSS-variable theme.
  • The iOS block still sets Platform.OS = 'ios' at describe time. This predates the PR, but it's worth scoping to beforeAll/afterAll.

Manual test results

Setup: a test screen on a white background with one row per case, plus a text Button, a filled Button, an IconButton, a FAB and a FAB.Menu. Colors were read from the DOM on web and from screenshot pixels on iOS and Android.

Devices: web (Chrome), iOS (iPhone 17 Pro simulator), Android 15 (API 35 emulator). All ran RN 0.86+.

Case Web iOS Android 15
Default ripple (onSurface at 0.1) ✅ 0.1, hover 0.08 ✅ ✅
rippleColor="#FF0000" ✅ 0.1, hover 0.08 ✅ ✅
Red at half alpha → 0.05 ✅ hover 0.04 ✅ ✅
underlayColor purple n/a ✅ drawn as given ✅ ignored, ripple used
background: { color: blue, alpha: 0.5 } ignored ✅ ignored ✅ ✅ 0.5 kept, same as main
background: { color: blue } (no alpha) ignored ✅ ignored ✅ ✅ 0.1 applied
PlatformColor red n/a ✅ kept, not swapped ✅ kept, 0.1 applied
transparent ✅ invisible ✅ invisible ✅ invisible
Text / filled Button, IconButton ✅ label or icon color (white on filled) not tested ✅ content color; main fell back to gray
FAB.Menu trigger ✅ content color not tested ✅ white content; main darkened it
FAB.Menu close button, menu open ❌ trigger color (issue 3) not tested looks right (in this theme both content colors are white)
Theme with onSurface: 'var(--x)' ❌ opaque hover and ripple (issue 1) n/a n/a
Plain FAB ✅ white at 0.1 not tested ⚠️ no ripple, same on main

Notes:

  • On Android, RippleDrawable draws the ripple at about 75–78% of the alpha it's given. This happens on main too and for both baked and native alpha, so it comes from the platform, not this PR.
  • The plain FAB has no ripple on Android on main as well, so that's a separate bug.

Not tested on a device: RN 0.85 and older (the baked-alpha path) and Android 11 or earlier. These are covered only by unit tests and reading the code. On iOS, only the plain TouchableRipple rows were forced into the pressed state.

Summary

Approve once issue 1 is fixed. Issues 2 and 3 should either be split into their own PR or have 3 fixed here.

…ack#4972)

TouchableRipple now takes an opaque color and applies the MD3 pressed
state-layer opacity itself, so theme.colors.stateLayerPressed is gone.

- Android: on React Native 0.86+, pass the color as it is with
  android_ripple.alpha, so PlatformColor ripples (dynamic themes) work.
  On 0.85 and older, bake the alpha into a string color and swap a
  PlatformColor for the static onSurface tone.
- iOS: the default underlay is drawn at the pressed opacity.
- Web: the pressed and hover layers take the ripple color at the pressed
  and hovered opacities.
- Button, IconButton and the FAB.Menu items pass their opaque content
  color, so the opacity isn't applied twice.

BREAKING CHANGE: Removes theme.colors.stateLayerPressed. Pass an opaque
rippleColor; TouchableRipple applies the pressed opacity.
The ripple fallback for React Native 0.85 and older hardcoded the
neutral10 and neutral90 palette tones. It now reads the onSurface role
through the light and dark role mapping, with the new getRoleColor,
so it follows the default themes if that mapping changes.

The tests compare the fallback with LightTheme's and DarkTheme's
onSurface, and getRoleColor with what buildScheme maps every role to.
On web the opacity is put into the ripple color. A color `color` can't
parse, such as var(--x), fell back to theme.colors.onSurface, and when
that was a CSS variable too, to the raw ripple color without opacity, so
the hover and pressed layers covered the content.

The fallback now ends on the default theme's onSurface from the palette,
which always parses, so the layers keep their opacity. The rippleColor
docs and the ripple effect guide describe the fallback.
On React Native 0.85 and older, the Android ripple color ended on
`?? rippleColor` after the default theme's onSurface, which always
parses, so that branch could never run. The fallback now puts the
opacity into that color directly.
- iOS: a rippleColor underlay is drawn at the pressed opacity, and an
  underlayColor as it is. Only snapshots covered them before.
- Android: a null ripple alpha, which React Native's types allow, and a
  background alpha set to undefined both get the pressed alpha.
- The iOS block sets Platform.OS per test with jest.replaceProperty,
  instead of once when the suite is collected.
The iOS highlight took its color from getTouchableRippleColors, while
the component decided its opacity from whether underlayColor was set.
getTouchableRippleColors now returns both: the ripple color at the
pressed opacity, or an underlayColor as it is, at full opacity.

No visual change: the two underlay snapshots only merge the opacity into
the color's style object, and spell out opacity 1 for an underlayColor.
Per the MD3 FAB spec, the pressed and hovered state layers take the
content color. FAB's Shell now passes it to TouchableRipple as the
ripple color, instead of the default onSurface, which was grey on a
dark or dynamic-color container.

The FAB.Menu trigger is the close button while the menu is open. It
now gives Shell the close button's content color then, so the close
button's ripple matches its icon instead of the trigger's.
@Priyanshu0007
Priyanshu0007 force-pushed the feat/remove-state-layer-pressed branch from 0970e54 to 25cb464 Compare December 4, 2026 16:46
@Priyanshu0007

Copy link
Copy Markdown
Contributor Author

@alpharius-ck thanks for the thorough review! I rebased on main and put each point in its own commit:

  1. CSS-variable onSurface on web – 0516aac. The fallback now ends on the default theme's onSurface, which always parses. Added util and hover tests and a note in ripple-effect.md. In Chrome, with both rippleColor and onSurface set to var(...), press is rgba(29, 27, 32, 0.1) and hover is 0.08. Also 9f43779: the fallback is read from the role-to-tone map (getRoleColor) instead of hardcoded palette keys.
  2. FAB content color – called out in the description. It shares commit 25cb464 with point 3, since the close-button fix builds on it.
  3. FAB.Menu close button – 25cb464. While the menu is open, Shell gets the close button's content color. Web: hover rgba(255, 255, 255, 0.08), press 0.1. Android: pressing now lightens the close button instead of darkening it.
  4. iOS underlay opacity – a71d3dc. getTouchableRippleColors returns the underlay color and its opacity together.
  5. Unreachable ?? rippleColor – afd1833.
  6. Test gaps – e12eef2: iOS tests for a custom rippleColor and underlayColor; a null alpha test (through getAndroidRippleColor, since RN's type for background.alpha doesn't allow null); the iOS block now sets Platform.OS per test and restores it. The CSS-variable tests are in 0516aac.

Lint, typecheck and all 1866 tests pass.

@Doberjohn Doberjohn left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Approving. Thanks Priyanshu0007 for the rework, and alpharius-ck for the test table that shaped the last round.

Checked on the head (25cb464) and on a local merge with main: typecheck, lint and the tests pass on both. Pressed layers on device:

  • Android 16 (API 36 emulator): every press is drawn in its content color: TouchableRipple with the default, an opaque and a PlatformColor rippleColor, text and filled Button, IconButton, FAB, the FAB.Menu trigger and menu items, and the close button while the menu is open, which now uses onPrimary instead of darkening the container with onSurface. An opaque or PlatformColor rippleColor is now translucent instead of near solid.
  • iOS (iPhone 18 Pro simulator, iOS 27.2): the highlight is 0.10 in the same colors.
  • Web (Chrome): hover 0.08 and press 0.10. A theme whose onSurface is a CSS variable now gets the default onSurface at those opacities instead of an opaque layer, and FAB.Menu items still draw a single layer.

Keeping the FAB content color change in this PR makes sense to me: it's what the MD3 state layer spec asks for, and without it the FAB would fall back to onSurface once stateLayerPressed is gone.

Two small things, fine as follow-ups:

  1. A Button test that pins the opaque label color with alpha: 0.1 on Android, like the new IconButton and FAB tests. Button is where the double-opacity problem started, and it's the one content-color component without such a test.
  2. nativeRippleTakesAlpha reads only the major and minor version, so 0.86.0-rc.0 and rc.1 count as taking alpha, but android_ripple.alpha only landed in rc.2. On those two release candidates the ripple is opaque. It fits with the prerelease version check in #5355.

Separately, on Android 13 the pressed layer still shows at about 1%, the same as on main: the platform seems to apply the ripple alpha twice there. That gets its own issue for 6.1.

@Doberjohn
Doberjohn merged commit c05552f into callstack:main Dec 6, 2026
12 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.

feat: integrate PlatformColor with alpha to replace stateLayerPressed

3 participants