Application Android et IOS pour l'amicale des élèves
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

OptionsDialog.js 1.4KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. // @flow
  2. import * as React from 'react';
  3. import {Button, Dialog, Paragraph, Portal} from 'react-native-paper';
  4. import {FlatList} from 'react-native';
  5. export type OptionsDialogButtonType = {
  6. title: string,
  7. icon?: string,
  8. onPress: () => void,
  9. };
  10. type PropsType = {
  11. visible: boolean,
  12. title: string,
  13. message: string,
  14. buttons: Array<OptionsDialogButtonType>,
  15. onDismiss: () => void,
  16. };
  17. class OptionsDialog extends React.PureComponent<PropsType> {
  18. getButtonRender = ({item}: {item: OptionsDialogButtonType}): React.Node => {
  19. return (
  20. <Button onPress={item.onPress} icon={item.icon}>
  21. {item.title}
  22. </Button>
  23. );
  24. };
  25. keyExtractor = (item: OptionsDialogButtonType): string => {
  26. if (item.icon != null) {
  27. return item.title + item.icon;
  28. }
  29. return item.title;
  30. };
  31. render(): React.Node {
  32. const {props} = this;
  33. return (
  34. <Portal>
  35. <Dialog visible={props.visible} onDismiss={props.onDismiss}>
  36. <Dialog.Title>{props.title}</Dialog.Title>
  37. <Dialog.Content>
  38. <Paragraph>{props.message}</Paragraph>
  39. </Dialog.Content>
  40. <Dialog.Actions>
  41. <FlatList
  42. data={props.buttons}
  43. renderItem={this.getButtonRender}
  44. keyExtractor={this.keyExtractor}
  45. horizontal
  46. inverted
  47. />
  48. </Dialog.Actions>
  49. </Dialog>
  50. </Portal>
  51. );
  52. }
  53. }
  54. export default OptionsDialog;