Looking for documentation on gluestack-ui v2 with NativeWind? Refer to this link.
This is an illustration of a Themed AlertDialog component with default configuration.
function Example() {
const [showAlertDialog, setShowAlertDialog] = React.useState(false)
return (
<Center h={300}>
<Button onPress={() => setShowAlertDialog(true)}>
<ButtonText>Click me</ButtonText>
</Button>
<AlertDialog
isOpen={showAlertDialog}
onClose={() => {
setShowAlertDialog(false)
}}
>
<AlertDialogBackdrop />
<AlertDialogContent>
<AlertDialogHeader>
<Heading size="lg">Deactivate account</Heading>
<AlertDialogCloseButton>
<Icon as={CloseIcon} />
</AlertDialogCloseButton>
</AlertDialogHeader>
<AlertDialogBody>
<Text size="sm">
Are you sure you want to deactivate your account? Your data will
be permanently removed and cannot be undone.
</Text>
</AlertDialogBody>
<AlertDialogFooter>
<ButtonGroup space="lg">
<Button
variant="outline"
action="secondary"
onPress={() => {
setShowAlertDialog(false)
}}
>
<ButtonText>Cancel</ButtonText>
</Button>
<Button
bg="$error600"
action="negative"
onPress={() => {
setShowAlertDialog(false)
}}
>
<ButtonText>Deactivate</ButtonText>
</Button>
</ButtonGroup>
</AlertDialogFooter>
</AlertDialogContent>
</AlertDialog>
</Center>
)
}

API Reference

Import

To use this component in your project, include the following import statement in your file.
import {
AlertDialog,
AlertDialogBackdrop,
AlertDialogContent,
AlertDialogHeader,
AlertDialogCloseButton,
AlertDialogFooter,
AlertDialogBody,
} from "@gluestack-ui/themed"

Anatomy

The structure provided below can help you identify and understand a AlertDialog component's various parts.
export default () => (
<AlertDialog>
<AlertDialogBackdrop />
<AlertDialogContent>
<AlertDialogHeader>
<AlertDialogCloseButton />
</AlertDialogHeader>
<AlertDialogBody />
<AlertDialogFooter />
</AlertDialogContent>
</AlertDialog>
)

Component Props

This section provides a comprehensive reference list for the component props, detailing descriptions, properties, types, and default behavior for easy project integration.

AlertDialog

Contains all View related layout style props and actions. It inherits all the properties of React Native's View component.
Prop
Type
Default
Description
isOpen
boolean
false
If true, the alert-dialog will open. Useful for controllable state behavior.
onClose
() => any
-
Callback invoked when the alert-dialog is closed.
useRNModal
boolean
false
If true, renders react-native native modal. (Only works in react-native)
defaultIsOpen
boolean
false
Specifies the default open state of the AlertDialog
initialFocusRef
React.RefObject<any>
-
The ref of element to receive focus when the alert-dialog opens.
finalFocusRef
React.RefObject<any>
-
The ref of element to receive focus when the alert-dialog closes.
avoidKeyboard
boolean
-
If true, the AlertDialog will avoid the keyboard.
closeOnOverlayClick
boolean
true
If true, the AlertDialog will close when the overlay is clicked.
isKeyboardDismissable
boolean
true
If true, the keyboard can dismiss the AlertDialog
animationPreset
slide | fade
slide
Specifies the animation preset for the AlertDialog
Descendants Styling Props Props to style child components.
Sx Prop
Description
_content
Prop to style AlertDialogContent Component

AlertDialogBackdrop

It is React Native's Pressable component, created using @legendapp/motion's createMotionAnimatedComponent function to add animation to the component. You can use any declarative animation library you prefer.

AlertDialogContent

It is @legendapp/motion's Motion.View component. You can use any declarative animation library you prefer.

AlertDialogCloseButton

It inherits all the properties of React Native's Pressable component.
Descendants Styling Props Props to style child components.
Sx Prop
Description
_text
Prop to style AlertDialogCloseButton Text Component
_icon
Prop to style AlertDialogCloseButton Icon Component

AlertDialogHeader

It inherits all the properties of React Native's View component.

AlertDialogBody

It inherits all the properties of React Native's View component.

AlertDialogFooter

It inherits all the properties of React Native's View component.

Accessibility

We have outlined the various features that ensure the AlertDialog component is accessible to all users, including those with disabilities. These features help ensure that your application is inclusive and meets accessibility standards.It uses React Native ARIA @react-native-aria/focus which follows the WAI-ARIA Alert and Message Dialogs Pattern.

Themed

The themed version of the component is a pre-styled version of the component, which allows you to quickly integrate the component into your project. The component's design and functionality are fully defined, allowing you to focus on the more important aspects of your project. To know more about Themed Library please visit this link.

Props

AlertDialog component is created using View component from react-native. It extends all the props supported by React Native View, utility props and the props mentioned below.

AlertDialog

Name
Value
Default
size
xs | sm | md | lg | full
md
Note: These props are exclusively applicable when utilizing the default configuration of gluestack-ui/config. If you are using a custom theme, these props may not be available.

Examples

The Examples section provides visual representations of the different variants of the component, allowing you to quickly and easily determine which one best fits your needs. Simply copy the code and integrate it into your project.

AlertDialog with semantic icon

An example of an AlertDialog component incorporating an icon component for visually representing important information or actions.
function App() {
const [showAlertDialog, setShowAlertDialog] = React.useState(false)
return (
<>
<Center h={300}>
<Button onPress={() => setShowAlertDialog(true)}>
<ButtonText>Click me</ButtonText>
</Button>
</Center>
<AlertDialog
isOpen={showAlertDialog}
onClose={() => {
setShowAlertDialog(false)
}}
>
<AlertDialogBackdrop />
<AlertDialogContent>
<AlertDialogHeader borderBottomWidth="$0">
<HStack space="sm" alignItems="center">
<Icon
as={CheckCircleIcon}
color="$success700"
$dark-color="$success300"
/>
<Heading size="lg">Order placed</Heading>
</HStack>
</AlertDialogHeader>
<AlertDialogBody>
<Text size="sm">
Congratulations, your order has been placed! You will receive a
confirmation email shortly. Thank you for shopping with us.
</Text>
</AlertDialogBody>
<AlertDialogFooter borderTopWidth="$0">
<Button
variant="outline"
size="sm"
action="secondary"
mr="$3"
onPress={() => {
setShowAlertDialog(false)
}}
>
<ButtonText>Okay</ButtonText>
</Button>
</AlertDialogFooter>
</AlertDialogContent>
</AlertDialog>
</>
)
}

AlertDialog Sizes

An AlertDialog component with adjustable sizes, providing flexible and visually appealing pop-up notifications and interactive prompts to users.
size
function App() {
const [showAlertDialog, setShowAlertDialog] = React.useState(false)
return (
<>
<Center h={300}>
<Button onPress={() => setShowAlertDialog(true)}>
<ButtonText>Click me</ButtonText>
</Button>
</Center>
<AlertDialog
isOpen={showAlertDialog}
onClose={() => {
setShowAlertDialog(false)
}}
size="md"
>
<AlertDialogBackdrop />
<AlertDialogContent>
<AlertDialogHeader borderBottomWidth="$0">
<HStack space="sm" alignItems="center">
<Icon as={AlertTriangleIcon} color="$error700" />
<Heading size="lg">Order placed</Heading>
</HStack>
</AlertDialogHeader>
<AlertDialogBody>
<Text>
You have exceeded your monthly upload limit. Please upgrade to a
premium account to continue uploading.
</Text>
</AlertDialogBody>
<AlertDialogFooter borderTopWidth="$0">
<ButtonGroup space="lg">
<Button
variant="outline"
action="secondary"
onPress={() => {
setShowAlertDialog(false)
}}
>
<ButtonText fontSizes="$md">Close</ButtonText>
</Button>
<Button
action="primary"
onPress={() => {
setShowAlertDialog(false)
}}
bgColor="$darkBlue700"
>
<ButtonText>View plans</ButtonText>
</Button>
</ButtonGroup>
</AlertDialogFooter>
</AlertDialogContent>
</AlertDialog>
</>
)
}

Unstyled

All the components in gluestack-ui are unstyled by default. To customize your UI using the extendedTheme, please refer to this link. The import names of components serve as keys to customize each component.

Spec Doc

Explore the comprehensive details of the AlertDialog in this document, including its implementation details, checklist, and potential future additions. Dive into the thought process behind the component and gain insights into its development journey.