GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

No menu could be recovered. Follow the blue links in the page.

This view

  • Original page
  • New address

GeezerVison is showing docs.nativebase.io — Modal | NativeBase | Universal Components for React and React Native

Modal | NativeBase | Universal Components for React and React Native

NativeBase
3.4.x
🎉 Prompt to React Native UI
→
Search
⌘
K
Hire us
NativeBase
Introduction
Getting Started
Installation
Setup NativeBase Provider
Migration
Upgrading to v3
Upgrading to 3.2.0 from 3.x
Upgrading to 3.4.0 from 3.3.x
Components Migration
ActionSheet
Badge
Button
Card
Checkbox
DatePicker
DeckSwiper
Drawer
FABs
FooterTab
Form
Header
Icon
Layout
Picker
Radio Button
Searchbar
Segment
Spinner
SwipeList
Tabs
Thumbnail
Toast
Typography
Resources
Contribution
Creating a Universal App with NativeBase and Solito
Core Concepts
Utility First
Utility Props Specificity
Design Tokens
Pseudo Props: Overview
Pseudo Props: Dos & Don'ts
Internal Pseudo Props
Responsive
Features
Utility Props
Color mode (Dark Mode)
NativeBase Factory
SafeAreaView Props
Strict Mode
Accessibility
Theme
Default Theme
Customizing Theme
Customizing Fonts
Customizing Components
Making components dark mode compatible
Breakpoints
Using Theme
TypeScript
Layout
AspectRatio
Box
Center
Container
Flex
HStack / Row
Stack
VStack / Column
ZStack
Forms
Button
Pressable
Checkbox
FormControl
IconButton
Input
Link
Radio
Select
Slider
Switch
TextArea
Data Display
Badge
Divider
Feedback
Alert
Progress
Skeleton
Spinner
Toast
Typography
Text
Heading
Overlay
AlertDialog
Menu
Modal
Popover
Tooltip
Disclosure
ActionSheet
Media and Icons
Avatar
Icon
Image
Transition
PresenceTransition
Slide
Stagger
Others
Fab
Hidden
ReactNative Components
ScrollView
View
KeyboardAvoidingView
StatusBar
FlatList
SectionList
Hooks
useDisclose
useBreakpointValue
useClipboard
useMediaQuery
useTheme
useToken
useColorMode
useColorModeValue
useContrastText
useAccessibleColors
Examples
Todo-List
Kitchen Sink
Recipes
Designs
AppBar
Card
Drawer Navigation
Tab View
Swipe List
Forms
Form with Validation
Login/Signup Forms
SearchBar
Layout
App Drawer
Footer
More
Changelog
Testing
FAQ's
More Props
If you are starting a new project, please try gluestack-ui for better performance and new design.
Modal
A Modal is an overlay on the primary window or another dialog window. Content behind the modal dialog remains inert and users cannot interact with it.
Show Code
Playground
const Example = () => {
const [showModal, setShowModal] = useState(false);
return <>
<Button shadow={2} onPress={() => setShowModal(true)}>
Button
</Button>
<Modal isOpen={showModal} onClose={() => setShowModal(false)}>
<Modal.Content maxWidth="400px">
<Modal.CloseButton />
<Modal.Header>Contact Us</Modal.Header>
<Modal.Body>
<FormControl>
<FormControl.Label>Name</FormControl.Label>
<Input />
</FormControl>
<FormControl mt="3">
<FormControl.Label>Email</FormControl.Label>
<Input />
</FormControl>
</Modal.Body>
<Modal.Footer>
<Button.Group space={2}>
<Button variant="ghost" colorScheme="blueGray" onPress={() => {
setShowModal(false);
}}>
Cancel
</Button>
<Button onPress={() => {
setShowModal(false);
}}>
Save
</Button>
</Button.Group>
</Modal.Footer>
</Modal.Content>
</Modal>
</>;
};
Import
NativeBase exports a Modal Compound component:
Modal: The wrapper that provides context for its children.
Modal.Content: The container for the modal dialog's content.
Modal.Header: The header that labels the modal dialog.
Modal.Footer: The footer that houses the modal actions.
Modal.Body: The wrapper that houses the modal's main content.
Modal.CloseButton: The button that closes the modal.
Copy
import { Modal } from "native-base";
Examples
Basic
Playground
const Example = () => {
const [showModal, setShowModal] = useState(false);
return <Center>
<Button onPress={() => setShowModal(true)}>Button</Button>
<Modal isOpen={showModal} onClose={() => setShowModal(false)}>
<Modal.Content maxWidth="400px">
<Modal.CloseButton />
<Modal.Header>Contact Us</Modal.Header>
<Modal.Body>
<FormControl>
<FormControl.Label>Name</FormControl.Label>
<Input />
</FormControl>
<FormControl mt="3">
<FormControl.Label>Email</FormControl.Label>
<Input />
</FormControl>
</Modal.Body>
<Modal.Footer>
<Button.Group space={2}>
<Button variant="ghost" colorScheme="blueGray" onPress={() => {
setShowModal(false);
}}>
Cancel
</Button>
<Button onPress={() => {
setShowModal(false);
}}>
Save
</Button>
</Button.Group>
</Modal.Footer>
</Modal.Content>
</Modal>
</Center>;
};
Multiple Modals
Playground
const Example = () => {
const [showModal, setShowModal] = useState(false);
const [showModal2, setShowModal2] = useState(false);
const [showModal3, setShowModal3] = useState(false);
return <Center>
<Button onPress={() => setShowModal(true)}>Button</Button>
<Modal isOpen={showModal} onClose={() => setShowModal(false)} size="lg">
<Modal.Content maxWidth="350">
<Modal.CloseButton />
<Modal.Header>Order</Modal.Header>
<Modal.Body>
<VStack space={3}>
<HStack alignItems="center" justifyContent="space-between">
<Text fontWeight="medium">Sub Total</Text>
<Text color="blueGray.400">$298.77</Text>
</HStack>
<HStack alignItems="center" justifyContent="space-between">
<Text fontWeight="medium">Tax</Text>
<Text color="blueGray.400">$38.84</Text>
</HStack>
<HStack alignItems="center" justifyContent="space-between">
<Text fontWeight="medium">Total Amount</Text>
<Text color="green.500">$337.61</Text>
</HStack>
</VStack>
</Modal.Body>
<Modal.Footer>
<Button flex="1" onPress={() => {
setShowModal2(true);
}}>
Continue
</Button>
</Modal.Footer>
</Modal.Content>
</Modal>
<Modal isOpen={showModal2} onClose={() => setShowModal2(false)} size="lg">
<Modal.Content maxWidth="350">
<Modal.CloseButton />
<Modal.Header>Select Address</Modal.Header>
<Modal.Body>
<Radio.Group defaultValue="address1" name="address" size="sm">
<VStack space={3}>
<Radio alignItems="flex-start" _text={{
mt: "-1",
ml: "2",
fontSize: "sm"
}} value="address1">
4140 Parker Rd. Allentown, New Mexico 31134
</Radio>
<Radio alignItems="flex-start" _text={{
mt: "-1",
ml: "2",
fontSize: "sm"
}} value="address2">
6391 Elign St. Celina, Delaware 10299
</Radio>
</VStack>
</Radio.Group>
</Modal.Body>
<Modal.Footer>
<Button flex="1" onPress={() => {
setShowModal3(true);
}}>
Continue
</Button>
</Modal.Footer>
</Modal.Content>
</Modal>
<Modal isOpen={showModal3} size="lg" onClose={() => setShowModal3(false)}>
<Modal.Content maxWidth="350">
<Modal.CloseButton />
<Modal.Header>Payment Options</Modal.Header>
<Modal.Body>
<Radio.Group name="payment" size="sm">
<VStack space={3}>
<Radio alignItems="flex-start" _text={{
mt: "-1",
ml: "2",
fontSize: "sm"
}} value="payment1">
Cash on delivery
</Radio>
<Radio alignItems="flex-start" _text={{
mt: "-1",
ml: "2",
fontSize: "sm"
}} value="payment2">
Credit/ Debit/ ATM Card
</Radio>
<Radio alignItems="flex-start" _text={{
mt: "-1",
ml: "2",
fontSize: "sm"
}} value="payment3">
UPI
</Radio>
</VStack>
</Radio.Group>
</Modal.Body>
<Modal.Footer>
<Button flex="1" onPress={() => {
setShowModal(false);
setShowModal2(false);
setShowModal3(false);
}}>
Checkout
</Button>
</Modal.Footer>
</Modal.Content>
</Modal>
</Center>;
};
Modal Sizes
You can pass size prop to NativeBase Modal , it can take sm, md, lg, full that maps to 60%, 75%, 90%, 100%, or a string or a numerical width of the Modal.
Playground
// @ts-nocheck
function Example() {
const [modalVisible, setModalVisible] = React.useState(false);
const [size, setSize] = React.useState("md");
const handleSizeClick = newSize => {
setSize(newSize);
setModalVisible(!modalVisible);
};
return <>
<Modal isOpen={modalVisible} onClose={setModalVisible} size={size}>
<Modal.Content maxH="212">
<Modal.CloseButton />
<Modal.Header>Return Policy</Modal.Header>
<Modal.Body>
<ScrollView>
<Text>
Create a 'Return Request' under “My Orders” section of
App/Website. Follow the screens that come up after tapping on
the 'Return’ button. Please make a note of the Return ID that we
generate at the end of the process. Keep the item ready for pick
up or ship it to us basis on the return mode.
</Text>
</ScrollView>
</Modal.Body>
<Modal.Footer>
<Button.Group space={2}>
<Button variant="ghost" colorScheme="blueGray" onPress={() => {
setModalVisible(false);
}}>
Cancel
</Button>
<Button onPress={() => {
setModalVisible(false);
}}>
Save
</Button>
</Button.Group>
</Modal.Footer>
</Modal.Content>
</Modal>
<Center>
<VStack space={4}>
{["xs", "sm", "md", "lg", "xl", "full"].map(size => {
return <Button onPress={() => handleSizeClick(size)} key={size}>{`Open ${size} Modal`}</Button>;
})}
</VStack>
</Center>
</>;
}
intialFocusRef and finalFocusRef Example
Playground
function Example() {
const [modalVisible, setModalVisible] = React.useState(false);
const initialRef = React.useRef(null);
const finalRef = React.useRef(null);
return <>
<Modal isOpen={modalVisible} onClose={() => setModalVisible(false)} initialFocusRef={initialRef} finalFocusRef={finalRef}>
<Modal.Content>
<Modal.CloseButton />
<Modal.Header>Contact Us</Modal.Header>
<Modal.Body>
<FormControl>
<FormControl.Label>Name</FormControl.Label>
<Input ref={initialRef} />
</FormControl>
<FormControl mt="3">
<FormControl.Label>Email</FormControl.Label>
<Input />
</FormControl>
</Modal.Body>
<Modal.Footer>
<Button.Group space={2}>
<Button variant="ghost" colorScheme="blueGray" onPress={() => {
setModalVisible(false);
}}>
Cancel
</Button>
<Button onPress={() => {
setModalVisible(false);
}}>
Save
</Button>
</Button.Group>
</Modal.Footer>
</Modal.Content>
</Modal>
<HStack space="4" justifyContent="center" alignItems="center">
<Button onPress={() => {
setModalVisible(!modalVisible);
}}>
Open Modal
</Button>
<Input w="32" ref={finalRef} placeholder="Enter the OTP" _light={{
placeholderTextColor: "blueGray.700"
}} _dark={{
placeholderTextColor: "blueGray.100"
}} />
</HStack>
</>;
}
Modal with avoidKeyboard
Playground
function Example() {
const [modalVisible, setModalVisible] = React.useState(false);
return <>
<Modal isOpen={modalVisible} onClose={() => setModalVisible(false)} avoidKeyboard justifyContent="flex-end" bottom="4" size="lg">
<Modal.Content>
<Modal.CloseButton />
<Modal.Header>Forgot Password?</Modal.Header>
<Modal.Body>
Enter email address and we'll send a link to reset your password.
<FormControl mt="3">
<FormControl.Label>Email</FormControl.Label>
<Input />
</FormControl>
</Modal.Body>
<Modal.Footer>
<Button flex="1" onPress={() => {
setModalVisible(false);
}}>
Proceed
</Button>
</Modal.Footer>
</Modal.Content>
</Modal>
<VStack space={8} alignItems="center">
<Button w="104" onPress={() => {
setModalVisible(!modalVisible);
}}>
Open Modal
</Button>
<Text textAlign="center">
Open modal and focus on the input element to see the effect.
</Text>
</VStack>
</>;
}
Modal Placement
Playground
//@ts-nocheck
const Example = () => {
const [placement, setPlacement] = useState(undefined);
const [open, setOpen] = useState(false);
const openModal = placement => {
setOpen(true);
setPlacement(placement);
};
return <>
<Stack direction={{
base: "column",
md: "row"
}} space={2}>
<Button onPress={() => openModal("top")}>Top</Button>
<Button onPress={() => openModal("bottom")}>Bottom</Button>
<Button onPress={() => openModal("center")}>Center</Button>
<Button onPress={() => openModal("left")}>Left</Button>
<Button onPress={() => openModal("right")}>Right</Button>
</Stack>
<Modal isOpen={open} onClose={() => setOpen(false)} safeAreaTop={true}>
<Modal.Content maxWidth="350" {...styles[placement]}>
<Modal.CloseButton />
<Modal.Header>Contact Us</Modal.Header>
<Modal.Body>
<FormControl>
<FormControl.Label>Name</FormControl.Label>
<Input />
</FormControl>
<FormControl mt="3">
<FormControl.Label>Email</FormControl.Label>
<Input />
</FormControl>
</Modal.Body>
<Modal.Footer>
<Button.Group space={2}>
<Button variant="ghost" colorScheme="blueGray" onPress={() => {
setOpen(false);
}}>
Cancel
</Button>
<Button onPress={() => {
setOpen(false);
}}>
Save
</Button>
</Button.Group>
</Modal.Footer>
</Modal.Content>
</Modal>
</>;
};
const styles = {
top: {
marginBottom: "auto",
marginTop: 0
},
bottom: {
marginBottom: 0,
marginTop: "auto"
},
left: {
marginLeft: 0,
marginRight: "auto"
},
right: {
marginLeft: "auto",
marginRight: 0
},
center: {}
};
Custom Backdrop Modal
Playground
const Example = () => {
const [showModal, setShowModal] = useState(false);
return <Center>
<Button onPress={() => setShowModal(true)}>Button</Button>
<Modal isOpen={showModal} onClose={() => setShowModal(false)} _backdrop={{
_dark: {
bg: "coolGray.800"
},
bg: "warmGray.50"
}}>
<Modal.Content maxWidth="350" maxH="212">
<Modal.CloseButton />
<Modal.Header>Return Policy</Modal.Header>
<Modal.Body>
Create a 'Return Request' under “My Orders” section of App/Website.
Follow the screens that come up after tapping on the 'Return’
button. Please make a note of the Return ID that we generate at the
end of the process. Keep the item ready for pick up or ship it to us
basis on the return mode.
</Modal.Body>
<Modal.Footer>
<Button.Group space={2}>
<Button variant="ghost" colorScheme="blueGray" onPress={() => {
setShowModal(false);
}}>
Cancel
</Button>
<Button onPress={() => {
setShowModal(false);
}}>
Save
</Button>
</Button.Group>
</Modal.Footer>
</Modal.Content>
</Modal>
</Center>;
};

Tip: If you want a specifically aligned Modal, pass justifyContent and alignItems to Modal.
Accessibility
Uses React Native ARIA
@react-native-aria/focus
which follows the
Dialog Modal WAI-ARIA design pattern
.
Keyboard Interactions
Key
Description
Tab
Moves focus to the next tabbable element inside the dialog. If focus is on the last tabbable element inside the dialog, moves focus to the first tabbable element inside the dialog.
Shift + Tab
Moves focus to the previous tabbable element inside the dialog. If focus is on the first tabbable element inside the dialog, moves focus to the last tabbable element inside the dialog.
Escape
Closes the dialog
Props
Modal
Modal implements
View
,
SafeAreaProps
,
PlatformProps
,
FlexProps
,
LayoutProps
,
ColorProps
,
BorderProps
,
TypographyProps
,
ShadowProps
,
PositionProps
isOpen
If true, the modal will open. Useful for controllable state behavior.
Type: boolean
onClose
Callback invoked when the modal is closed.
Type: any
defaultIsOpen
If true, the modal will be opened by default.
Type: boolean
size
The size of the modal.
Type: ThemeComponentSizeType<"Modal">
initialFocusRef
The ref of element to receive focus when the modal opens.
Type: RefObject<any>
finalFocusRef
The ref of element to receive focus when the modal closes.
Type: RefObject<any>
avoidKeyboard
If true and the keyboard is opened, the modal will move up equvivalent to the keyboard height.
Type: boolean
Default: false
closeOnOverlayClick
If true, the modal will close when the overlay is clicked.
Type: boolean
Default: true
isKeyboardDismissable
If true, the modal will close when Escape key is pressed.
Type: boolean
Default: true
overlayVisible
If true, a backdrop element is visible.
Type: boolean
Default: true
backdropVisible
If true, a backdrop element is visible.
Type: boolean
Default: true
_backdrop
Props applied on Overlay.
Type: any
animationPreset
Sets the animation type.
Type: "slide" | "fade"
Default: "fade"
_backdropFade
Props applied on Overlay Animation.
Type: Partial<IFadeProps>
_fade
Props applied on Child Fade Animation.
Type: Partial<IFadeProps>
_slide
Props applied on Child Slide Animation.
Type: Partial<ISlideProps>
_overlay
Props to be passed to the Overlay used inside of Modal.
Type: IOverlayProps
useRNModal
Type: boolean
Children components
Modal.Header, Modal.Footer and Modal.Body composes the 
Box
 component.
Modal.CloseButton composes the 
Button
.
Styling
NativeBase ships with a default theme for each component. Check out the default theme of the modal
here
.
Info: We can easily extend the modal component theme using extendTheme function as described in the documentation
here
.
Previous
Menu
Next
Popover
Quick Nav
Import
Examples
Basic
Multiple Modals
Modal Sizes
intialFocusRef and finalFocusRef Example
Modal with avoidKeyboard
Modal Placement
Custom Backdrop Modal
Accessibility
Keyboard Interactions
Props
Modal
Children components
Styling
MadeWithNativeBase
gluestack-ui
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.