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.

AboutDependenciesScreen.js 1.9KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. // @flow
  2. import * as React from 'react';
  3. import {List} from 'react-native-paper';
  4. import {View} from 'react-native-animatable';
  5. import CollapsibleFlatList from '../../components/Collapsible/CollapsibleFlatList';
  6. import packageJson from '../../../package.json';
  7. type ListItemType = {
  8. name: string,
  9. version: string,
  10. };
  11. /**
  12. * Generates the dependencies list from the raw json
  13. *
  14. * @param object The raw json
  15. * @return {Array<ListItemType>}
  16. */
  17. function generateListFromObject(object: {
  18. [key: string]: string,
  19. }): Array<ListItemType> {
  20. const list = [];
  21. const keys = Object.keys(object);
  22. keys.forEach((key: string) => {
  23. list.push({name: key, version: object[key]});
  24. });
  25. return list;
  26. }
  27. const LIST_ITEM_HEIGHT = 64;
  28. /**
  29. * Class defining a screen showing the list of libraries used by the app, taken from package.json
  30. */
  31. export default class AboutDependenciesScreen extends React.Component<null> {
  32. data: Array<ListItemType>;
  33. constructor() {
  34. super();
  35. this.data = generateListFromObject(packageJson.dependencies);
  36. }
  37. keyExtractor = (item: ListItemType): string => item.name;
  38. getRenderItem = ({item}: {item: ListItemType}): React.Node => (
  39. <List.Item
  40. title={item.name}
  41. description={item.version.replace('^', '').replace('~', '')}
  42. style={{height: LIST_ITEM_HEIGHT}}
  43. />
  44. );
  45. getItemLayout = (
  46. data: ListItemType,
  47. index: number,
  48. ): {length: number, offset: number, index: number} => ({
  49. length: LIST_ITEM_HEIGHT,
  50. offset: LIST_ITEM_HEIGHT * index,
  51. index,
  52. });
  53. render(): React.Node {
  54. return (
  55. <View>
  56. <CollapsibleFlatList
  57. data={this.data}
  58. keyExtractor={this.keyExtractor}
  59. renderItem={this.getRenderItem}
  60. // Performance props, see https://reactnative.dev/docs/optimizing-flatlist-configuration
  61. removeClippedSubviews
  62. getItemLayout={this.getItemLayout}
  63. />
  64. </View>
  65. );
  66. }
  67. }