Skip to main content

Modal pop-up component

1. Content at the bottom

<Modal visible={visible} onClose={() => setVisible(false)}>
<Box height={120} backgroundColor="primary200">
<Text variant="h2">I am the content</Text>
</Box>
</Modal>

2. Content in the middle

<Modal visible={visible} onClose={() => setVisible(false)} position="center">
<Box height={120} backgroundColor="warningColor">
<Text variant="h3">I am the content</Text>
</Box>
</Modal>

3. Content full screen

<Modal
visible={visible}
onClose={() => setVisible(false)}
position="fullscreen"
bodyContainerStyle={{ backgroundColor: "gold" }}
>
<Box height={300} backgroundColor="warningColor">
<Text variant="h2">I am a content</Text>
</Box>
<Button title="closure" onPress={() => setVisible(false)} />
</Modal>

4. Clicking on the mask layer does not allow closing

<Modal
visible={visible}
onClose={() => setVisible(false)}
position="fullscreen"
bodyContainerStyle={{ backgroundColor: "gold" }}
>
<Box height={300} backgroundColor="warningColor">
<Text variant="h3">I am the content</Text>
</Box>
<Button title="Close" onPress={() => setVisible(false)} />
</Modal>

API

PropertiesRequiredDescriptionTypeDefault Value
visibletrueWhether to display the pop-up windowboolean
onClosetrueClose pop-up window event() => void
maskClosablefalseWhether the mask layer allows clicking to close the pop-up windowbooleantrue
maskVisiblefalseWhether to display the maskbooleantrue
positionfalseContent display positionbottom | center | fullscreenbottom
bodyContainerStylefalsePop-up content container styleViewStyle
durationfalsePop-up window display/close duration (ms)number100
animationTypefalsePop-up animationnone|fade|slide-up|slide-downslide-up
onAnimationEndfalseExecuted after the pop-up animation ends(visible: boolean) => void
onRequestClosefalseTriggered when the user presses the back button on an Android device() => void

Modal.alert

Effect demonstration

const handlePress = () => {
Modal.alert({
title: "I am a pop-up window",
content: "I am the content",
});
};
return (
<Container>
<Button title="pop-up window" onPress={handlePress} />
</Container>
);

API

PropertiesRequiredDescriptionTypeDefault Value
iconfalsewarning iconReactNode
titletruetitlestring
contentfalsecontentReactNode
onPressfalseClick callback event() => void
confirmTexttruebutton textstringOK

Modal.confirm

Effect demonstration

const handlePress = () => {
Modal.confirm({
title: "I am a pop-up window",
content: "I am the content",
});
};
return (
<Container>
<Button title="pop-up window" onPress={handlePress} />
</Container>
);

API

PropertiesRequiredDescriptionTypeDefault Value
iconfalsewarning iconReactNode
titletruetitlestring
contentfalsecontentReactNode
onOkfalseConfirm event() => void | Promise<void>
onCancelfalseCancel event() => void | Promise<void>
okTextfalseConfirmation textstringOK
cancelTextfalseCancel textstringCancel

Modal.prompt

Effect demonstration

const [value, setValue] = useState<string>();
const handlePress = () => {
Modal.prompt({
title: "I am a pop-up window",
content: "I am the content",
input: <Input placeholder="Please enter" />,
onOk: setValue,
onCancel: () => console.log(123),
});
};
return (
<Container>
<Button title="pop-up window" onPress={handlePress} />
<WhiteSpace />
<Text>What you entered is: {value}</Text>
</Container>
);

API

PropertiesRequiredDescriptionTypeDefault Value
titletruetitlestring
contentfalsecontentReactNode
onOkfalseConfirm event(value: string) => void | Promise<void>
onCancelfalseCancel event() => void | Promise<void>
okTextfalseConfirmation textstringOK
cancelTextfalseCancel textstringCancel
inputfalseCustom input box componentReactElement

Modal.tip

Effect demonstration

const handlePress = () => {
Modal.tip({
img: require("../../assets/images/island.jpg"),
height: 400,
title: "I am a pop-up window",
content: "I am the content",
});
};
return (
<Container>
<Button title="pop-up window" onPress={handlePress} />
</Container>
);

API

PropertiesRequiredDescriptionTypeDefault Value
titletruetitlestring
contentfalsecontentReactNode
imgtruebackground imageImageSourcePropType
heighttrueheightnumber
closeIconActiveOpacityfalseTurn off the opacity of the iconnumber0.6