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.

DashboardEditAccordion.js 3.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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. // @flow
  20. import * as React from 'react';
  21. import {withTheme} from 'react-native-paper';
  22. import {FlatList, Image, View} from 'react-native';
  23. import MaterialCommunityIcons from 'react-native-vector-icons/MaterialCommunityIcons';
  24. import DashboardEditItem from './DashboardEditItem';
  25. import AnimatedAccordion from '../../Animations/AnimatedAccordion';
  26. import type {
  27. ServiceCategoryType,
  28. ServiceItemType,
  29. } from '../../../managers/ServicesManager';
  30. import type {CustomThemeType} from '../../../managers/ThemeManager';
  31. type PropsType = {
  32. item: ServiceCategoryType,
  33. activeDashboard: Array<string>,
  34. onPress: (service: ServiceItemType) => void,
  35. theme: CustomThemeType,
  36. };
  37. const LIST_ITEM_HEIGHT = 64;
  38. class DashboardEditAccordion extends React.Component<PropsType> {
  39. getRenderItem = ({item}: {item: ServiceItemType}): React.Node => {
  40. const {props} = this;
  41. return (
  42. <DashboardEditItem
  43. height={LIST_ITEM_HEIGHT}
  44. item={item}
  45. isActive={props.activeDashboard.includes(item.key)}
  46. onPress={() => {
  47. props.onPress(item);
  48. }}
  49. />
  50. );
  51. };
  52. getItemLayout = (
  53. data: ?Array<ServiceItemType>,
  54. index: number,
  55. ): {length: number, offset: number, index: number} => ({
  56. length: LIST_ITEM_HEIGHT,
  57. offset: LIST_ITEM_HEIGHT * index,
  58. index,
  59. });
  60. render(): React.Node {
  61. const {props} = this;
  62. const {item} = props;
  63. return (
  64. <View>
  65. <AnimatedAccordion
  66. title={item.title}
  67. left={(): React.Node =>
  68. typeof item.image === 'number' ? (
  69. <Image
  70. source={item.image}
  71. style={{
  72. width: 40,
  73. height: 40,
  74. }}
  75. />
  76. ) : (
  77. <MaterialCommunityIcons
  78. // $FlowFixMe
  79. name={item.image}
  80. color={props.theme.colors.primary}
  81. size={40}
  82. />
  83. )
  84. }>
  85. {/* $FlowFixMe */}
  86. <FlatList
  87. data={item.content}
  88. extraData={props.activeDashboard.toString()}
  89. renderItem={this.getRenderItem}
  90. listKey={item.key}
  91. // Performance props, see https://reactnative.dev/docs/optimizing-flatlist-configuration
  92. getItemLayout={this.getItemLayout}
  93. removeClippedSubviews
  94. />
  95. </AnimatedAccordion>
  96. </View>
  97. );
  98. }
  99. }
  100. export default withTheme(DashboardEditAccordion);