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

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