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 2.4KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. // @flow
  2. import * as React from 'react';
  3. import {withTheme} from 'react-native-paper';
  4. import {FlatList, Image, View} from 'react-native';
  5. import MaterialCommunityIcons from 'react-native-vector-icons/MaterialCommunityIcons';
  6. import DashboardEditItem from './DashboardEditItem';
  7. import AnimatedAccordion from '../../Animations/AnimatedAccordion';
  8. import type {
  9. ServiceCategoryType,
  10. ServiceItemType,
  11. } from '../../../managers/ServicesManager';
  12. import type {CustomTheme} from '../../../managers/ThemeManager';
  13. type PropsType = {
  14. item: ServiceCategoryType,
  15. activeDashboard: Array<string>,
  16. onPress: (service: ServiceItemType) => void,
  17. theme: CustomTheme,
  18. };
  19. const LIST_ITEM_HEIGHT = 64;
  20. class DashboardEditAccordion extends React.Component<PropsType> {
  21. getRenderItem = ({item}: {item: ServiceItemType}): React.Node => {
  22. const {props} = this;
  23. return (
  24. <DashboardEditItem
  25. height={LIST_ITEM_HEIGHT}
  26. item={item}
  27. isActive={props.activeDashboard.includes(item.key)}
  28. onPress={() => {
  29. props.onPress(item);
  30. }}
  31. />
  32. );
  33. };
  34. getItemLayout = (
  35. data: ?Array<ServiceItemType>,
  36. index: number,
  37. ): {length: number, offset: number, index: number} => ({
  38. length: LIST_ITEM_HEIGHT,
  39. offset: LIST_ITEM_HEIGHT * index,
  40. index,
  41. });
  42. render(): React.Node {
  43. const {props} = this;
  44. const {item} = props;
  45. return (
  46. <View>
  47. <AnimatedAccordion
  48. title={item.title}
  49. left={(): React.Node =>
  50. typeof item.image === 'number' ? (
  51. <Image
  52. source={item.image}
  53. style={{
  54. width: 40,
  55. height: 40,
  56. }}
  57. />
  58. ) : (
  59. <MaterialCommunityIcons
  60. // $FlowFixMe
  61. name={item.image}
  62. color={props.theme.colors.primary}
  63. size={40}
  64. />
  65. )
  66. }>
  67. {/* $FlowFixMe */}
  68. <FlatList
  69. data={item.content}
  70. extraData={props.activeDashboard.toString()}
  71. renderItem={this.getRenderItem}
  72. listKey={item.key}
  73. // Performance props, see https://reactnative.dev/docs/optimizing-flatlist-configuration
  74. getItemLayout={this.getItemLayout}
  75. removeClippedSubviews
  76. />
  77. </AnimatedAccordion>
  78. </View>
  79. );
  80. }
  81. }
  82. export default withTheme(DashboardEditAccordion);