mirror of
https://github.com/facebook/react-native.git
synced 2026-11-18 20:19:07 +00:00
Fix shadowColor and outline prop defaults in BaseViewManagerDelegate
## Summary: `BaseViewManagerDelegate` resets three props to values that don't match the `@ReactProp` defaults in `BaseViewManager` when they're removed: | Prop | `BaseViewManager` default | `BaseViewManagerDelegate` | | --- | --- | --- | | `shadowColor` | `Color.BLACK` | `0` | | `outlineOffset` | `0f` | `YogaConstants.UNDEFINED` | | `outlineWidth` | `0f` | `YogaConstants.UNDEFINED` | This affects every component whose view manager uses a codegen delegate (e.g. `Switch`, `Modal`, `RefreshControl`, and third-party Fabric components), but not `View`. Removing `shadowColor` from a view with `elevation` makes the shadow disappear instead of going back to black, and removing `outlineOffset` makes the outline disappear instead of drawing it with no offset. This makes the delegate use the same defaults as `BaseViewManager`. ## Changelog: [ANDROID] [FIXED] - Fix `shadowColor`, `outlineOffset` and `outlineWidth` not resetting to their defaults on components with a codegen view manager delegate ## Test Plan: Added `setShadowColorResetsToBlack`, `setOutlineOffsetResetsToZero` and `setOutlineWidthResetsToZero` to `BaseViewManagerDelegateTest`. They pass with this change and fail without it (`0` instead of `-16777216`, `NaNf` instead of `0.0f`). ``` ./gradlew :packages:react-native:ReactAndroid:testDebugUnitTest --tests "com.facebook.react.uimanager.BaseViewManagerDelegateTest" ``` Also checked in RNTester on an OPPO K12x 5G (CPH2667, Android 16) with a `View` and a `Switch` side by side, each with `elevation` + `shadowColor: 'red'` and `outlineWidth` + `outlineOffset: 8`, then removing `shadowColor` and `outlineOffset`: - Before: `View` resets correctly; on `Switch` the shadow and the outline both disappear. - After: `Switch` matches `View` (black shadow, outline with no offset). | Before | After | | --- | --- | | <img width="360" alt="Before" src="https://github.com/user-attachments/assets/94029d71-1786-45b1-bbcf-616aafcdd5ac" /> | <img width="360" alt="After" src="https://github.com/user-attachments/assets/014a6285-6dc4-44f4-94e7-cb9a9a54b285" /> | 🤖 Generated with [Claude Code](https://claude.com/claude-code) Differential Revision: D127789219 Pull Request resolved: https://github.com/react/react-native/pull/59423
This commit is contained in:
1 parent
3cee68fa7a
commit
dfed2d925d
2 files changed
+29
-9
No files matched your search
+7
-9
@@ -7,6 +7,7 @@
|
||||
|
||||
package com.facebook.react.uimanager
|
||||
|
||||
import android.graphics.Color
|
||||
import android.view.View
|
||||
import com.facebook.react.bridge.ColorPropConverter
|
||||
import com.facebook.react.bridge.Dynamic
|
||||
@@ -89,7 +90,10 @@ public abstract class BaseViewManagerDelegate<
|
||||
ViewProps.MIX_BLEND_MODE -> mViewManager.setMixBlendMode(view, value as String?)
|
||||
|
||||
ViewProps.SHADOW_COLOR ->
|
||||
mViewManager.setShadowColor(view, ColorPropConverter.getColor(value, view.context, 0))
|
||||
mViewManager.setShadowColor(
|
||||
view,
|
||||
ColorPropConverter.getColor(value, view.context, Color.BLACK),
|
||||
)
|
||||
|
||||
ViewProps.IMPORTANT_FOR_ACCESSIBILITY ->
|
||||
mViewManager.setImportantForAccessibility(view, value as String?)
|
||||
@@ -113,18 +117,12 @@ public abstract class BaseViewManagerDelegate<
|
||||
)
|
||||
|
||||
ViewProps.OUTLINE_OFFSET ->
|
||||
mViewManager.setOutlineOffset(
|
||||
view,
|
||||
(value as Double?)?.toFloat() ?: YogaConstants.UNDEFINED,
|
||||
)
|
||||
mViewManager.setOutlineOffset(view, (value as Double?)?.toFloat() ?: 0.0f)
|
||||
|
||||
ViewProps.OUTLINE_STYLE -> mViewManager.setOutlineStyle(view, value as String?)
|
||||
|
||||
ViewProps.OUTLINE_WIDTH ->
|
||||
mViewManager.setOutlineWidth(
|
||||
view,
|
||||
(value as Double?)?.toFloat() ?: YogaConstants.UNDEFINED,
|
||||
)
|
||||
mViewManager.setOutlineWidth(view, (value as Double?)?.toFloat() ?: 0.0f)
|
||||
|
||||
ViewProps.RENDER_TO_HARDWARE_TEXTURE ->
|
||||
mViewManager.setRenderToHardwareTexture(view, value as Boolean? ?: false)
|
||||
|
||||
+22
@@ -10,6 +10,7 @@ package com.facebook.react.uimanager;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
||||
import android.graphics.Color;
|
||||
import com.facebook.react.bridge.ReactApplicationContext;
|
||||
import com.facebook.react.bridge.ReactTestHelper;
|
||||
import com.facebook.react.internal.featureflags.ReactNativeFeatureFlags;
|
||||
@@ -63,4 +64,25 @@ public class BaseViewManagerDelegateTest {
|
||||
|
||||
verify(viewManager).setOutlineColor(view, null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setShadowColorResetsToBlack() {
|
||||
delegate.setProperty(view, ViewProps.SHADOW_COLOR, null);
|
||||
|
||||
verify(viewManager).setShadowColor(view, Color.BLACK);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setOutlineOffsetResetsToZero() {
|
||||
delegate.setProperty(view, ViewProps.OUTLINE_OFFSET, null);
|
||||
|
||||
verify(viewManager).setOutlineOffset(view, 0f);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setOutlineWidthResetsToZero() {
|
||||
delegate.setProperty(view, ViewProps.OUTLINE_WIDTH, null);
|
||||
|
||||
verify(viewManager).setOutlineWidth(view, 0f);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user