Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions packages/react-native/Libraries/Modal/Modal.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
/**
Expand Down Expand Up @@ -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<any>) => 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 {
Expand Down
10 changes: 9 additions & 1 deletion packages/react-native/Libraries/Modal/Modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,12 @@ export type Props = $ReadOnly<{|
* See https://reactnative.dev/docs/modal#onorientationchange
*/
onOrientationChange?: ?DirectEventHandler<OrientationChangeEvent>,

/**
* 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) {
Expand Down Expand Up @@ -250,7 +256,9 @@ class Modal extends React.Component<Props, State> {

const containerStyles = {
backgroundColor:
this.props.transparent === true ? 'transparent' : 'white',
this.props.transparent === true
? 'transparent'
: this.props.backdropColor ?? 'white',
};

let animationType = this.props.animationType || 'none';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6408,6 +6408,7 @@ export type Props = $ReadOnly<{|
| \\"landscape-right\\",
>,
onOrientationChange?: ?DirectEventHandler<OrientationChangeEvent>,
backdropColor?: ?string,
|}>;
type State = {
isRendered: boolean,
Expand Down
24 changes: 24 additions & 0 deletions packages/rn-tester/js/examples/Modal/ModalPresentation.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ const supportedOrientations = [
'landscape-right',
];

const backdropColors = ['red', 'blue', undefined];

function ModalPresentation() {
const onDismiss = React.useCallback(() => {
alert('onDismiss');
Expand Down Expand Up @@ -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');

Expand Down Expand Up @@ -211,6 +215,26 @@ function ModalPresentation() {
/>
</View>
</View>
<View style={styles.block}>
<Text style={styles.title}>Overlay Color ⚫️</Text>
<View style={styles.row}>
{backdropColors.map(type => (
<RNTOption
key={type}
style={styles.option}
label={type === undefined ? 'default' : type}
multiSelect={true}
onPress={() =>
setProps(prev => ({
...prev,
backdropColor: type,
}))
}
selected={type === backdropColor}
/>
))}
</View>
</View>
</>
);

Expand Down