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.

CardList.js 2.0KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. // @flow
  2. import * as React from 'react';
  3. import {Animated, Dimensions} from 'react-native';
  4. import type {ViewStyle} from 'react-native/Libraries/StyleSheet/StyleSheet';
  5. import ImageListItem from './ImageListItem';
  6. import CardListItem from './CardListItem';
  7. import type {ServiceItemType} from '../../../managers/ServicesManager';
  8. type PropsType = {
  9. dataset: Array<ServiceItemType>,
  10. isHorizontal?: boolean,
  11. contentContainerStyle?: ViewStyle | null,
  12. };
  13. export default class CardList extends React.Component<PropsType> {
  14. static defaultProps = {
  15. isHorizontal: false,
  16. contentContainerStyle: null,
  17. };
  18. windowWidth: number;
  19. horizontalItemSize: number;
  20. constructor(props: PropsType) {
  21. super(props);
  22. this.windowWidth = Dimensions.get('window').width;
  23. this.horizontalItemSize = this.windowWidth / 4; // So that we can fit 3 items and a part of the 4th => user knows he can scroll
  24. }
  25. getRenderItem = ({item}: {item: ServiceItemType}): React.Node => {
  26. const {props} = this;
  27. if (props.isHorizontal)
  28. return (
  29. <ImageListItem
  30. item={item}
  31. key={item.title}
  32. width={this.horizontalItemSize}
  33. />
  34. );
  35. return <CardListItem item={item} key={item.title} />;
  36. };
  37. keyExtractor = (item: ServiceItemType): string => item.key;
  38. render(): React.Node {
  39. const {props} = this;
  40. let containerStyle = {};
  41. if (props.isHorizontal) {
  42. containerStyle = {
  43. height: this.horizontalItemSize + 50,
  44. justifyContent: 'space-around',
  45. };
  46. }
  47. return (
  48. <Animated.FlatList
  49. data={props.dataset}
  50. renderItem={this.getRenderItem}
  51. keyExtractor={this.keyExtractor}
  52. numColumns={props.isHorizontal ? undefined : 2}
  53. horizontal={props.isHorizontal}
  54. contentContainerStyle={
  55. props.isHorizontal ? containerStyle : props.contentContainerStyle
  56. }
  57. pagingEnabled={props.isHorizontal}
  58. snapToInterval={
  59. props.isHorizontal ? (this.horizontalItemSize + 5) * 3 : null
  60. }
  61. />
  62. );
  63. }
  64. }