Skip to content

Instantly share code, notes, and snippets.

@rpastorelle
Created April 12, 2016 17:16
Show Gist options
  • Save rpastorelle/801eabf763f1919cb528fd2e43e16b2a to your computer and use it in GitHub Desktop.
Save rpastorelle/801eabf763f1919cb528fd2e43e16b2a to your computer and use it in GitHub Desktop.
Cross-Platform ActionSheet Component for React Native
import { Alert } from 'react-native';
var ActionSheet = {
showActionSheetWithOptions: function(options : Object, onSelect : Function) {
let title = options.title,
buttons = [];
if (! title) {
if (options.options.length === 2) {
title = options.options[0] + '?';
} else {
title = 'Choose:';
}
}
options.options.forEach((label, index) => {
buttons.push({
text: label,
onPress: () => onSelect(index),
});
});
Alert.alert(null, title, buttons);
},
};
export default ActionSheet;
import { ActionSheetIOS } from 'react-native';
export default ActionSheetIOS;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment