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.

FeedItemScreen.tsx 3.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. /*
  2. * Copyright (c) 2019 - 2020 Arnaud Vergnet.
  3. *
  4. * This file is part of Campus INSAT.
  5. *
  6. * Campus INSAT is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * Campus INSAT is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with Campus INSAT. If not, see <https://www.gnu.org/licenses/>.
  18. */
  19. import * as React from 'react';
  20. import {Linking, Image} from 'react-native';
  21. import {Card, Text} from 'react-native-paper';
  22. import Autolink from 'react-native-autolink';
  23. import {StackNavigationProp} from '@react-navigation/stack';
  24. import MaterialHeaderButtons, {
  25. Item,
  26. } from '../../components/Overrides/CustomHeaderButton';
  27. import CustomTabBar from '../../components/Tabbar/CustomTabBar';
  28. import type {FeedItemType} from './HomeScreen';
  29. import CollapsibleScrollView from '../../components/Collapsible/CollapsibleScrollView';
  30. import ImageGalleryButton from '../../components/Media/ImageGalleryButton';
  31. import NewsSourcesConstants, {
  32. AvailablePages,
  33. } from '../../constants/NewsSourcesConstants';
  34. import type {NewsSourceType} from '../../constants/NewsSourcesConstants';
  35. type PropsType = {
  36. navigation: StackNavigationProp<any>;
  37. route: {params: {data: FeedItemType; date: string}};
  38. };
  39. /**
  40. * Class defining a feed item page.
  41. */
  42. class FeedItemScreen extends React.Component<PropsType> {
  43. displayData: FeedItemType;
  44. date: string;
  45. constructor(props: PropsType) {
  46. super(props);
  47. this.displayData = props.route.params.data;
  48. this.date = props.route.params.date;
  49. }
  50. componentDidMount() {
  51. const {props} = this;
  52. props.navigation.setOptions({
  53. headerRight: this.getHeaderButton,
  54. });
  55. }
  56. /**
  57. * Opens the feed item out link in browser or compatible app
  58. */
  59. onOutLinkPress = () => {
  60. Linking.openURL(this.displayData.url);
  61. };
  62. /**
  63. * Gets the out link header button
  64. *
  65. * @returns {*}
  66. */
  67. getHeaderButton = () => {
  68. return (
  69. <MaterialHeaderButtons>
  70. <Item
  71. title="main"
  72. iconName="facebook"
  73. color="#2e88fe"
  74. onPress={this.onOutLinkPress}
  75. />
  76. </MaterialHeaderButtons>
  77. );
  78. };
  79. render() {
  80. const pageSource: NewsSourceType =
  81. NewsSourcesConstants[this.displayData.page_id as AvailablePages];
  82. return (
  83. <CollapsibleScrollView style={{margin: 5}} hasTab>
  84. <Card.Title
  85. title={pageSource.name}
  86. subtitle={this.date}
  87. left={() => (
  88. <Image
  89. source={pageSource.icon}
  90. style={{
  91. width: 48,
  92. height: 48,
  93. }}
  94. />
  95. )}
  96. />
  97. {this.displayData.image ? (
  98. <ImageGalleryButton
  99. images={[{url: this.displayData.image}]}
  100. style={{
  101. width: 250,
  102. height: 250,
  103. marginLeft: 'auto',
  104. marginRight: 'auto',
  105. }}
  106. />
  107. ) : null}
  108. <Card.Content style={{paddingBottom: CustomTabBar.TAB_BAR_HEIGHT + 20}}>
  109. {this.displayData.message !== undefined ? (
  110. <Autolink
  111. text={this.displayData.message}
  112. hashtag="facebook"
  113. // @ts-ignore
  114. component={Text}
  115. />
  116. ) : null}
  117. </Card.Content>
  118. </CollapsibleScrollView>
  119. );
  120. }
  121. }
  122. export default FeedItemScreen;