mirror of
https://github.com/facebook/react-native.git
synced 2026-11-18 20:19:07 +00:00
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
This commit is contained in:
1 parent
677f571059
commit
53b933feca
2 files changed
+59
-1
No files matched your search
+7
-1
@@ -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(
|
||||
|
||||
+52
@@ -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<ReactViewGroup, ReactViewManager> 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);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user