From dfed2d925d713cf8cab431cbb5851d53db4d4114 Mon Sep 17 00:00:00 2001 From: Shubh Porwal Date: Wed, 28 Oct 2026 16:58:45 +0530 Subject: [PATCH] Fix shadowColor and outline prop defaults in BaseViewManagerDelegate MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## 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 | | --- | --- | | Before | After | 🤖 Generated with [Claude Code](https://claude.com/claude-code) Differential Revision: D127789219 Pull Request resolved: https://github.com/react/react-native/pull/59423 --- .../uimanager/BaseViewManagerDelegate.kt | 16 ++++++-------- .../BaseViewManagerDelegateTest.java | 22 +++++++++++++++++++ 2 files changed, 29 insertions(+), 9 deletions(-) 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 c1d63abe3a7..fb4ca1ad6ea 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 @@ -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) 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 index baa5e5883ed..594f2c75f9d 100644 --- 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 @@ -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); + } }