Skip to main content

Dialog

Included components

  • Dialog: Provides context and state for the dialog.
  • Dialog.Header: Header section. Contains the title of the message and the icon.
  • Dialog.Body: Body section. Contains the description of the message.
  • Dialog.Footer: Footer section. Contains the actions of the dialog.

Import

To add the Dialog component to your project you can import it as follows:

import { Dialog } from '@amalgamaco/embassy-ui';

Example

Dialog Example
import { useState } from 'react';
import { VStack, Text, Box, Button, Dialog, HStack } from '@amalgamaco/embassy-ui';

const Example = () => {
const [ isModalVisible, setIsModalVisible ] = useState( false );

return (
<VStack>
<Box flex={1} justifyContent="center">
<Button
onPress={() => setIsModalVisible( true )}
borderWidth={0} textAlign="center"
>
Dialog Example
</Button>
</Box>

<Dialog
isVisible={isModalVisible}
onClosePress={() => setIsModalVisible( false )}
>
<Dialog.Header title="Header title" />

<Dialog.Body>
<Text variant="body" textAlign="center" fontWeight="medium">
Are you sure you want to leave?
</Text>
<Text variant="body" textAlign="center">
All the changes saved will {'\n'} be discarded
</Text>
</Dialog.Body>

<Dialog.Footer>
<HStack space={8} marginBottom={5} marginTop={5} alignItems="center">
<Button
onPress={() => setIsModalVisible( false )}
variant="secondary"
width={110}
padding={2}
bg="transparent"
>
No
</Button>

<Button
onPress={() => setIsModalVisible( false )}
variant="primary"
width={110}
padding={2}
>
Yes
</Button>
</HStack>
</Dialog.Footer>
</Dialog>
</VStack> )
}

Dialog Props

icon

An icon to show on the header of the Dialog.

TYPEREQUIRED
ReactElement<IIconProps>No
Dialog with custom icon
<Dialog
icon={<Icon name="earth-outline" as={Ionicons} />}
isVisible
>
<Dialog.Header title="Custom icon" />
<Dialog.Footer />
</Dialog>

variant

The variant style to use. You can add more variants extending the theme configuration for this component.

The available variants are:

  • low-priority
  • high-priority
Dialog - Low Priority
Dialog - High Priority
<Dialog variant="low-priority">
<Dialog.Header title="Dialog Low Priority" />
<Dialog.Footer />
</Dialog>

<Dialog variant="high-priority">
<Dialog.Header title="Dialog High Priority" />
<Dialog.Footer />
</Dialog>

onClosePress

A callback that is called when the dialog's close icon is pressed.

TYPEREQUIRED
(): voidNo
info

The delete icon is only shown when this prop is not undefined nor null.

Dialog Example
<Dialog onClosePress={() => alert("On close pressed")}>
<Dialog.Header title="Header title" />
</Dialog>

closeIcon

The icon used as the delete icon.

TYPEREQUIRED
ReactElement<IIconProps>No
info

Remember that the close icon is only shown when the onClosePress prop is not undefined nor null.

Dialog with custom close icon
<Dialog closeIcon={<Icon name="trash-outline" as={Ionicons} />}>
<Dialog.Header title="Custom close icon" />
</Dialog>

isVisible

If the dialog is visible or not.

TYPEREQUIREDDEFAULT
BooleanNotrue
<Dialog isVisible={true}>
<Dialog.Header title="Header title" />
</Dialog>

<Dialog isVisible={false}>
<Dialog.Header title="Header title" />
</Dialog>

withIcon

If the icon is visible or not.

TYPEREQUIREDDEFAULT
BooleanNotrue
Dialog with icon
<Dialog withIcon={true}>
<Dialog.Header title="Dialog with icon" />
</Dialog>
Dialog without icon

<Dialog withIcon={false}>
<Dialog.Header title="Dialog without icon" />
</Dialog>
info

The icon is only shown when the variant prop is a valid variant or when an icon prop is provided and this prop is not false.

react-native-modal

Under the hood the Dialog component use react-native-modal library. So, you can use all the props that react-native-modal allows. You can find all the props here.

Available react-native-modal props

NameTypeDefaultDescription
animationInstring or object"slideInUp"Modal show animation
animationInTimingnumber300Timing for the modal show animation (in ms)
animationOutstring or object"slideOutDown"Modal hide animation
animationOutTimingnumber300Timing for the modal hide animation (in ms)
avoidKeyboardboolfalseMove the modal up if the keyboard is open
coverScreenbooltrueWill use RN Modal component to cover the entire screen wherever the modal is mounted in the component hierarchy
hasBackdropbooltrueRender the backdrop
backdropColorstring"black"The backdrop background color
backdropOpacitynumber0.70The backdrop opacity when the modal is visible
backdropTransitionInTimingnumber300The backdrop show timing (in ms)
backdropTransitionOutTimingnumber300The backdrop hide timing (in ms)
customBackdropnodenullThe custom backdrop element
deviceHeightnumbernullDevice height (useful on devices that can hide the navigation bar)
deviceWidthnumbernullDevice width (useful on devices that can hide the navigation bar)
onBackButtonPressfunc() => nullCalled when the Android back button is pressed
onBackdropPressfunc() => nullCalled when the backdrop is pressed
onModalWillHidefunc() => nullCalled before the modal hide animation begins
onModalHidefunc() => nullCalled when the modal is completely hidden
onModalWillShowfunc() => nullCalled before the modal show animation begins
onModalShowfunc() => nullCalled when the modal is completely visible
onSwipeStartfunc() => nullCalled when the swipe action started
onSwipeMovefunc(percentageShown) => nullCalled on each swipe event
onSwipeCompletefunc({ swipingDirection }) => nullCalled when the swipeThreshold has been reached
onSwipeCancelfunc() => nullCalled when the swipeThreshold has not been reached
panResponderThresholdnumber4The threshold for when the panResponder should pick up swipe events
scrollOffsetnumber0When > 0, disables swipe-to-close, in order to implement scrollable content
scrollOffsetMaxnumber0Used to implement overscroll feel when content is scrollable. See /example directory
scrollTofuncnullUsed to implement scrollable modal. See /example directory for reference on how to use it
scrollHorizontalboolfalseSet to true if your scrollView is horizontal (for a correct scroll handling)
swipeThresholdnumber100Swiping threshold that when reached calls onSwipeComplete
swipeDirectionstring or arraynullDefines the direction where the modal can be swiped. Can be 'up', 'down', 'left, or 'right', or a combination of them like ['up','down']
useNativeDriverboolfalseDefines if animations should use native driver
useNativeDriverForBackdropboolnullDefines if animations for backdrop should use native driver (to avoid flashing on android)
hideModalContentWhileAnimatingboolfalseEnhances the performance by hiding the modal content until the animations complete
propagateSwipebool or funcfalseAllows swipe events to propagate to children components (eg a ScrollView inside a modal)

Dialog.Header Props

title

The title text to show on the Header Section.

TYPEREQUIRED
stringNo

<Dialog>
<Dialog.Header title="Header title" />
</Dialog>

Dialog Pseudo Props

__title

Props to be applied to the internal text component showing the label text.

TYPEREQUIRED
ITextPropsNo

__header

Props to be applied to the internal box component that contains the header section.

TYPEREQUIRED
IBoxPropsNo

__body

Props to be applied to the internal box component that contains the body section.

TYPEREQUIRED
IBoxPropsNo

Props to be applied to the internal box component that contains the footer section.

TYPEREQUIRED
IBoxPropsNo

__closeButtonContainer

Props to be applied to the internal box component that contains the close button icon.

TYPEREQUIRED
IBoxPropsNo

__icon

Props to be applied to the internal icon component.

TYPEREQUIRED
IIconPropsNo

__closeIcon

Props to be applied to the internal close icon component.

TYPEREQUIRED
IIconPropsNo

Fully customizable example

Dialog Example

<Dialog
isVisible
variant="high-priority"
icon={<Icon name="circle" as={UIKitIcon} />}
closeIcon={<Icon name="alert-triangle" as={UIKitIcon} />}
backdropOpacity={0.5}
animationInTiming={1000}
animationIn="swing"
bg="primary.300"
__icon={{ size: '2xl' }}
__closeIcon={{ color: 'white' }}
__title={{ color: 'error.900' }}
>
<Dialog.Header title="Dialog fully customizable" />

<Dialog.Body>
<Text variant="body" textAlign="center" color="white" fontWeight="bold">
Are you sure you want to leave?
</Text>
<Text variant="body" textAlign="center" color="white">
All the changes saved will {'\n'} be discarded
</Text>
</Dialog.Body>

<Dialog.Footer>
<HStack space={8} marginBottom={5} marginTop={5} alignItems="center">

<Button
variant="secondary"
onPress={() => setIsModalVisible( false )}
width={110}
bg="transparent"
padding={4}
__label={{ color: 'white' }}
borderColor="white"
>
No
</Button>

<Button
variant="priority"
onPress={() => setIsModalVisible( false )}
width={110}
padding={4}
>
Yes
</Button>
</HStack>
</Dialog.Footer>
</Dialog>

Available animations

Take a look at react-native-animatable to see the dozens of animations available out-of-the-box. You can also pass in custom animation definitions and have them automatically register with react-native-animatable. For more information on creating custom animations, see the react-native-animatable animation definition schema.