Repository navigation
Description
Description
On Android, a filter list that holds only colour functions (brightness, contrast, grayscale, hueRotate, invert, opacity, saturate, sepia) applies them last to first. FilterHelper.parseColorMatrixFilters (L74-L100) folds the list into one ColorMatrix with resultColorMatrix.preConcat(tempColorMatrix) (L96), and ColorMatrix.setConcat(matA, matB), which preConcat calls as setConcat(this, prematrix), applies matB first. So each function is applied before the ones written ahead of it. The fold came in with #44453.
BaseViewManager takes this path for every list isOnlyColorMatrixFilters admits, at every API level (L597-L603). A list that also holds a blur or a dropShadow goes through parseFilters and RenderEffect on Android 12 and later, which chains the functions in the order written, so the same colour functions draw differently once a blur follows them.
CSS applies a filter list in the order written (Filter Effects 1). For a red box with [{invert: 1}, {sepia: 1}], invert(1) gives rgb(0, 255, 255) and sepia(1) then gives rgb(244, 218, 170). In reverse order, sepia(1) first, the box is rgb(155, 166, 186).
Steps to reproduce
- Clone the reproducer,
yarn installinReproducerApp, and run it on an Android device (yarn android). - The white screen shows one 200 × 200 box with
backgroundColor: 'rgb(255, 0, 0)'andfilter: [{invert: 1}, {sepia: 1}](the list is inReproducerApp/filter.json).
Expected: the box is rgb(244, 218, 170), a light tan, as in a browser, and as the same list draws on Android with a blur after it.
Seen: the box is rgb(155, 166, 186), a grey blue: sepia(1) applied first, then invert(1).
bash reproduce-android.sh at the reproducer's root does the same on the device adb is attached to: it builds and installs the release app, reads the colour at the box's centre from adb exec-out screencap, and exits 1 when the box shows the list in reverse order. It takes another list as its one argument, bash reproduce-android.sh '[{"invert":1},{"sepia":1},{"blur":1}]'.
React Native Version
0.88.1, and 0.90.0-nightly-20261127-7a2d1d257
Affected Platforms
Runtime - Android
Output of npx @react-native-community/cli info
System:
OS: Windows 11 10.0.26300
CPU: "(32) x64 AMD Ryzen 9 9950X3D 16-Core Processor "
Memory: 94.48 GB / 255.67 GB
Binaries:
Node:
version: 26.12.1
path: C:\Program Files\nodejs\node.EXE
Yarn:
version: 1.22.22
path: C:\Users\[…]\AppData\Roaming\npm\yarn.CMD
npm:
version: 12.2.1
path: C:\Program Files\nodejs\npm.CMD
Watchman: Not Found
SDKs:
Android SDK: Not Found
Windows SDK:
AllowDevelopmentWithoutDevLicense: Enabled
Versions:
- 10.0.19041.0
- 10.0.26100.0
IDEs:
Android Studio: AI-262.9437.185.2621.16467767
Visual Studio: Not Found
Languages:
Java:
version: 17.0.20.1
path: C:\Program Files\Microsoft\jdk-17.0.20.101-hotspot\bin\javac.EXE
Ruby: Not Found
npmPackages:
"@react-native-community/cli":
installed: 20.2.0
wanted: 20.2.0
react:
installed: 19.3.0
wanted: 19.3.0
react-native:
installed: 0.88.1
wanted: 0.88.1
react-native-windows: Not Found
npmGlobalPackages:
"*react-native*": Not Found
Android:
hermesEnabled: true
newArchEnabled: true
iOS:
hermesEnabled: Not found
newArchEnabled: Not found
Stacktrace or Logs
bash reproduce-android.sh on a Galaxy S23:
[…]
react-native 0.88.1, release build, SM-S911B on Android 14 (API 34)
filter: [{"invert":1},{"sepia":1}] on a rgb(255, 0, 0) box over rgb(255, 255, 255)
in the order written, as CSS draws it: rgb(244, 218, 170)
in reverse order: rgb(155, 166, 186)
the box's centre on the screen: rgb(155, 166, 186)
the box draws the list in reverse order
The reproducer's nightly branch, on 0.90.0-nightly-20261127-7a2d1d257:
[…]
react-native 0.90.0-nightly-20261127-7a2d1d257, release build, SM-S911B on Android 14 (API 34)
filter: [{"invert":1},{"sepia":1}] on a rgb(255, 0, 0) box over rgb(255, 255, 255)
in the order written, as CSS draws it: rgb(244, 218, 170)
in reverse order: rgb(155, 166, 186)
the box's centre on the screen: rgb(155, 166, 186)
the box draws the list in reverse order
The same list with a blur after it, bash reproduce-android.sh '[{"invert":1},{"sepia":1},{"blur":1}]' on 0.88.1:
[…]
react-native 0.88.1, release build, SM-S911B on Android 14 (API 34)
filter: [{"invert":1},{"sepia":1},{"blur":1}] on a rgb(255, 0, 0) box over rgb(255, 255, 255)
in the order written, as CSS draws it: rgb(244, 218, 170)
the box's centre on the screen: rgb(244, 218, 169)
the box draws the list in the order written
MANDATORY Reproducer
https://github.com/YevheniiKotyrlo/react-native-android-filter-colours
Screenshots and Videos
No response
Activity