Repository navigation
Conversation
ColorPropConverter threw when no resource path resolved, ignoring the raw
`fallback` string that `PlatformColor(..., {fallback})` sends. Java prop
setters (backgroundColor, borderColor, TextInput colors, ripple) crashed
while the C++ renderer painted the fallback. Parse the fallback with the
shared C++ CSS color parser over JNI, and paint transparent when nothing
resolves, matching the C++ renderer and iOS.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary:
On Android, a
PlatformColorwhose name doesn't resolve crashes the app, even when afallbackis set. This PR makes Android paint the fallback, or transparent when there is none, the same as iOS and the Android C++ renderer already do.The problem
RN 0.88 added a lazy raw-color fallback to
PlatformColor(#57701, #57655, #57556):#ff0000Stack trace
Root cause
{resource_paths: [...], fallback: '#ff0000'}.fallback(PlatformColorParser.cpp).enablePropsUpdateReconciliationAndroid, which would send the C++-parsed value instead, defaults tofalseColorPropConverter, which never readsfallbackand throws when no path resolves.Every Java color path goes through
ColorPropConverter, so all of them are affected:@ReactPropcolor setters (including TextInput colors),BaseViewManagerDelegate, ripple, box shadow, gradients and animated colors.The fix
When no resource path resolves,
ColorPropConverternow:parseCSSProperty<CSSColor>→hostPlatformColorFromRGBA). Hex,rgb(),rgba(),hsl(),hsla(),hwb()and named colors resolve exactly as on the other paths, with no Kotlin copy of the parser to drift.The parser is reached through a small JNI helper,
RawColorParser, laid out like the existingScrollEventHelperandTouchesHelper. It only runs on a miss that has a fallback; colors that resolve take the same path as before.bridge/ColorPropConverter.ktbridge/RawColorParser.ktnativeParse(value): Int?jni/react/jni/RawColorParser.{h,cpp}jni/react/jni/OnLoad.cpp,CMakeLists.txtreact_renderer_cssscripts/cxx-api/api-snapshots/ReactAndroid*Cxx.apiColorPropConverterTest.kt,ShadowRawColorParser.ktBehavior across platforms
PlatformColorfallbackfallbackfallbackImportant
Behavior change on Android. An unresolved
PlatformColorwith no fallback used to throw through the@ReactPropcolor setters. It now paints transparent and logs a warning, matching iOS, the Android C++ renderer and the RN Tester example ("miss → transparent"). This is intentional.Changelog:
[ANDROID] [FIXED] - Honor the
PlatformColorfallback and paint unresolved colors transparent instead of crashingTest Plan:
Automated
./gradlew :packages:react-native:ReactAndroid:testDebugUnitTest --tests 'com.facebook.react.bridge.ColorPropConverterTest'yarn cxx-api-validate(Doxygen 1.16.1, same as CI)yarn format-check-kotlin,yarn format-check-cppThe 6 new tests cover a valid fallback, the fallback beating a caller's default value, a transparent fallback, a resolved path ignoring the fallback, and the missing and invalid fallback cases. Against the old
ColorPropConverter, the fallback tests fail.Manual: RN Tester
Pixel 8 Pro emulator, Android 14, RN Tester built from source:
./gradlew :packages:rn-tester:android:app:assembleDebug -PreactNativeArchitectures=arm64-v8arntester://example/PlatformColorExample).After the fix:
rgb(),rgba()and#RRGGBBAAfallbacks paint the expected colors onbackgroundColor,borderColorand textcolor.'not-a-color'renders that row transparent, with no crash.Not run
The full CI matrix and iOS. iOS code is unchanged by this PR.