import React from 'react';
import { View, Button, ActionSheetIOS, Alert, StyleSheet } from 'react-native';
const App = () => {
const showActionSheet = () => {
ActionSheetIOS.showActionSheetWithOptions(
{
title: 'File Actions',
message: 'Choose what to do with this file',
options: ['Cancel', 'Delete', 'Archive', 'Duplicate', 'Share'],
destructiveButtonIndex: 1,
cancelButtonIndex: 0,
tintColor: '#007AFF',
userInterfaceStyle: 'light',
},
(buttonIndex) => {
const actions = ['Cancelled', 'Delete', 'Archive', 'Duplicate', 'Share'];
Alert.alert('Action Selected', actions[buttonIndex]);
}
);
};
const showActionSheetWithMultipleDestructive = () => {
ActionSheetIOS.showActionSheetWithOptions(
{
title: 'Destructive Actions',
message: 'Multiple destructive options',
options: ['Cancel', 'Delete All', 'Remove', 'Clear Cache'],
destructiveButtonIndex: [1, 2, 3],
cancelButtonIndex: 0,
},
(buttonIndex) => {
console.log('Selected button:', buttonIndex);
}
);
};
const showShareSheet = () => {
ActionSheetIOS.showShareActionSheetWithOptions(
{
url: 'https://reactnative.dev',
message: 'React Native - A framework for building native apps using React',
subject: 'Check out React Native!',
},
(error) => Alert.alert('Error', error.message),
(success, method) => {
if (success) {
Alert.alert('Success', `Shared via ${method}`);
} else {
Alert.alert('Cancelled', 'Share was cancelled');
}
}
);
};
const showShareSheetWithImage = () => {
// Example with a local image
const imageUrl = 'file:///path/to/local/image.png';
// Or base64 encoded image
// const imageUrl = 'data:image/png;base64,iVBORw0KGgoAAAANS...';
ActionSheetIOS.showShareActionSheetWithOptions(
{
url: imageUrl,
message: 'Check out this image!',
},
(error) => console.error('Share failed:', error),
(success, method) => {
if (success) {
console.log('Image shared via', method);
}
}
);
};
return (
<View style={styles.container}>
<Button title="Show Action Sheet" onPress={showActionSheet} />
<Button
title="Multiple Destructive Buttons"
onPress={showActionSheetWithMultipleDestructive}
/>
<Button title="Share URL" onPress={showShareSheet} />
<Button title="Share Image" onPress={showShareSheetWithImage} />
<Button
title="Dismiss Action Sheet"
onPress={() => ActionSheetIOS.dismissActionSheet()}
/>
</View>
);
};
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
paddingHorizontal: 20,
gap: 10,
},
});
export default App;