Commit f8fa76f
fix: forward style prop to Modal inner container View (#56181)
Summary:
`Modal` accepts a `style` prop via `ViewProps` (since `ModalProps` spreads `...ViewProps`) but silently discards it. The inner container `<View>` only applies `styles.container` and `containerStyles` (which handles `backdropColor`/`transparent`), so any style passed by the consumer has no effect.
For example, `<Modal style={{ padding: 20 }}>` 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 |
|---|---|
| `<Modal style={{ backgroundColor: 'red' }}>` | Red (user overrides default white) |
| `<Modal transparent>` | Transparent (explicit prop wins) |
| `<Modal transparent style={{ backgroundColor: 'red' }}>` | Transparent wins |
| `<Modal backdropColor="blue" style={{ backgroundColor: 'red' }}>` | Blue wins |
| `<Modal style={{ padding: 20 }}>` | 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: #56181
Test Plan:
1. Render a Modal with a custom style prop:
```jsx
<Modal visible style={{ padding: 40, backgroundColor: 'red' }}>
<View style={{ flex: 1, backgroundColor: 'white' }}>
<Text>Hello</Text>
</View>
</Modal>
```
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: b138648ce41b55eb794c79a0217f905d5cc9a5f21 parent c2280e3 commit f8fa76f
2 files changed
Lines changed: 15 additions & 10 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
288 | 288 | | |
289 | 289 | | |
290 | 290 | | |
291 | | - | |
292 | | - | |
293 | | - | |
294 | | - | |
295 | | - | |
296 | | - | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
297 | 301 | | |
298 | 302 | | |
299 | 303 | | |
| |||
349 | 353 | | |
350 | 354 | | |
351 | 355 | | |
352 | | - | |
| 356 | + | |
353 | 357 | | |
354 | 358 | | |
355 | 359 | | |
| |||
380 | 384 | | |
381 | 385 | | |
382 | 386 | | |
| 387 | + | |
383 | 388 | | |
384 | 389 | | |
385 | 390 | | |
| |||
Lines changed: 3 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
26 | 26 | | |
27 | 27 | | |
28 | 28 | | |
| 29 | + | |
29 | 30 | | |
30 | 31 | | |
31 | 32 | | |
32 | 33 | | |
33 | | - | |
34 | | - | |
35 | | - | |
| 34 | + | |
| 35 | + | |
36 | 36 | | |
37 | 37 | | |
38 | 38 | | |
| |||
0 commit comments