Elevation and border radius do not work well with opacity from Android 9
See original GitHub issueThe way elevation works is that it creates a border around the element that is then shifted to the bottom. The background color of the element then hides the inside part of the border.
When we apply border radius to the same element, the border gets thicker to accommodate for the increased radius. So far so good.
Unfortunately if we then apply the opacity to the parent, the background color of the element gets semitransparent, making the border visible and creating an ugly effect.
React Native version: 0.57 Expo SDK 32 Android version: 9.0
Steps To Reproduce
Create an element and apply, elevation, border radius and background color. Then apply opacity on its parent.
Describe what you expected to happen:
The border underneath the element should not leak out
Snack, code example, or link to a repository:
Issue Analytics
- State:
- Created 4 years ago
- Reactions:39
- Comments:24 (3 by maintainers)
Using
backgroundColor: '#fff'
sets it right and works as expected.I found that this problem occur when changing opacity on a wrapping element that contain child elements using elevation for shadow. What fixed this bug for me temporarily was to set flag needsOffscreenAlphaCompositing on the wrapping element that i animated opacity style prop for. (For best practice usage check: https://reactnative.dev/docs/view#needsoffscreenalphacompositing) Otherwise setting opacity on each of the child elements should also work, instead of only the parent wrapper.
This was mentioned here: https://github.com/facebook/react-native/issues/23090#issuecomment-669157170