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

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