From 53b933fecac5c51118f55983f82c622aede1d682 Mon Sep 17 00:00:00 2001 From: HURRAEY Date: Wed, 22 Jul 2026 03:11:43 -0700 Subject: [PATCH] fix(android): convert outlineColor values before delegation (#57558) Summary: - Convert Android `outlineColor` values with `ColorPropConverter` before delegating them to the view manager. - Preserve the nullable color contract by using the converter overload without a default value. - Add a regression test for `Double` color values that previously threw `ClassCastException`. Fixes https://github.com/react/react-native/issues/57190 ## Changelog: [Android] [Fixed] - Fix crashes when `outlineColor` is provided as a numeric color value Pull Request resolved: https://github.com/react/react-native/pull/57558 Test Plan: - [x] Confirmed that the regression test fails with `ClassCastException` before the fix - [x] `BaseViewManagerDelegateTest` - [x] `:packages:react-native:ReactAndroid:test` - [x] `npx prettier --write .` - [ ] Full JavaScript lint: stops while loading `react-native/specs/react-native-modules` for the unchanged `NativeDevMenu.js` file with `SyntaxError: Unexpected token '{'` Reviewed By: Abbondanzo Differential Revision: D113021908 Pulled By: fabriziocucci fbshipit-source-id: 493f3da9a3df19b5309f82aab9b8f964666a672a --- .../uimanager/BaseViewManagerDelegate.kt | 8 ++- .../BaseViewManagerDelegateTest.java | 52 +++++++++++++++++++ 2 files changed, 59 insertions(+), 1 deletion(-) create mode 100644 packages/react-native/ReactAndroid/src/test/java/com/facebook/react/uimanager/BaseViewManagerDelegateTest.java diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/BaseViewManagerDelegate.kt b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/BaseViewManagerDelegate.kt index 9fca177f3b1..d2164e77b19 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/BaseViewManagerDelegate.kt +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/BaseViewManagerDelegate.kt @@ -104,7 +104,13 @@ public abstract class BaseViewManagerDelegate< mViewManager.setAccessibilityLabelledBy(view, dynamicFromObject) } ViewProps.OPACITY -> mViewManager.setOpacity(view, (value as Double?)?.toFloat() ?: 1.0f) - ViewProps.OUTLINE_COLOR -> mViewManager.setOutlineColor(view, value as Int?) + ViewProps.OUTLINE_COLOR -> + mViewManager.setOutlineColor( + view, + // Use the overload without a default value to preserve outlineColor's nullable + // contract. + ColorPropConverter.getColor(value, view.context), + ) ViewProps.OUTLINE_OFFSET -> mViewManager.setOutlineOffset( diff --git a/packages/react-native/ReactAndroid/src/test/java/com/facebook/react/uimanager/BaseViewManagerDelegateTest.java b/packages/react-native/ReactAndroid/src/test/java/com/facebook/react/uimanager/BaseViewManagerDelegateTest.java new file mode 100644 index 00000000000..6de844d1e5c --- /dev/null +++ b/packages/react-native/ReactAndroid/src/test/java/com/facebook/react/uimanager/BaseViewManagerDelegateTest.java @@ -0,0 +1,52 @@ +/* + * Copyright (c) Meta Platforms, Inc. and affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +package com.facebook.react.uimanager; + +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; + +import com.facebook.react.bridge.ReactApplicationContext; +import com.facebook.react.bridge.ReactTestHelper; +import com.facebook.react.views.view.ReactViewGroup; +import com.facebook.react.views.view.ReactViewManager; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.robolectric.RobolectricTestRunner; + +@RunWith(RobolectricTestRunner.class) +public class BaseViewManagerDelegateTest { + private ReactViewManager viewManager; + private ReactViewGroup view; + private BaseViewManagerDelegate delegate; + + @Before + public void setUp() { + viewManager = mock(ReactViewManager.class); + ReactApplicationContext context = ReactTestHelper.createCatalystContextForTest(); + ThemedReactContext themedReactContext = new ThemedReactContext(context, context, null, -1); + view = new ReactViewGroup(themedReactContext); + delegate = new BaseViewManagerDelegate<>(viewManager) {}; + } + + @Test + public void setOutlineColorConvertsDoubleToInt() { + int color = 0xFF336699; + + delegate.setProperty(view, ViewProps.OUTLINE_COLOR, (double) color); + + verify(viewManager).setOutlineColor(view, color); + } + + @Test + public void setOutlineColorPreservesNull() { + delegate.setProperty(view, ViewProps.OUTLINE_COLOR, null); + + verify(viewManager).setOutlineColor(view, null); + } +}