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.tsx 3.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  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, StyleSheet } 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, {
  28. TAB_BAR_HEIGHT,
  29. } from '../../components/Tabbar/CustomTabBar';
  30. import type { FeedItemType } from './HomeScreen';
  31. import CollapsibleScrollView from '../../components/Collapsible/CollapsibleScrollView';
  32. import ImageGalleryButton from '../../components/Media/ImageGalleryButton';
  33. import NewsSourcesConstants, {
  34. AvailablePages,
  35. } from '../../constants/NewsSourcesConstants';
  36. import type { NewsSourceType } from '../../constants/NewsSourcesConstants';
  37. type PropsType = {
  38. navigation: StackNavigationProp<any>;
  39. route: { params: { data: FeedItemType; date: string } };
  40. };
  41. const styles = StyleSheet.create({
  42. container: {
  43. margin: 5,
  44. },
  45. image: {
  46. width: 48,
  47. height: 48,
  48. },
  49. button: {
  50. width: 250,
  51. height: 250,
  52. marginLeft: 'auto',
  53. marginRight: 'auto',
  54. },
  55. });
  56. /**
  57. * Class defining a feed item page.
  58. */
  59. class FeedItemScreen extends React.Component<PropsType> {
  60. displayData: FeedItemType;
  61. date: string;
  62. constructor(props: PropsType) {
  63. super(props);
  64. this.displayData = props.route.params.data;
  65. this.date = props.route.params.date;
  66. }
  67. componentDidMount() {
  68. const { props } = this;
  69. props.navigation.setOptions({
  70. headerRight: this.getHeaderButton,
  71. });
  72. }
  73. /**
  74. * Opens the feed item out link in browser or compatible app
  75. */
  76. onOutLinkPress = () => {
  77. Linking.openURL(this.displayData.url);
  78. };
  79. /**
  80. * Gets the out link header button
  81. *
  82. * @returns {*}
  83. */
  84. getHeaderButton = () => {
  85. return (
  86. <MaterialHeaderButtons>
  87. <Item
  88. title="main"
  89. iconName="facebook"
  90. color="#2e88fe"
  91. onPress={this.onOutLinkPress}
  92. />
  93. </MaterialHeaderButtons>
  94. );
  95. };
  96. render() {
  97. const pageSource: NewsSourceType =
  98. NewsSourcesConstants[this.displayData.page_id as AvailablePages];
  99. return (
  100. <CollapsibleScrollView style={styles.container} hasTab>
  101. <Card.Title
  102. title={pageSource.name}
  103. subtitle={this.date}
  104. left={() => <Image source={pageSource.icon} style={styles.image} />}
  105. />
  106. {this.displayData.image ? (
  107. <ImageGalleryButton
  108. images={[{ url: this.displayData.image }]}
  109. style={styles.button}
  110. />
  111. ) : null}
  112. <Card.Content style={{ paddingBottom: TAB_BAR_HEIGHT + 20 }}>
  113. {this.displayData.message !== undefined ? (
  114. <Autolink
  115. text={this.displayData.message}
  116. hashtag={'facebook'}
  117. component={Text}
  118. truncate={32}
  119. email={true}
  120. url={true}
  121. phone={true}
  122. />
  123. ) : null}
  124. </Card.Content>
  125. </CollapsibleScrollView>
  126. );
  127. }
  128. }
  129. export default FeedItemScreen;