A modal view that presents choices related to an action people initiate.
import { useActionSheet } from '@expo/react-native-action-sheet';
import { Icon } from '@roninoss/icons';
import { Stack } from 'expo-router';
import { Button, View, Text, ScrollView, Pressable } from 'react-native';
import { useColorScheme } from '~/lib/useColorScheme';
export default function ActionSheetScreen() {
const { colorScheme, colors } = useColorScheme();
const { showActionSheetWithOptions } = useActionSheet();
return (
<>
<Stack.Screen
options={{
title: 'NativeWindUI',
headerSearchBarOptions: {
hideWhenScrolling: false,
},
headerLargeTitle: true,
headerRight() {
return (
<Pressable className="opacity-80 active:opacity-40">
<View className="opacity-90">
<Icon name="cog-outline" color={colors.foreground} />
</View>
</Pressable>
);
},
}}
/>
<ScrollView contentInsetAdjustmentBehavior="automatic" className="p-4">
<View className="border-border bg-card gap-4 rounded-xl border p-4 pb-6 shadow-sm shadow-black/10 dark:shadow-none">
<Text className="text-foreground text-center text-sm font-medium tracking-wider opacity-60">
Action Sheet
</Text>
<Button
color="grey"
onPress={async () => {
const options = ['Delete', 'Save', 'Cancel'];
const destructiveButtonIndex = 0;
const cancelButtonIndex = 2;
showActionSheetWithOptions(
{
options,
cancelButtonIndex,
destructiveButtonIndex,
containerStyle: {
backgroundColor: colorScheme === 'dark' ? 'black' : 'white',
},
textStyle: {
color: colors.foreground,
},
},
(selectedIndex) => {
switch (selectedIndex) {
case 1:
// Save
break;
case destructiveButtonIndex:
// Delete
break;
case cancelButtonIndex:
// Canceled
}
}
);
}}
title="Open action sheet"
/>
</View>
</ScrollView>
</>
);
}
npx nwui-cli@latest add action-sheet
Next, wrap your root component with an ActionSheetProvider.
npx expo install @expo/react-native-action-sheet
Next, wrap your root component with an ActionSheetProvider.
import { useActionSheet } from '@expo/react-native-action-sheet';
const { showActionSheetWithOptions } = useActionSheet();
React.useEffect(() => {
const options = ['Delete', 'Save', 'Cancel'];
const destructiveButtonIndex = 0;
const cancelButtonIndex = 2;
showActionSheetWithOptions(
{
options,
cancelButtonIndex,
destructiveButtonIndex,
},
(selectedIndex: number) => {
switch (selectedIndex) {
case 1:
// Save
break;
case destructiveButtonIndex:
// Delete
break;
case cancelButtonIndex:
// Canceled
}
}
);
}, []);
See the react-native-action-sheet documentation for all of the options.