Application Android et IOS pour l'amicale des élèves https://play.google.com/store/apps/details?id=fr.amicaleinsat.application
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.tsx 2.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. /*
  2. * Copyright (c) 2019 - 2020 Arnaud Vergnet.
  3. *
  4. * This file is part of Campus INSAT.
  5. *
  6. * Campus INSAT is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * Campus INSAT is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with Campus INSAT. If not, see <https://www.gnu.org/licenses/>.
  18. */
  19. import * as React from 'react';
  20. import { Button, Dialog, Paragraph, Portal } from 'react-native-paper';
  21. import { FlatList } from 'react-native';
  22. export type OptionsDialogButtonType = {
  23. title: string;
  24. icon?: string;
  25. onPress: () => void;
  26. };
  27. type PropsType = {
  28. visible: boolean;
  29. title: string;
  30. message: string;
  31. buttons: Array<OptionsDialogButtonType>;
  32. onDismiss: () => void;
  33. };
  34. function OptionsDialog(props: PropsType) {
  35. const getButtonRender = ({ item }: { item: OptionsDialogButtonType }) => {
  36. return (
  37. <Button onPress={item.onPress} icon={item.icon}>
  38. {item.title}
  39. </Button>
  40. );
  41. };
  42. const keyExtractor = (item: OptionsDialogButtonType): string => {
  43. if (item.icon != null) {
  44. return item.title + item.icon;
  45. }
  46. return item.title;
  47. };
  48. return (
  49. <Portal>
  50. <Dialog visible={props.visible} onDismiss={props.onDismiss}>
  51. <Dialog.Title>{props.title}</Dialog.Title>
  52. <Dialog.Content>
  53. <Paragraph>{props.message}</Paragraph>
  54. </Dialog.Content>
  55. <Dialog.Actions>
  56. <FlatList
  57. data={props.buttons}
  58. renderItem={getButtonRender}
  59. keyExtractor={keyExtractor}
  60. horizontal
  61. inverted
  62. />
  63. </Dialog.Actions>
  64. </Dialog>
  65. </Portal>
  66. );
  67. }
  68. export default OptionsDialog;