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.

ClubListItem.js 2.4KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. // @flow
  2. import * as React from 'react';
  3. import {Avatar, Chip, List, withTheme} from 'react-native-paper';
  4. import {View} from 'react-native';
  5. import type {
  6. ClubCategoryType,
  7. ClubType,
  8. } from '../../../screens/Amicale/Clubs/ClubListScreen';
  9. import type {CustomThemeType} from '../../../managers/ThemeManager';
  10. type PropsType = {
  11. onPress: () => void,
  12. categoryTranslator: (id: number) => ClubCategoryType,
  13. item: ClubType,
  14. height: number,
  15. theme: CustomThemeType,
  16. };
  17. class ClubListItem extends React.Component<PropsType> {
  18. hasManagers: boolean;
  19. constructor(props: PropsType) {
  20. super(props);
  21. this.hasManagers = props.item.responsibles.length > 0;
  22. }
  23. shouldComponentUpdate(): boolean {
  24. return false;
  25. }
  26. getCategoriesRender(categories: Array<number | null>): React.Node {
  27. const {props} = this;
  28. const final = [];
  29. categories.forEach((cat: number | null) => {
  30. if (cat != null) {
  31. const category: ClubCategoryType = props.categoryTranslator(cat);
  32. final.push(
  33. <Chip
  34. style={{marginRight: 5, marginBottom: 5}}
  35. key={`${props.item.id}:${category.id}`}>
  36. {category.name}
  37. </Chip>,
  38. );
  39. }
  40. });
  41. return <View style={{flexDirection: 'row'}}>{final}</View>;
  42. }
  43. render(): React.Node {
  44. const {props} = this;
  45. const categoriesRender = (): React.Node =>
  46. this.getCategoriesRender(props.item.category);
  47. const {colors} = props.theme;
  48. return (
  49. <List.Item
  50. title={props.item.name}
  51. description={categoriesRender}
  52. onPress={props.onPress}
  53. left={(): React.Node => (
  54. <Avatar.Image
  55. style={{
  56. backgroundColor: 'transparent',
  57. marginLeft: 10,
  58. marginRight: 10,
  59. }}
  60. size={64}
  61. source={{uri: props.item.logo}}
  62. />
  63. )}
  64. right={(): React.Node => (
  65. <Avatar.Icon
  66. style={{
  67. marginTop: 'auto',
  68. marginBottom: 'auto',
  69. backgroundColor: 'transparent',
  70. }}
  71. size={48}
  72. icon={
  73. this.hasManagers ? 'check-circle-outline' : 'alert-circle-outline'
  74. }
  75. color={this.hasManagers ? colors.success : colors.primary}
  76. />
  77. )}
  78. style={{
  79. height: props.height,
  80. justifyContent: 'center',
  81. }}
  82. />
  83. );
  84. }
  85. }
  86. export default withTheme(ClubListItem);