Skip to content

Commit 53b933f

Browse files
HURRAEYmeta-codesync[bot]
authored andcommitted
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 #57190 ## Changelog: [Android] [Fixed] - Fix crashes when `outlineColor` is provided as a numeric color value Pull Request resolved: #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
1 parent 677f571 commit 53b933f

2 files changed

Lines changed: 59 additions & 1 deletion

File tree

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/BaseViewManagerDelegate.kt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,13 @@ public abstract class BaseViewManagerDelegate<
104104
mViewManager.setAccessibilityLabelledBy(view, dynamicFromObject)
105105
}
106106
ViewProps.OPACITY -> mViewManager.setOpacity(view, (value as Double?)?.toFloat() ?: 1.0f)
107-
ViewProps.OUTLINE_COLOR -> mViewManager.setOutlineColor(view, value as Int?)
107+
ViewProps.OUTLINE_COLOR ->
108+
mViewManager.setOutlineColor(
109+
view,
110+
// Use the overload without a default value to preserve outlineColor's nullable
111+
// contract.
112+
ColorPropConverter.getColor(value, view.context),
113+
)
108114

109115
ViewProps.OUTLINE_OFFSET ->
110116
mViewManager.setOutlineOffset(
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/*
2+
* Copyright (c) Meta Platforms, Inc. and affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*/
7+
8+
package com.facebook.react.uimanager;
9+
10+
import static org.mockito.Mockito.mock;
11+
import static org.mockito.Mockito.verify;
12+
13+
import com.facebook.react.bridge.ReactApplicationContext;
14+
import com.facebook.react.bridge.ReactTestHelper;
15+
import com.facebook.react.views.view.ReactViewGroup;
16+
import com.facebook.react.views.view.ReactViewManager;
17+
import org.junit.Before;
18+
import org.junit.Test;
19+
import org.junit.runner.RunWith;
20+
import org.robolectric.RobolectricTestRunner;
21+
22+
@RunWith(RobolectricTestRunner.class)
23+
public class BaseViewManagerDelegateTest {
24+
private ReactViewManager viewManager;
25+
private ReactViewGroup view;
26+
private BaseViewManagerDelegate<ReactViewGroup, ReactViewManager> delegate;
27+
28+
@Before
29+
public void setUp() {
30+
viewManager = mock(ReactViewManager.class);
31+
ReactApplicationContext context = ReactTestHelper.createCatalystContextForTest();
32+
ThemedReactContext themedReactContext = new ThemedReactContext(context, context, null, -1);
33+
view = new ReactViewGroup(themedReactContext);
34+
delegate = new BaseViewManagerDelegate<>(viewManager) {};
35+
}
36+
37+
@Test
38+
public void setOutlineColorConvertsDoubleToInt() {
39+
int color = 0xFF336699;
40+
41+
delegate.setProperty(view, ViewProps.OUTLINE_COLOR, (double) color);
42+
43+
verify(viewManager).setOutlineColor(view, color);
44+
}
45+
46+
@Test
47+
public void setOutlineColorPreservesNull() {
48+
delegate.setProperty(view, ViewProps.OUTLINE_COLOR, null);
49+
50+
verify(viewManager).setOutlineColor(view, null);
51+
}
52+
}

0 commit comments

Comments
 (0)