From f8fa76f94c37a97e0479f55e9945e1dd111a5567 Mon Sep 17 00:00:00 2001 From: Anurag Yadav <78202060+AnuMessi10@users.noreply.github.com> Date: Thu, 16 Apr 2026 10:46:53 -0700 Subject: [PATCH] fix: forward style prop to Modal inner container View (#56181) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Summary: `Modal` accepts a `style` prop via `ViewProps` (since `ModalProps` spreads `...ViewProps`) but silently discards it. The inner container `` only applies `styles.container` and `containerStyles` (which handles `backdropColor`/`transparent`), so any style passed by the consumer has no effect. For example, `` compiles without errors but the padding is never applied. This PR forwards `this.props.style` to the inner container View with a carefully designed precedence chain: ``` styles.container (layout defaults + white background) → this.props.style (consumer overrides) → containerStyles (explicit transparent / backdropColor always win) ``` `containerStyles` now only sets `backgroundColor` when `transparent` or `backdropColor` are explicitly passed, ensuring these Modal-specific API props always take precedence over the generic `style` prop while still allowing consumers to customize other style properties. **Precedence examples:** | Usage | Result | |---|---| | `` | Red (user overrides default white) | | `` | Transparent (explicit prop wins) | | `` | Transparent wins | | `` | Blue wins | | `` | Works, no conflicts | ## Changelog: [GENERAL] [FIXED] - Forward `style` prop to Modal's inner container View with correct precedence so consumer styles are applied without overriding `transparent` or `backdropColor` Pull Request resolved: https://github.com/facebook/react-native/pull/56181 Test Plan: 1. Render a Modal with a custom style prop: ```jsx Hello ``` 2. **Before fix:** `padding` and `backgroundColor` are silently ignored 3. **After fix:** The modal container has 40px padding and a red background Also verified that: - `transparent={true}` always produces a transparent background, even if `style={{ backgroundColor }}` is set - `backdropColor` always takes precedence over `style.backgroundColor` - Default behavior (no `style` prop) is unchanged — white background - Non-backgroundColor style properties (padding, margin, etc.) work without conflicts Reviewed By: javache Differential Revision: D101170804 Pulled By: zeyap fbshipit-source-id: b138648ce41b55eb794c79a0217f905d5cc9a5f2 --- .../react-native/Libraries/Modal/Modal.js | 19 ++++++++++++------- .../__snapshots__/Modal-test.js.snap | 6 +++--- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/packages/react-native/Libraries/Modal/Modal.js b/packages/react-native/Libraries/Modal/Modal.js index 1fabac7de3d..28233e6f266 100644 --- a/packages/react-native/Libraries/Modal/Modal.js +++ b/packages/react-native/Libraries/Modal/Modal.js @@ -288,12 +288,16 @@ class Modal extends React.Component { return null; } - const containerStyles = { - backgroundColor: - this.props.transparent === true - ? 'transparent' - : (this.props.backdropColor ?? 'white'), - }; + // Only override backgroundColor when transparent or backdropColor are + // explicitly set, so that these Modal-specific props take precedence + // over the generic style prop. The default backgroundColor ('white') + // is defined in styles.container below. + const containerStyles: {backgroundColor?: ColorValue} = {}; + if (this.props.transparent === true) { + containerStyles.backgroundColor = 'transparent'; + } else if (this.props.backdropColor != null) { + containerStyles.backgroundColor = this.props.backdropColor; + } let animationType = this.props.animationType || 'none'; @@ -349,7 +353,7 @@ class Modal extends React.Component { {innerChildren} @@ -380,6 +384,7 @@ const styles = StyleSheet.create({ [side]: 0, top: 0, flex: 1, + backgroundColor: 'white', }, }); diff --git a/packages/react-native/Libraries/Modal/__tests__/__snapshots__/Modal-test.js.snap b/packages/react-native/Libraries/Modal/__tests__/__snapshots__/Modal-test.js.snap index 9b33931eb1a..b157f063e77 100644 --- a/packages/react-native/Libraries/Modal/__tests__/__snapshots__/Modal-test.js.snap +++ b/packages/react-native/Libraries/Modal/__tests__/__snapshots__/Modal-test.js.snap @@ -26,13 +26,13 @@ exports[`Modal should render as when not mocked 1`] = ` style={ Array [ Object { + "backgroundColor": "white", "flex": 1, "left": 0, "top": 0, }, - Object { - "backgroundColor": "white", - }, + undefined, + Object {}, ] } >