Drawer

A sliding panel that emerges from the edge of the screen to reveal additional content or navigation options..
Installation
API Reference
Important Note
This is the documentation for gluestack-ui v2 (beta). For @gluestack-ui/themed (stable) documentation, refer to gluestack-ui v1.
This is an illustration of Drawer component.
size
anchor
function App() {
const [showDrawer, setShowDrawer] = React.useState(false)
return (
<>
<Button
onPress={() => {
setShowDrawer(true)
}}
>
<ButtonText>Show Drawer</ButtonText>
</Button>
<Drawer
isOpen={showDrawer}
onClose={() => {
setShowDrawer(false)
}}
size="sm"
anchor="left"
>
<DrawerBackdrop />
<DrawerContent>
<DrawerHeader>
<Heading size="3xl">Heading</Heading>
</DrawerHeader>
<DrawerBody>
<Text size="2xl" className="text-typography-800">
This is a sentence.
</Text>
</DrawerBody>
<DrawerFooter>
<Button
onPress={() => {
setShowDrawer(false)
}}
className="flex-1"
>
<ButtonText>Button</ButtonText>
</Button>
</DrawerFooter>
</DrawerContent>
</Drawer>
</>
)
}

Installation

Run the following command:

npx gluestack-ui add drawer

API Reference

To use this component in your project, include the following import statement in your file.
import {
Drawer,
DrawerBackdrop,
DrawerContent,
DrawerHeader,
DrawerCloseButton,
DrawerBody,
DrawerFooter,
} from "@/components/ui/drawer"
anatomy-image
export default () => (
<Drawer>
<DrawerBackdrop />
<DrawerContent>
<DrawerHeader>
<DrawerCloseButton></DrawerCloseButton>
</DrawerHeader>
<DrawerBody />
<DrawerFooter />
</DrawerContent>
</Drawer>
)

Component Props

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

Drawer

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
-
If true, the drawer will open. Useful for controllable state behavior.
onClose
() => any
-
Callback invoked when the drawer is closed.
defaultIsOpen
boolean
-
Specifies the default open state of the Drawer
initialFocusRef
React.RefObject<any>
-
The ref of element to receive focus when the drawer opens.
finalFocusRef
React.RefObject<any>
-
The ref of element to receive focus when the drawer closes
avoidKeyboard
boolean
-
If true, the Drawer will avoid the keyboard.
closeOnOverlayClick
boolean
-
If true, the Drawer will close when the overlay is clicked.
isKeyboardDismissable
boolean
-
If true, the keyboard can dismiss the Drawer
children
any
-
The content to display inside the Drawer

DrawerBackdrop

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.

DrawerContent

It is @legendapp/motion's Motion.View component. You can use any declarative animation library you prefer.
Prop
Type
Default
Description
focusable
boolean
false
If true, Drawer Content will be focusable.

DrawerHeader

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

DrawerCloseButton

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

DrawerBody

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

DrawerFooter

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

Props

Modal 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.
Name
Value
Default
size
xs | sm | md | lg | full
sm
anchor
left | right | top | bottom
left

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.

Filter

function App() {
const [showDrawer, setShowDrawer] = React.useState(false)
const [categories, setCategories] = React.useState([])
const [brands, setBrands] = React.useState([])
const [colors, setColors] = React.useState([])
return (
<>
<Button
onPress={() => {
setShowDrawer(true)
}}
>
<ButtonText>Show Drawer</ButtonText>
</Button>
<Drawer
isOpen={showDrawer}
onClose={() => {
setShowDrawer(false)
}}
>
<DrawerBackdrop />
<DrawerContent className="px-4 py-3 w-[270px] md:w-[300px]">
<DrawerHeader>
<Heading size="md">FILTERS</Heading>
<Button
variant="link"
size="xs"
onPress={() => {
setCategories([])
setBrands([])
setColors([])
}}
>
<ButtonText>Clear All</ButtonText>
</Button>
</DrawerHeader>
<DrawerBody className="gap-4 mt-0 mb-0">
<VStack className="pl-2 py-3">
<Text className="font-semibold" size="sm">
Categories
</Text>
<Divider className="my-1" />
<CheckboxGroup
value={categories}
onChange={(keys) => {
setCategories(keys)
}}
>
<VStack className="gap-3 mt-3 ml-1">
<HStack className="items-center gap-1">
<Checkbox value="tops" size="sm">
<CheckboxIndicator>
<CheckboxIcon as={CheckIcon} />
</CheckboxIndicator>
<CheckboxLabel>Tops</CheckboxLabel>
</Checkbox>
<Text className="text-typography-500" size="xs">
(143,234)
</Text>
</HStack>
<HStack className="items-center gap-1">
<Checkbox value="bottoms" size="sm">
<CheckboxIndicator>
<CheckboxIcon as={CheckIcon} />
</CheckboxIndicator>
<CheckboxLabel>Bottoms</CheckboxLabel>
</Checkbox>
<Text className="text-typography-500" size="xs">
(5,431,234)
</Text>
</HStack>
<HStack className="items-center gap-1">
<Checkbox value="shoes" size="sm">
<CheckboxIndicator>
<CheckboxIcon as={CheckIcon} />
</CheckboxIndicator>
<CheckboxLabel>Shoes</CheckboxLabel>
</Checkbox>
<Text className="text-typography-500" size="xs">
(98,234)
</Text>
</HStack>
<HStack className="items-center gap-1">
<Checkbox value="accessories" size="sm">
<CheckboxIndicator>
<CheckboxIcon as={CheckIcon} />
</CheckboxIndicator>
<CheckboxLabel>Accessories</CheckboxLabel>
</Checkbox>
<Text className="text-typography-500" size="xs">
(91,234)
</Text>
</HStack>
</VStack>
</CheckboxGroup>
</VStack>
<VStack className="pl-2 py-3">
<Text className="font-semibold">Brands</Text>
<Divider className="my-1" />
<CheckboxGroup
value={brands}
onChange={(keys) => {
setBrands(keys)
}}
>
<VStack className="gap-3 mt-3 ml-1">
<HStack className="items-center gap-1">
<Checkbox value="tops" size="sm">
<CheckboxIndicator>
<CheckboxIcon as={CheckIcon} />
</CheckboxIndicator>
<CheckboxLabel>Allen Solly</CheckboxLabel>
</Checkbox>
<Text className="text-typography-500" size="xs">
(1,234)
</Text>
</HStack>
<HStack className="items-center gap-1">
<Checkbox value="bottoms" size="sm">
<CheckboxIndicator>
<CheckboxIcon as={CheckIcon} />
</CheckboxIndicator>
<CheckboxLabel>Adidas</CheckboxLabel>
</Checkbox>
<Text className="text-typography-500" size="xs">
(524)
</Text>
</HStack>
<HStack className="items-center gap-1">
<Checkbox value="shoes" size="sm">
<CheckboxIndicator>
<CheckboxIcon as={CheckIcon} />
</CheckboxIndicator>
<CheckboxLabel>Nike</CheckboxLabel>
</Checkbox>
<Text className="text-typography-500" size="xs">
(931)
</Text>
</HStack>
<HStack className="items-center gap-1">
<Checkbox value="accessories" size="sm">
<CheckboxIndicator>
<CheckboxIcon as={CheckIcon} />
</CheckboxIndicator>
<CheckboxLabel>Marks & Spencer</CheckboxLabel>
</Checkbox>
<Text className="text-typography-500" size="xs">
(1,241)
</Text>
</HStack>
</VStack>
</CheckboxGroup>
</VStack>
<VStack className="pl-2 py-3">
<Text className="font-semibold">Price Range</Text>
<Divider className="my-1" />
<VStack className="pt-6 pr-4 ml-1">
<Slider
defaultValue={2000}
size="sm"
orientation="horizontal"
minValue={0}
maxValue={10000}
>
<SliderTrack>
<SliderFilledTrack />
</SliderTrack>
<SliderThumb />
</Slider>
</VStack>
<HStack className="justify-between pt-2">
<Text size="sm">0</Text>
<Text size="sm">10,000</Text>
</HStack>
</VStack>
<VStack className="pl-2 py-3">
<Text className="font-semibold">Colour</Text>
<Divider className="my-1" />
<CheckboxGroup
//@ts-ignore
value={colors}
onChange={(keys) => {
setColors(keys)
}}
>
<VStack className="gap-3 mt-3 ml-1">
<HStack className="items-center gap-1">
<Checkbox value="tops" size="sm">
<CheckboxIndicator>
<CheckboxIcon as={CheckIcon} />
</CheckboxIndicator>
<CheckboxLabel className="flex flex-row items-center">
<Icon
as={CircleIcon}
className="fill-gray-200 text-gray-200 mr-1"
/>
White
</CheckboxLabel>
</Checkbox>
<Text className="text-typography-500" size="xs">
(23,673)
</Text>
</HStack>
<HStack className="items-center gap-1">
<Checkbox value="bottoms" size="sm">
<CheckboxIndicator>
<CheckboxIcon as={CheckIcon} />
</CheckboxIndicator>
<CheckboxLabel className="flex flex-row items-center">
<Icon
as={CircleIcon}
className="fill-black text-black mr-1"
/>
Black
</CheckboxLabel>
</Checkbox>
<Text className="text-typography-500" size="xs">
(54,657)
</Text>
</HStack>
<HStack className="items-center gap-1">
<Checkbox value="shoes" size="sm">
<CheckboxIndicator>
<CheckboxIcon as={CheckIcon} />
</CheckboxIndicator>
<CheckboxLabel className="flex flex-row items-center">
<Icon
as={CircleIcon}
className="fill-red-500 text-red-500 mr-1"
/>
Red
</CheckboxLabel>
</Checkbox>
<Text className="text-typography-500" size="xs">
(45,678)
</Text>
</HStack>
<HStack className="items-center gap-1">
<Checkbox value="accessories" size="sm">
<CheckboxIndicator>
<CheckboxIcon as={CheckIcon} />
</CheckboxIndicator>
<CheckboxLabel className="flex flex-row items-center">
<Icon
as={CircleIcon}
className="fill-amber-900 text-amber-900 mr-1"
/>
Brown
</CheckboxLabel>
</Checkbox>
<Text className="text-typography-500" size="xs">
(13,672)
</Text>
</HStack>
</VStack>
</CheckboxGroup>
</VStack>
</DrawerBody>
</DrawerContent>
</Drawer>
</>
)
}
function App() {
const [showDrawer, setShowDrawer] = React.useState(false)
return (
<>
<Button
onPress={() => {
setShowDrawer(true)
}}
>
<ButtonText>Show Drawer</ButtonText>
</Button>
<Drawer
isOpen={showDrawer}
onClose={() => {
setShowDrawer(false)
}}
>
<DrawerBackdrop />
<DrawerContent className="w-[270px] md:w-[300px]">
<DrawerHeader className="justify-center flex-col gap-2">
<Avatar size="2xl">
<AvatarFallbackText>User Image</AvatarFallbackText>
<AvatarImage
source={{
uri: "https://images.unsplash.com/photo-1494790108377-be9c29b29330?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=687&q=80",
}}
/>
</Avatar>
<VStack className="justify-center items-center">
<Text size="lg">User Name</Text>
<Text size="sm" className="text-typography-600">
abc@gmail.com
</Text>
</VStack>
</DrawerHeader>
<Divider className="my-4" />
<DrawerBody contentContainerClassName="gap-2">
<Pressable className="gap-3 flex-row items-center hover:bg-background-50 p-2 rounded-md">
{/* User is imported from 'lucide-react-native' */}
<Icon as={User} size="lg" className="text-typography-600" />
<Text>My Profile</Text>
</Pressable>
<Pressable className="gap-3 flex-row items-center hover:bg-background-50 p-2 rounded-md">
{/* Home is imported from 'lucide-react-native' */}
<Icon as={Home} size="lg" className="text-typography-600" />
<Text>Saved Address</Text>
</Pressable>
<Pressable className="gap-3 flex-row items-center hover:bg-background-50 p-2 rounded-md">
{/* ShoppingCart is imported from 'lucide-react-native' */}
<Icon
as={ShoppingCart}
size="lg"
className="text-typography-600"
/>
<Text>Orders</Text>
</Pressable>
<Pressable className="gap-3 flex-row items-center hover:bg-background-50 p-2 rounded-md">
{/* Wallet is imported from 'lucide-react-native' */}
<Icon as={Wallet} size="lg" className="text-typography-600" />
<Text>Saved Cards</Text>
</Pressable>
<Pressable className="gap-3 flex-row items-center hover:bg-background-50 p-2 rounded-md">
<Icon as={StarIcon} size="lg" className="text-typography-600" />
<Text>Review App</Text>
</Pressable>
<Pressable className="gap-3 flex-row items-center hover:bg-background-50 p-2 rounded-md">
<Icon as={PhoneIcon} size="lg" className="text-typography-600" />
<Text>Contact Us</Text>
</Pressable>
</DrawerBody>
<DrawerFooter>
<Button
className="w-full gap-2"
variant="outline"
action="secondary"
>
<ButtonText>Logout</ButtonText>
{/* LogOut is imported from 'lucide-react-native' */}
<ButtonIcon as={LogOut} />
</Button>
</DrawerFooter>
</DrawerContent>
</Drawer>
</>
)
}