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.

CardList.js 1.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. // @flow
  2. import * as React from 'react';
  3. import {Animated} from "react-native";
  4. import ImageListItem from "./ImageListItem";
  5. import CardListItem from "./CardListItem";
  6. type Props = {
  7. dataset: Array<cardItem>,
  8. isHorizontal: boolean,
  9. }
  10. export type cardItem = {
  11. title: string,
  12. subtitle: string,
  13. image: string | number,
  14. onPress: () => void,
  15. };
  16. export type cardList = Array<cardItem>;
  17. export default class CardList extends React.Component<Props> {
  18. static defaultProps = {
  19. isHorizontal: false,
  20. }
  21. renderItem = ({item}: { item: cardItem }) => {
  22. if (this.props.isHorizontal)
  23. return <ImageListItem item={item} key={item.title}/>;
  24. else
  25. return <CardListItem item={item} key={item.title}/>;
  26. };
  27. keyExtractor = (item: cardItem) => item.title;
  28. render() {
  29. let containerStyle;
  30. if (this.props.isHorizontal) {
  31. containerStyle = {
  32. ...this.props.contentContainerStyle,
  33. height: 150,
  34. justifyContent: 'space-around',
  35. };
  36. } else {
  37. containerStyle = {
  38. ...this.props.contentContainerStyle,
  39. }
  40. }
  41. return (
  42. <Animated.FlatList
  43. {...this.props}
  44. data={this.props.dataset}
  45. renderItem={this.renderItem}
  46. keyExtractor={this.keyExtractor}
  47. numColumns={this.props.isHorizontal ? undefined : 2}
  48. horizontal={this.props.isHorizontal}
  49. contentContainerStyle={containerStyle}
  50. />
  51. );
  52. }
  53. }