Repository navigation
feat(touchable-ripple)!: state-layer opacity via ripple alpha (#4972) - #5177
Conversation
|
We'd like this PR to carry the
|
2b1a538 to
502cb52
Compare
|
Hi @Doberjohn, i have made changes requested by you. |
|
@Priyanshu0007 hey! could you please resolve merge conflicts and verify that your solution is still working? |
|
/review |
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
Apex Sentinel: 9 new findings on 502cb52. The verdict and the full list are in the summary comment.
- 🟡 Minor · android_ripple.alpha is Android 12+ only; ripple renders fully opaque on Android 5.0–11 ·
src/components/TouchableRipple/TouchableRipple.native.tsx:69 - 🟡 Minor · Unrelated FAB Menu visual changes bundled into the TouchableRipple PR ·
src/components/FAB/Menu.tsx:452 - 🟡 Minor · Explicit background.alpha of undefined/null clobbers the default pressed opacity ·
src/components/TouchableRipple/TouchableRipple.native.tsx:70 - 🟡 Minor · background={{ alpha: null }} silently disables the pressed state-layer opacity ·
src/components/TouchableRipple/TouchableRipple.native.tsx:70 - 🟡 Minor · Explicit rippleColor on iOS/Android<21 now draws at full onSurface opacity at default alpha ·
src/components/TouchableRipple/TouchableRipple.native.tsx:109 - 🟡 Minor · iOS underlay opacity is keyed on underlayColor, not on the color actually painted ·
src/components/TouchableRipple/TouchableRipple.native.tsx:112 - 🟡 Minor · New TouchableRippleAndroidRippleConfig type is not reused by the components that forward background ·
src/components/TouchableRipple/types.ts:9 - 🟡 Minor · PlatformColor rippleColor swapped for a hardcoded neutral on iOS/web too, not just Android ·
src/components/TouchableRipple/utils.ts:28 - 🟡 Minor · New Android suite mutates Platform.OS/support statically with an order-dependent fallback ·
src/components/__tests__/TouchableRipple.test.tsx:121
502cb52 to
8c1aed5
Compare
|
/review |
Apex Sentinel · ✅ Approve · review of
|
| 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 outsrc/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.
There was a problem hiding this comment.
Apex Sentinel: 1 new finding on 8c1aed5. The verdict and the full list are in the summary comment.
- 🟡 Minor · Ripple fallback hand-copies the onSurface-to-palette mapping instead of deriving it ·
src/components/TouchableRipple/utils.ts:130
Review and manual testing of
|
| 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 | main |
Notes:
- On Android,
RippleDrawabledraws the ripple at about 75–78% of the alpha it's given. This happens onmaintoo 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
mainas 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.
0970e54 to
25cb464
Compare
|
@alpharius-ck thanks for the thorough review! I rebased on
Lint, typecheck and all 1866 tests pass. |
Doberjohn
left a comment
There was a problem hiding this comment.
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
PlatformColorrippleColor, 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 orPlatformColorrippleColoris 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
onSurfaceis a CSS variable now gets the defaultonSurfaceat 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:
- A Button test that pins the opaque label color with
alpha: 0.1on 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. nativeRippleTakesAlphareads only the major and minor version, so 0.86.0-rc.0 and rc.1 count as takingalpha, butandroid_ripple.alphaonly 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.
Motivation
Closes #4972. Removes
theme.colors.stateLayerPressedfor 6.0.TouchableRipplenow applies the MD3 pressed opacity (0.10) itself: asandroid_ripple.alphaon 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_ripple.mp4
ios_ripple.mp4
web_ripple.mp4