React Native · Components
Dialog
A modal window that opens on top of the screen.
Live example
The preview runs in the browser with the web component; the native component takes the same props and looks the same on iOS and Android.
Preview
Code
Events
- Events appear here when you interact with the preview.
confirm(): a confirmation question in one line
Custom footer: the footer function receives close
Import
Dialog
componentA modal window that opens on top of the screen. Same API as Dialog on web: the title, description, icon, body and buttons are given as props; while an onConfirm returning a Promise runs, the confirm button shows loading and the window does not close.
- Phone: Opens as a sheet sliding up from the bottom (
mobileSheet); closes by pulling down, tapping the backdrop and the Android back button. When the keyboard opens it moves above the keyboard and respects the bottom inset of notched screens. - Tablet: Opens centered.
- Look and animations are the same on iOS and Android: not RN's
Modalbut the library's own layer is used (seeUIProvider).
Do not write a component just for an "Are you sure?" question; use confirm.
Examples
confirm
functionAsks the user a confirmation question and waits for the answer. Returns true if confirmed, false if dismissed (Cancel, backdrop, pull down, back button). Same as confirm on web.
The window has all of Dialog's behavior (a bottom sheet on a phone, closing with the back button…). When called several times at once the questions are shown in order. It can also be called from outside components (services, stores).
It needs a UIProvider at the root of the app; without one it falls back to the platform's own alert (Alert).
Examples
ConfirmOptions
interfaceOptions of the confirm function (same as web).
| Name | Type | Default | Description |
|---|---|---|---|
title | ReactNode | The question; becomes the window title. | |
description? | ReactNode | Description below the question (e.g. "This cannot be undone."). | |
icon? | IconProp | Icon next to the title: a name or an element. | |
confirmLabel? | ReactNode | "Onayla" | Confirm button text. |
cancelLabel? | ReactNode | "İptal" | Cancel button text. |
tone? | Tone | "primary" | Confirm button color. "danger" for actions like deleting. |
onConfirm? | () => unknown | Runs on confirm, before the window closes. If it returns a Promise the confirm button shows loading until it finishes; if it returns false or throws, the window stays open. |
DialogSize
typeMaximum width of the dialog window (same as web).
DialogProps
interfaceProps of the Dialog component.
| Name | Type | Default | Description |
|---|---|---|---|
size? | DialogSize | "md" | Maximum width of the window: sm 384, md 512, lg 672, xl 896 pixels. When it opens as a bottom sheet on a phone it is always full width. |
mobileSheet? | boolean | true | Turn into a sheet sliding up from the bottom on narrow screens (below 640 pixels, i.e. phones)? With false it opens centered on every screen. |
open? | boolean | Whether it is open in controlled use. | |
defaultOpen? | boolean | false | Open initially in uncontrolled use? |
onOpenChange? | (open: boolean) => void | Called with the new state when it opens or closes. | |
trigger? | ReactElement | Element that opens the window, usually a Button. Pressing it opens the window. | |
title | ReactNode | Title. Screen readers announce the window by this name; so it is required. | |
description? | ReactNode | Description below the title. | |
icon? | IconProp | Icon next to the title: a name or an element. | |
children? | ModalSlot | Body. When a function, it receives { close, pending }. | |
onConfirm? | () => unknown | Called when the confirm button is pressed (unlike web there is no form, so no FormData is passed; read field values from your own state). - If it returns a Promise, the confirm button shows loading until it finishes and the window does not close (the backdrop, dragging and the back button wait too). - If it returns false or throws, the window stays open. - Otherwise the window closes. | |
confirmLabel? | ReactNode | Confirm button text. "Onayla" when onConfirm is given and this is not. | |
cancelLabel? | ReactNode | "İptal" | Cancel button text. With null the button is not shown. |
tone? | Tone | "primary" | Confirm button color. "danger" for actions like deleting. |
footer? | ModalSlot | Footer instead of the built-in buttons. When a function, it receives { close, pending }; null draws nothing. | |
showCloseButton? | boolean | true | Close (×) button in the top right corner. |
closeOnBackdropClick? | boolean | true | Close when the backdrop is tapped? |
closeOnBackButton? | boolean | true | Should the Android back button (and back gesture) close the window? |
swipeToClose? | boolean | true | Closing by swiping with a finger. |
stickyHeader? | boolean | true | Keep the header fixed in place? With false it scrolls with the body. |
stickyFooter? | boolean | true | Keep the footer (buttons) fixed in place? |
style? | ViewStyle | Style of the window itself. | |
testID? | string | Test id (the window surface). |
ModalRenderContext
interfaceValues received when children and footer are given as functions; so the window can be closed without writing a nested component.
| Name | Type | Description |
|---|---|---|
close | () => void | Closes the window. |
pending | boolean | Whether the confirm (onConfirm) is in progress. |
ModalSlot
typeContent that can be given as children or footer.
ModalOwnProps
interfaceCommon props of Dialog and Sheet (ModalOwnProps on web).
| Name | Type | Default | Description |
|---|---|---|---|
open? | boolean | Whether it is open in controlled use. | |
defaultOpen? | boolean | false | Open initially in uncontrolled use? |
onOpenChange? | (open: boolean) => void | Called with the new state when it opens or closes. | |
trigger? | ReactElement | Element that opens the window, usually a Button. Pressing it opens the window. | |
title | ReactNode | Title. Screen readers announce the window by this name; so it is required. | |
description? | ReactNode | Description below the title. | |
icon? | IconProp | Icon next to the title: a name or an element. | |
children? | ModalSlot | Body. When a function, it receives { close, pending }. | |
onConfirm? | () => unknown | Called when the confirm button is pressed (unlike web there is no form, so no FormData is passed; read field values from your own state). - If it returns a Promise, the confirm button shows loading until it finishes and the window does not close (the backdrop, dragging and the back button wait too). - If it returns false or throws, the window stays open. - Otherwise the window closes. | |
confirmLabel? | ReactNode | Confirm button text. "Onayla" when onConfirm is given and this is not. | |
cancelLabel? | ReactNode | "İptal" | Cancel button text. With null the button is not shown. |
tone? | Tone | "primary" | Confirm button color. "danger" for actions like deleting. |
footer? | ModalSlot | Footer instead of the built-in buttons. When a function, it receives { close, pending }; null draws nothing. | |
showCloseButton? | boolean | true | Close (×) button in the top right corner. |
closeOnBackdropClick? | boolean | true | Close when the backdrop is tapped? |
closeOnBackButton? | boolean | true | Should the Android back button (and back gesture) close the window? |
swipeToClose? | boolean | true | Closing by swiping with a finger. |
stickyHeader? | boolean | true | Keep the header fixed in place? With false it scrolls with the body. |
stickyFooter? | boolean | true | Keep the footer (buttons) fixed in place? |
style? | ViewStyle | Style of the window itself. | |
testID? | string | Test id (the window surface). |