diff --git a/packages/react-native/Libraries/Modal/Modal.d.ts b/packages/react-native/Libraries/Modal/Modal.d.ts index 4cc2df22367b..a8b647874271 100644 --- a/packages/react-native/Libraries/Modal/Modal.d.ts +++ b/packages/react-native/Libraries/Modal/Modal.d.ts @@ -10,6 +10,7 @@ import type * as React from 'react'; import {ViewProps} from '../Components/View/ViewPropTypes'; import {NativeSyntheticEvent} from '../Types/CoreEventTypes'; +import {ColorValue} from '../StyleSheet/StyleSheet'; export interface ModalBaseProps { /** @@ -43,6 +44,12 @@ export interface ModalBaseProps { * The `onShow` prop allows passing a function that will be called once the modal has been shown. */ onShow?: ((event: NativeSyntheticEvent) => void) | undefined; + + /** + * The `backdropColor` props sets the color of the modal's background overlay. + * Defaults to `white` if not provided and transparent is `false`. Ignored if `transparent` is `true`. + */ + backdropColor?: ColorValue | undefined; } export interface ModalPropsIOS { diff --git a/packages/react-native/Libraries/Modal/Modal.js b/packages/react-native/Libraries/Modal/Modal.js index 1942d9e567d3..32f082184029 100644 --- a/packages/react-native/Libraries/Modal/Modal.js +++ b/packages/react-native/Libraries/Modal/Modal.js @@ -157,6 +157,12 @@ export type Props = $ReadOnly<{| * See https://reactnative.dev/docs/modal#onorientationchange */ onOrientationChange?: ?DirectEventHandler, + + /** + * The `backdropColor` props sets the color of the modal's background overlay. + * Defaults to `white` if not provided and transparent is `false`. Ignored if `transparent` is `true`. + */ + backdropColor?: ?string, |}>; function confirmProps(props: Props) { @@ -250,7 +256,9 @@ class Modal extends React.Component { const containerStyles = { backgroundColor: - this.props.transparent === true ? 'transparent' : 'white', + this.props.transparent === true + ? 'transparent' + : this.props.backdropColor ?? 'white', }; let animationType = this.props.animationType || 'none'; diff --git a/packages/react-native/Libraries/__tests__/__snapshots__/public-api-test.js.snap b/packages/react-native/Libraries/__tests__/__snapshots__/public-api-test.js.snap index e5f4590fdc51..11bc4065329a 100644 --- a/packages/react-native/Libraries/__tests__/__snapshots__/public-api-test.js.snap +++ b/packages/react-native/Libraries/__tests__/__snapshots__/public-api-test.js.snap @@ -6408,6 +6408,7 @@ export type Props = $ReadOnly<{| | \\"landscape-right\\", >, onOrientationChange?: ?DirectEventHandler, + backdropColor?: ?string, |}>; type State = { isRendered: boolean, diff --git a/packages/rn-tester/js/examples/Modal/ModalPresentation.js b/packages/rn-tester/js/examples/Modal/ModalPresentation.js index e5f2cad774eb..c59b07812724 100644 --- a/packages/rn-tester/js/examples/Modal/ModalPresentation.js +++ b/packages/rn-tester/js/examples/Modal/ModalPresentation.js @@ -34,6 +34,8 @@ const supportedOrientations = [ 'landscape-right', ]; +const backdropColors = ['red', 'blue', undefined]; + function ModalPresentation() { const onDismiss = React.useCallback(() => { alert('onDismiss'); @@ -63,10 +65,12 @@ function ModalPresentation() { onDismiss: undefined, onShow: undefined, visible: false, + backdropColor: undefined, }); const presentationStyle = props.presentationStyle; const hardwareAccelerated = props.hardwareAccelerated; const statusBarTranslucent = props.statusBarTranslucent; + const backdropColor = props.backdropColor; const [currentOrientation, setCurrentOrientation] = React.useState('unknown'); @@ -211,6 +215,26 @@ function ModalPresentation() { /> + + Overlay Color ⚫️ + + {backdropColors.map(type => ( + + setProps(prev => ({ + ...prev, + backdropColor: type, + })) + } + selected={type === backdropColor} + /> + ))} + + );