Looking for documentation on gluestack-ui with NativeWind (alpha) version? Refer to this link.
This is an illustration of a Themed Actionsheet component with default configuration.
function App() {
const [showActionsheet, setShowActionsheet] = React.useState(false)
const handleClose = () => setShowActionsheet(!showActionsheet)
return (
<Box>
<Button onPress={handleClose}>
<ButtonText>Open</ButtonText>
</Button>
<Actionsheet isOpen={showActionsheet} onClose={handleClose} zIndex={999}>
<ActionsheetBackdrop />
<ActionsheetContent h="$72" zIndex={999}>
<ActionsheetDragIndicatorWrapper>
<ActionsheetDragIndicator />
</ActionsheetDragIndicatorWrapper>
<ActionsheetItem onPress={handleClose}>
<ActionsheetItemText>Delete</ActionsheetItemText>
</ActionsheetItem>
<ActionsheetItem onPress={handleClose}>
<ActionsheetItemText>Share</ActionsheetItemText>
</ActionsheetItem>
<ActionsheetItem onPress={handleClose}>
<ActionsheetItemText>Play</ActionsheetItemText>
</ActionsheetItem>
<ActionsheetItem onPress={handleClose}>
<ActionsheetItemText>Favourite</ActionsheetItemText>
</ActionsheetItem>
<ActionsheetItem onPress={handleClose}>
<ActionsheetItemText>Cancel</ActionsheetItemText>
</ActionsheetItem>
</ActionsheetContent>
</Actionsheet>
</Box>
)
}

API Reference

Import

To use this component in your project, include the following import statement in your file.
import { Actionsheet } from '@gluestack-ui/themed';

Anatomy

The structure provided below can help you identify and understand a actionsheet component's various parts.
export default () => (
<Actionsheet>
<ActionsheetBackdrop />
<ActionsheetContent>
<ActionsheetDragIndicatorWrapper>
<ActionsheetDragIndicator />
</ActionsheetDragIndicatorWrapper>
<ActionsheetItem>
<ActionsheetItemText />
</ActionsheetItem>
</ActionsheetContent>
</Actionsheet>
)

Component Props

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

Actionsheet

It inherits all the properties of React Native's View component.
Prop
Type
Default
Description
isOpen
boolean
-
If true, the Actionsheet will open. Useful for controllable state behavior.
onClose
() => any
-
Callback invoked when the Actionsheet is closed.
onOpen
() => any
-
Callback invoked when the Actionsheet is opened.
useRNModal
boolean
false
If true, renders react-native native modal.
defaultIsOpen
boolean
-
Specifies the default open state of the Actionsheet
initialFocusRef
React.RefObject<any>
-
The ref of element to receive focus when the Actionsheet opens.
finalFocusRef
React.RefObject<any>
-
The ref of element to receive focus when the Actionsheet closes
closeOnOverlayClick
boolean
-
If true, the Actionsheet will close when the overlay is clicked.
isKeyboardDismissable
boolean
-
If true, the keyboard can dismiss the Actionsheet
trapFocus
boolean
true
If true, creates a focus scope containing all elements within the Actionsheet content.
children
any
-
The content to display inside the Actionsheet
snapPoints
Array<number>
[50]
The snap points for the Actionsheet The Actionsheet will snap to the point closest to its current position. The default value is 50% of the screen height. The value should be between 0 and 100. Currently, only one snap point is supported. We plan to support multiple snap points in the future.

ActionsheetBackdrop

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.

ActionsheetContent

It inherits all the properties of @legendapp/motion's Motion.View component. With this Actionsheet component, you have the flexibility to use any declarative animation library that suits your needs.
Descendants Styling Props Props to style child components.
Sx Prop
Description
_sectionHeaderText
Prop to style ActionsheetSectionHeaderText Component

ActionsheetDragIndicatorWrapper

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

ActionsheetDragIndicator

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

ActionsheetItem

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 ActionsheetItemText Component
_icon
Prop to style ActionsheetIcon Component

ActionsheetItemText

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

ActionsheetIcon

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

ActionsheetScrollView

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

ActionsheetVirtualizedList

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

ActionsheetFlatList

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

ActionsheetSectionList

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

ActionsheetSectionHeaderText

It inherits all the properties of React Native's Text component.
Note: While our Actionsheet component supports both ActionsheetScrollView and ActionsheetVirtualizedList, we recommend using VirtualizedList for better performance on large lists of items. The ScrollView option may cause performance issues on lists with many items.

Features

  • Actionsheet has aria-modal set to true.
  • Actionsheet has role set to dialog.
  • When the Actionsheet opens, focus is trapped within it.
  • Pressing Esc closes the Actionsheet
  • Clicking on the overlay closes the Actionsheet
  • Scrolling is blocked on the elements behind the Actionsheet

Accessibility

We have outlined the various features that ensure the Actionsheet component is accessible to all users, including those with disabilities. These features help ensure that your application is inclusive and meets accessibility standards.

Keyboard

  • Tab + Enter: Triggers the actionsheet action.

Screen Reader

  • VoiceOver: When the actionsheet is focused, the screen reader will announce the button group .

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.

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.

Keyboard handling

Demonstrates a common UI pattern known as keyboard handling or keyboard scrolling, in which an input field is automatically scrolled into view when the user taps on it and the keyboard appears. This improves usability and ensures that the input field is always visible and accessible, even when the keyboard is blocking part of the screen.
Without SnapPoints
function App() {
const [showActionsheet, setShowActionsheet] = React.useState(false)
const handleClose = () => setShowActionsheet(!showActionsheet)
return (
<>
<Button onPress={handleClose}>
<ButtonText>Open</ButtonText>
</Button>
<KeyboardAvoidingView
behavior={Platform.OS === "ios" ? "padding" : undefined}
>
<Actionsheet isOpen={showActionsheet} onClose={handleClose}>
<ActionsheetBackdrop />
<ActionsheetContent maxHeight="75%">
<ActionsheetDragIndicatorWrapper>
<ActionsheetDragIndicator />
</ActionsheetDragIndicatorWrapper>
<VStack w="$full" p={20}>
<HStack justifyContent="center" alignItems="center" space="md">
<Box
w={50}
h="$full"
px="$2"
borderWidth={1}
borderStyle="solid"
borderColor="$borderLight300"
rounded="$sm"
>
<Image
source={{ uri: "https://i.imgur.com/UwTLr26.png" }}
flex={1}
resizeMode="contain"
/>
</Box>
<VStack flex={1}>
<Text fontWeight="$bold">Mastercard</Text>
<Text>Card ending in 2345</Text>
</VStack>
</HStack>
<FormControl mt={36}>
<FormControlLabel>
<FormControlLabelText>
Confirm security code
</FormControlLabelText>
</FormControlLabel>
<Input w="$full">
<InputSlot>
<InputIcon as={LeadingIcon} ml="$2" />
</InputSlot>
<InputField placeholder="CVC/CVV" />
</Input>
<Button onPress={handleClose} mt={20}>
<ButtonText>Pay $1000</ButtonText>
</Button>
</FormControl>
</VStack>
</ActionsheetContent>
</Actionsheet>
</KeyboardAvoidingView>
</>
)
}
With SnapPoints
function App() {
const [showActionsheet, setShowActionsheet] = React.useState(false)
const handleClose = () => setShowActionsheet(!showActionsheet)
return (
<>
<Button onPress={handleClose}>
<ButtonText>Open</ButtonText>
</Button>
<Actionsheet
isOpen={showActionsheet}
onClose={handleClose}
snapPoints={[50]}
>
<KeyboardAvoidingView
behavior="position"
// eslint-disable-next-line react-native/no-inline-styles
style={{
position: "relative",
flex: 1,
justifyContent: "flex-end",
}}
>
<ActionsheetBackdrop />
<ActionsheetContent maxHeight="75%">
<ActionsheetDragIndicatorWrapper>
<ActionsheetDragIndicator />
</ActionsheetDragIndicatorWrapper>
<VStack w="$full" p={20}>
<HStack justifyContent="center" alignItems="center" space="md">
<Box
w={50}
h="$full"
px="$2"
borderWidth={1}
borderStyle="solid"
borderColor="$borderLight300"
rounded="$sm"
>
<Image
source={{ uri: "https://i.imgur.com/UwTLr26.png" }}
flex={1}
resizeMode="contain"
/>
</Box>
<VStack flex={1}>
<Text fontWeight="$bold">Mastercard</Text>
<Text>Card ending in 2345</Text>
</VStack>
</HStack>
<FormControl mt={36}>
<FormControlLabel>
<FormControlLabelText>
Confirm security code
</FormControlLabelText>
</FormControlLabel>
<Input w="$full">
<InputSlot>
<InputIcon as={LeadingIcon} ml="$2" />
</InputSlot>
<InputField placeholder="CVC/CVV" />
</Input>
<Button onPress={handleClose} mt={20}>
<ButtonText>Pay $1000</ButtonText>
</Button>
</FormControl>
</VStack>
</ActionsheetContent>
</KeyboardAvoidingView>
</Actionsheet>
</>
)
}

Icons

The Actionsheet with Icons is a variation of the Actionsheet component that displays icons next to each option. It's commonly used in apps for a more visual representation of options and easier navigation.
function App() {
const [showActionsheet, setShowActionsheet] = React.useState(false)
const handleClose = () => setShowActionsheet(!showActionsheet)
return (
<>
<Button onPress={handleClose}>
<ButtonText>Open</ButtonText>
</Button>
<Actionsheet isOpen={showActionsheet} onClose={handleClose}>
<ActionsheetBackdrop />
<ActionsheetContent>
<ActionsheetDragIndicatorWrapper>
<ActionsheetDragIndicator />
</ActionsheetDragIndicatorWrapper>
<ActionsheetItem onPress={handleClose}>
<ActionsheetIcon>
<Icon as={TrashIcon} />
</ActionsheetIcon>
<ActionsheetItemText>Delete</ActionsheetItemText>
</ActionsheetItem>
<ActionsheetItem onPress={handleClose}>
<ActionsheetIcon>
<Icon as={ShareIcon} />
</ActionsheetIcon>
<ActionsheetItemText>Share</ActionsheetItemText>
</ActionsheetItem>
<ActionsheetItem onPress={handleClose}>
<ActionsheetIcon>
<Icon as={PlayIcon} />
</ActionsheetIcon>
<ActionsheetItemText>Play</ActionsheetItemText>
</ActionsheetItem>
<ActionsheetItem onPress={handleClose}>
<ActionsheetIcon>
<Icon as={FavouriteIcon} />
</ActionsheetIcon>
<ActionsheetItemText>Favourite</ActionsheetItemText>
</ActionsheetItem>
<ActionsheetItem onPress={handleClose}>
<ActionsheetIcon>
<Icon as={CloseIcon} />
</ActionsheetIcon>
<ActionsheetItemText>Cancel</ActionsheetItemText>
</ActionsheetItem>
</ActionsheetContent>
</Actionsheet>
</>
)
}

VirtualizedList

The Actionsheet with Virtualized List includes a virtualized list for better performance when displaying a large number of options. It's commonly used in apps with long lists of options for an improved user experience.
function App() {
const [showActionsheet, setShowActionsheet] = React.useState(false)
const handleClose = () => setShowActionsheet(!showActionsheet)
const data = React.useMemo(
() =>
Array(50)
.fill(0)
.map((_, index) => "Item" + index),
[]
)
const getItem = (_data, index) => ({
id: Math.random().toString(12).substring(0),
title: _data[index],
})
const getItemCount = (_data) => _data.length
const Item = React.useCallback(
({ title }) => (
<ActionsheetItem onPress={handleClose}>
<ActionsheetItemText>{title}</ActionsheetItemText>
</ActionsheetItem>
),
[handleClose]
)
return (
<>
<Button onPress={handleClose}>
<ButtonText>Open</ButtonText>
</Button>
<Actionsheet isOpen={showActionsheet} onClose={handleClose}>
<ActionsheetBackdrop />
<ActionsheetContent>
<ActionsheetDragIndicatorWrapper>
<ActionsheetDragIndicator />
</ActionsheetDragIndicatorWrapper>
<ActionsheetVirtualizedList
h="$56"
data={data}
initialNumToRender={5}
renderItem={({ item }) => <Item title={item.title} />}
keyExtractor={(item) => item.id}
getItemCount={getItemCount}
getItem={getItem}
/>
</ActionsheetContent>
</Actionsheet>
</>
)
}

FlatList

The Actionsheet with Flat List is a variation of the Actionsheet component that displays a flat list of options. It's commonly used in apps for a simple and straightforward display of options to the user.
function App() {
const [showActionsheet, setShowActionsheet] = React.useState(false)
const handleClose = () => setShowActionsheet(!showActionsheet)
const DATA = [
{
id: "bd7acbea-c1b1-46c2-aed5-3ad53abb28ba",
title: "First Item",
},
{
id: "3ac68afc-c605-48d3-a4f8-fbd91aa97f63",
title: "Second Item",
},
{
id: "58694a0f-3da1-471f-bd96-145571e29d72",
title: "Third Item",
},
]
const Item = React.useCallback(
({ title }) => (
<ActionsheetItem onPress={handleClose}>
<ActionsheetItemText>{title}</ActionsheetItemText>
</ActionsheetItem>
),
[handleClose]
)
return (
<>
<Button onPress={handleClose}>
<ButtonText>Open</ButtonText>
</Button>
<Actionsheet isOpen={showActionsheet} onClose={handleClose}>
<ActionsheetBackdrop />
<ActionsheetContent>
<ActionsheetDragIndicatorWrapper>
<ActionsheetDragIndicator />
</ActionsheetDragIndicatorWrapper>
<ActionsheetFlatList
data={DATA}
renderItem={({ item }) => <Item title={item.title} />}
keyExtractor={(item) => item.id}
/>
</ActionsheetContent>
</Actionsheet>
</>
)
}

SectionList

The Actionsheet with SectionList is a variation of the Actionsheet component that displays a sectioned list of options. It's commonly used in apps to organize options into different categories or sections for better readability and navigation.
Default styling of the component can be found in the components/actionsheet file. For reference, you can view the source code of the styled Actionsheet component.
function App() {
const [showActionsheet, setShowActionsheet] = React.useState(false)
const handleClose = () => setShowActionsheet(!showActionsheet)
const DATA = [
{
title: "Main dishes",
data: ["Pizza", "Burger", "Risotto"],
},
{
title: "Sides",
data: ["French Fries", "Onion Rings", "Fried Shrimps"],
},
{
title: "Drinks",
data: ["Water", "Coke", "Beer"],
},
{
title: "Desserts",
data: ["Cheese Cake", "Ice Cream"],
},
]
return (
<>
<Button onPress={handleClose}>
<ButtonText>Open</ButtonText>
</Button>
<Actionsheet isOpen={showActionsheet} onClose={handleClose}>
<ActionsheetBackdrop />
<ActionsheetContent>
<ActionsheetDragIndicatorWrapper>
<ActionsheetDragIndicator />
</ActionsheetDragIndicatorWrapper>
<ActionsheetSectionList
h="$56"
sections={DATA}
keyExtractor={(item, index) => item + index}
renderItem={({ item }) => (
<ActionsheetItem onPress={handleClose}>
<ActionsheetItemText>{item}</ActionsheetItemText>
</ActionsheetItem>
)}
renderSectionHeader={({ section: { title, data } }) => (
<ActionsheetSectionHeaderText>
{title} ({data.length})
</ActionsheetSectionHeaderText>
)}
/>
</ActionsheetContent>
</Actionsheet>
</>
)
}

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 Actionsheet 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.