Skip to content

Commit 88b45be

Browse files
committed
fix: ensure transparent and backdropColor take precedence over style prop
Reorder the style array so explicit Modal API props (transparent, backdropColor) always win over the generic style prop. Move the default backgroundColor into styles.container so user styles can override the default but not the explicit props. Precedence: styles.container (default white) → this.props.style → containerStyles - <Modal style={{ backgroundColor: 'red' }}> → red (user overrides default) - <Modal transparent> → transparent (explicit prop wins over style) - <Modal transparent style={{ backgroundColor: 'red' }}> → transparent wins - <Modal backdropColor="blue" style={{ backgroundColor: 'red' }}> → blue wins - <Modal style={{ padding: 20 }}> → works, no conflicts
1 parent ad0f25d commit 88b45be

1 file changed

Lines changed: 12 additions & 7 deletions

File tree

  • packages/react-native/Libraries/Modal

packages/react-native/Libraries/Modal/Modal.js

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -288,12 +288,16 @@ class Modal extends React.Component<ModalProps, ModalState> {
288288
return null;
289289
}
290290

291-
const containerStyles = {
292-
backgroundColor:
293-
this.props.transparent === true
294-
? 'transparent'
295-
: (this.props.backdropColor ?? 'white'),
296-
};
291+
// Only override backgroundColor when transparent or backdropColor are
292+
// explicitly set, so that these Modal-specific props take precedence
293+
// over the generic style prop. The default backgroundColor ('white')
294+
// is defined in styles.container below.
295+
const containerStyles = {};
296+
if (this.props.transparent === true) {
297+
containerStyles.backgroundColor = 'transparent';
298+
} else if (this.props.backdropColor != null) {
299+
containerStyles.backgroundColor = this.props.backdropColor;
300+
}
297301

298302
let animationType = this.props.animationType || 'none';
299303

@@ -349,7 +353,7 @@ class Modal extends React.Component<ModalProps, ModalState> {
349353
<ScrollView.Context.Provider value={null}>
350354
<View
351355
// $FlowFixMe[incompatible-type]
352-
style={[styles.container, containerStyles, this.props.style]}
356+
style={[styles.container, this.props.style, containerStyles]}
353357
collapsable={false}>
354358
{innerChildren}
355359
</View>
@@ -380,6 +384,7 @@ const styles = StyleSheet.create({
380384
[side]: 0,
381385
top: 0,
382386
flex: 1,
387+
backgroundColor: 'white',
383388
},
384389
});
385390

0 commit comments

Comments
 (0)