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.

AboutDependenciesScreen.tsx 2.7KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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 {List} from 'react-native-paper';
  21. import {View} from 'react-native-animatable';
  22. import CollapsibleFlatList from '../../components/Collapsible/CollapsibleFlatList';
  23. import packageJson from '../../../package.json';
  24. type ListItemType = {
  25. name: string;
  26. version: string;
  27. };
  28. /**
  29. * Generates the dependencies list from the raw json
  30. *
  31. * @param object The raw json
  32. * @return {Array<ListItemType>}
  33. */
  34. function generateListFromObject(object: {
  35. [key: string]: string;
  36. }): Array<ListItemType> {
  37. const list: Array<ListItemType> = [];
  38. const keys = Object.keys(object);
  39. keys.forEach((key: string) => {
  40. list.push({name: key, version: object[key]});
  41. });
  42. return list;
  43. }
  44. const LIST_ITEM_HEIGHT = 64;
  45. /**
  46. * Class defining a screen showing the list of libraries used by the app, taken from package.json
  47. */
  48. export default class AboutDependenciesScreen extends React.Component<{}> {
  49. data: Array<ListItemType>;
  50. constructor(props: {}) {
  51. super(props);
  52. this.data = generateListFromObject(packageJson.dependencies);
  53. }
  54. keyExtractor = (item: ListItemType): string => item.name;
  55. getRenderItem = ({item}: {item: ListItemType}) => (
  56. <List.Item
  57. title={item.name}
  58. description={item.version.replace('^', '').replace('~', '')}
  59. style={{height: LIST_ITEM_HEIGHT}}
  60. />
  61. );
  62. getItemLayout = (
  63. data: Array<ListItemType> | null | undefined,
  64. index: number,
  65. ): {length: number; offset: number; index: number} => ({
  66. length: LIST_ITEM_HEIGHT,
  67. offset: LIST_ITEM_HEIGHT * index,
  68. index,
  69. });
  70. render() {
  71. return (
  72. <View>
  73. <CollapsibleFlatList
  74. data={this.data}
  75. keyExtractor={this.keyExtractor}
  76. renderItem={this.getRenderItem}
  77. // Performance props, see https://reactnative.dev/docs/optimizing-flatlist-configuration
  78. removeClippedSubviews
  79. getItemLayout={this.getItemLayout}
  80. />
  81. </View>
  82. );
  83. }
  84. }