({
children,
dismissable = true,
dismissableBackButton = dismissable,
onDismiss,
visible = false,
style,
theme: themeOverrides,
testID,
}: Props)
| 95 | * ``` |
| 96 | */ |
| 97 | const Dialog = ({ |
| 98 | children, |
| 99 | dismissable = true, |
| 100 | dismissableBackButton = dismissable, |
| 101 | onDismiss, |
| 102 | visible = false, |
| 103 | style, |
| 104 | theme: themeOverrides, |
| 105 | testID, |
| 106 | }: Props) => { |
| 107 | const { right, left } = useSafeAreaInsets(); |
| 108 | const theme = useInternalTheme(themeOverrides); |
| 109 | const { isV3, dark, mode, colors, roundness } = theme; |
| 110 | const borderRadius = (isV3 ? 7 : 1) * roundness; |
| 111 | |
| 112 | const backgroundColorV2 = |
| 113 | dark && mode === 'adaptive' |
| 114 | ? overlay(DIALOG_ELEVATION, colors?.surface) |
| 115 | : colors?.surface; |
| 116 | const backgroundColor = isV3 |
| 117 | ? theme.colors.elevation.level3 |
| 118 | : backgroundColorV2; |
| 119 | |
| 120 | return ( |
| 121 | <Modal |
| 122 | dismissable={dismissable} |
| 123 | dismissableBackButton={dismissableBackButton} |
| 124 | onDismiss={onDismiss} |
| 125 | visible={visible} |
| 126 | contentContainerStyle={[ |
| 127 | { |
| 128 | borderRadius, |
| 129 | backgroundColor, |
| 130 | marginHorizontal: Math.max(left, right, 26), |
| 131 | }, |
| 132 | styles.container, |
| 133 | style, |
| 134 | ]} |
| 135 | theme={theme} |
| 136 | testID={testID} |
| 137 | > |
| 138 | {React.Children.toArray(children) |
| 139 | .filter((child) => child != null && typeof child !== 'boolean') |
| 140 | .map((child, i) => { |
| 141 | if (isV3) { |
| 142 | if (i === 0 && React.isValidElement<DialogChildProps>(child)) { |
| 143 | return React.cloneElement(child, { |
| 144 | style: [{ marginTop: 24 }, child.props.style], |
| 145 | }); |
| 146 | } |
| 147 | } |
| 148 | |
| 149 | if ( |
| 150 | i === 0 && |
| 151 | React.isValidElement<DialogChildProps>(child) && |
| 152 | child.type === DialogContent |
| 153 | ) { |
| 154 | // Dialog content is the first item, so we add a top padding |
nothing calls this directly
no test coverage detected
searching dependent graphs…