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.

FeedItem.js 3.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. // @flow
  2. import * as React from 'react';
  3. import {Button, Card, Text, TouchableRipple} from 'react-native-paper';
  4. import {Image, View} from 'react-native';
  5. import Autolink from 'react-native-autolink';
  6. import i18n from 'i18n-js';
  7. import {StackNavigationProp} from '@react-navigation/stack';
  8. import type {FeedItemType} from '../../screens/Home/HomeScreen';
  9. import NewsSourcesConstants from '../../constants/NewsSourcesConstants';
  10. import type {NewsSourceType} from '../../constants/NewsSourcesConstants';
  11. import ImageGalleryButton from '../Media/ImageGalleryButton';
  12. type PropsType = {
  13. navigation: StackNavigationProp,
  14. item: FeedItemType,
  15. height: number,
  16. };
  17. /**
  18. * Component used to display a feed item
  19. */
  20. class FeedItem extends React.Component<PropsType> {
  21. /**
  22. * Converts a dateString using Unix Timestamp to a formatted date
  23. *
  24. * @param dateString {string} The Unix Timestamp representation of a date
  25. * @return {string} The formatted output date
  26. */
  27. static getFormattedDate(dateString: number): string {
  28. const date = new Date(dateString * 1000);
  29. return date.toLocaleString();
  30. }
  31. shouldComponentUpdate(): boolean {
  32. return false;
  33. }
  34. onPress = () => {
  35. const {item, navigation} = this.props;
  36. navigation.navigate('feed-information', {
  37. data: item,
  38. date: FeedItem.getFormattedDate(item.time),
  39. });
  40. };
  41. render(): React.Node {
  42. const {props} = this;
  43. const {item} = props;
  44. const hasImage = item.image !== '' && item.image != null;
  45. const pageSource: NewsSourceType = NewsSourcesConstants[item.page_id];
  46. const cardMargin = 10;
  47. const cardHeight = props.height - 2 * cardMargin;
  48. const imageSize = 250;
  49. const titleHeight = 80;
  50. const actionsHeight = 60;
  51. const textHeight = hasImage
  52. ? cardHeight - titleHeight - actionsHeight - imageSize
  53. : cardHeight - titleHeight - actionsHeight;
  54. return (
  55. <Card
  56. style={{
  57. margin: cardMargin,
  58. height: cardHeight,
  59. }}>
  60. <TouchableRipple style={{flex: 1}} onPress={this.onPress}>
  61. <View>
  62. <Card.Title
  63. title={pageSource.name}
  64. subtitle={FeedItem.getFormattedDate(item.time)}
  65. left={(): React.Node => (
  66. <Image
  67. size={48}
  68. source={pageSource.icon}
  69. style={{
  70. width: 48,
  71. height: 48,
  72. }}
  73. />
  74. )}
  75. style={{height: titleHeight}}
  76. />
  77. {hasImage ? (
  78. <View style={{marginLeft: 'auto', marginRight: 'auto'}}>
  79. <ImageGalleryButton
  80. navigation={props.navigation}
  81. images={[{url: item.image}]}
  82. style={{
  83. width: imageSize,
  84. height: imageSize,
  85. }}
  86. />
  87. </View>
  88. ) : null}
  89. <Card.Content>
  90. {item.message !== undefined ? (
  91. <Autolink
  92. text={item.message}
  93. hashtag="facebook"
  94. component={Text}
  95. style={{height: textHeight}}
  96. />
  97. ) : null}
  98. </Card.Content>
  99. <Card.Actions style={{height: actionsHeight}}>
  100. <Button
  101. onPress={this.onPress}
  102. icon="plus"
  103. style={{marginLeft: 'auto'}}>
  104. {i18n.t('screens.home.dashboard.seeMore')}
  105. </Button>
  106. </Card.Actions>
  107. </View>
  108. </TouchableRipple>
  109. </Card>
  110. );
  111. }
  112. }
  113. export default FeedItem;