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.

FeedItemScreen.js 3.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. // @flow
  2. import * as React from 'react';
  3. import {Linking, Image} from 'react-native';
  4. import {Card, Text, withTheme} from 'react-native-paper';
  5. import Autolink from 'react-native-autolink';
  6. import {StackNavigationProp} from '@react-navigation/stack';
  7. import MaterialHeaderButtons, {
  8. Item,
  9. } from '../../components/Overrides/CustomHeaderButton';
  10. import CustomTabBar from '../../components/Tabbar/CustomTabBar';
  11. import type {FeedItemType} from './HomeScreen';
  12. import CollapsibleScrollView from '../../components/Collapsible/CollapsibleScrollView';
  13. import ImageGalleryButton from '../../components/Media/ImageGalleryButton';
  14. import NewsSourcesConstants from '../../constants/NewsSourcesConstants';
  15. import type {NewsSourceType} from '../../constants/NewsSourcesConstants';
  16. type PropsType = {
  17. navigation: StackNavigationProp,
  18. route: {params: {data: FeedItemType, date: string}},
  19. };
  20. /**
  21. * Class defining a feed item page.
  22. */
  23. class FeedItemScreen extends React.Component<PropsType> {
  24. displayData: FeedItemType;
  25. date: string;
  26. constructor(props: PropsType) {
  27. super(props);
  28. this.displayData = props.route.params.data;
  29. this.date = props.route.params.date;
  30. }
  31. componentDidMount() {
  32. const {props} = this;
  33. props.navigation.setOptions({
  34. headerRight: this.getHeaderButton,
  35. });
  36. }
  37. /**
  38. * Opens the feed item out link in browser or compatible app
  39. */
  40. onOutLinkPress = () => {
  41. Linking.openURL(this.displayData.url);
  42. };
  43. /**
  44. * Gets the out link header button
  45. *
  46. * @returns {*}
  47. */
  48. getHeaderButton = (): React.Node => {
  49. return (
  50. <MaterialHeaderButtons>
  51. <Item
  52. title="main"
  53. iconName="facebook"
  54. color="#2e88fe"
  55. onPress={this.onOutLinkPress}
  56. />
  57. </MaterialHeaderButtons>
  58. );
  59. };
  60. render(): React.Node {
  61. const {navigation} = this.props;
  62. const hasImage =
  63. this.displayData.image !== '' && this.displayData.image != null;
  64. const pageSource: NewsSourceType =
  65. NewsSourcesConstants[this.displayData.page_id];
  66. return (
  67. <CollapsibleScrollView style={{margin: 5}} hasTab>
  68. <Card.Title
  69. title={pageSource.name}
  70. subtitle={this.date}
  71. left={(): React.Node => (
  72. <Image
  73. size={48}
  74. source={pageSource.icon}
  75. style={{
  76. width: 48,
  77. height: 48,
  78. }}
  79. />
  80. )}
  81. />
  82. {hasImage ? (
  83. <ImageGalleryButton
  84. navigation={navigation}
  85. images={[{url: this.displayData.image}]}
  86. style={{
  87. width: 250,
  88. height: 250,
  89. marginLeft: 'auto',
  90. marginRight: 'auto',
  91. }}
  92. />
  93. ) : null}
  94. <Card.Content style={{paddingBottom: CustomTabBar.TAB_BAR_HEIGHT + 20}}>
  95. {this.displayData.message !== undefined ? (
  96. <Autolink
  97. text={this.displayData.message}
  98. hashtag="facebook"
  99. component={Text}
  100. />
  101. ) : null}
  102. </Card.Content>
  103. </CollapsibleScrollView>
  104. );
  105. }
  106. }
  107. export default withTheme(FeedItemScreen);