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.

AboutScreen.js 9.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  1. // @flow
  2. import * as React from 'react';
  3. import {FlatList, Linking, Platform, View} from 'react-native';
  4. import {Body, Card, CardItem, Container, Content, H1, Left, Right, Text, Thumbnail} from 'native-base';
  5. import CustomHeader from "../../components/CustomHeader";
  6. import i18n from "i18n-js";
  7. import appJson from '../../app';
  8. import packageJson from '../../package';
  9. import CustomMaterialIcon from "../../components/CustomMaterialIcon";
  10. import AsyncStorageManager from "../../utils/AsyncStorageManager";
  11. const links = {
  12. appstore: 'https://qwant.com',
  13. playstore: 'https://play.google.com/store/apps/details?id=fr.amicaleinsat.application',
  14. expo: 'https://expo.io/@amicaleinsat/application-amicale',
  15. git: 'https://git.srv-falcon.etud.insa-toulouse.fr/vergnet/application-amicale/src/branch/master/README.md',
  16. bugs: 'https://git.srv-falcon.etud.insa-toulouse.fr/vergnet/application-amicale/issues',
  17. changelog: 'https://git.srv-falcon.etud.insa-toulouse.fr/vergnet/application-amicale/src/branch/master/Changelog.md',
  18. license: 'https://git.srv-falcon.etud.insa-toulouse.fr/vergnet/application-amicale/src/branch/master/LICENSE',
  19. mail: "mailto:vergnet@etud.insa-toulouse.fr?subject=Application Amicale INSA Toulouse&body=",
  20. linkedin: 'https://www.linkedin.com/in/arnaud-vergnet-434ba5179/',
  21. facebook: 'https://www.facebook.com/arnaud.vergnet',
  22. react: 'https://facebook.github.io/react-native/',
  23. };
  24. type Props = {
  25. navigation: Object,
  26. };
  27. type State = {
  28. isDebugUnlocked: boolean,
  29. };
  30. /**
  31. * Opens a link in the device's browser
  32. * @param link The link to open
  33. */
  34. function openWebLink(link) {
  35. Linking.openURL(link).catch((err) => console.error('Error opening link', err));
  36. }
  37. /**
  38. * Class defining an about screen. This screen shows the user information about the app and it's author.
  39. */
  40. export default class AboutScreen extends React.Component<Props, State> {
  41. debugTapCounter = 0;
  42. state = {
  43. isDebugUnlocked: AsyncStorageManager.getInstance().preferences.debugUnlocked.current === '1'
  44. };
  45. /**
  46. * Data to be displayed in the app card
  47. */
  48. appData: Array<Object> = [
  49. {
  50. onPressCallback: () => openWebLink(Platform.OS === "ios" ? links.appstore : links.playstore),
  51. icon: Platform.OS === "ios" ? 'apple' : 'google-play',
  52. text: Platform.OS === "ios" ? i18n.t('aboutScreen.appstore') : i18n.t('aboutScreen.playstore'),
  53. showChevron: true
  54. },
  55. {
  56. onPressCallback: () => openWebLink(links.expo),
  57. icon: 'worker',
  58. text: i18n.t('aboutScreen.expoBeta'),
  59. showChevron: true
  60. },
  61. {
  62. onPressCallback: () => openWebLink(links.git),
  63. icon: 'git',
  64. text: 'Git',
  65. showChevron: true
  66. },
  67. {
  68. onPressCallback: () => openWebLink(links.bugs),
  69. icon: 'bug',
  70. text: i18n.t('aboutScreen.bugs'),
  71. showChevron: true
  72. },
  73. {
  74. onPressCallback: () => openWebLink(links.changelog),
  75. icon: 'refresh',
  76. text: i18n.t('aboutScreen.changelog'),
  77. showChevron: true
  78. },
  79. {
  80. onPressCallback: () => openWebLink(links.license),
  81. icon: 'file-document',
  82. text: i18n.t('aboutScreen.license'),
  83. showChevron: true
  84. },
  85. {
  86. onPressCallback: () => this.props.navigation.navigate('DebugScreen'),
  87. icon: 'bug-check',
  88. text: i18n.t('aboutScreen.debug'),
  89. showChevron: true,
  90. showOnlyDebug: true
  91. },
  92. ];
  93. /**
  94. * Data to be displayed in the author card
  95. */
  96. authorData: Array<Object> = [
  97. {
  98. onPressCallback: () => this.tryUnlockDebugMode(),
  99. icon: 'account-circle',
  100. text: 'Arnaud VERGNET',
  101. showChevron: false
  102. },
  103. {
  104. onPressCallback: () => openWebLink(links.mail),
  105. icon: 'email',
  106. text: i18n.t('aboutScreen.mail'),
  107. showChevron: true
  108. },
  109. {
  110. onPressCallback: () => openWebLink(links.linkedin),
  111. icon: 'linkedin',
  112. text: 'Linkedin',
  113. showChevron: true
  114. },
  115. {
  116. onPressCallback: () => openWebLink(links.facebook),
  117. icon: 'facebook',
  118. text: 'Facebook',
  119. showChevron: true
  120. },
  121. ];
  122. /**
  123. * Data to be displayed in the technologies card
  124. */
  125. technoData: Array<Object> = [
  126. {
  127. onPressCallback: () => openWebLink(links.react),
  128. icon: 'react',
  129. text: i18n.t('aboutScreen.reactNative'),
  130. showChevron: false
  131. },
  132. {
  133. onPressCallback: () => this.props.navigation.navigate('AboutDependenciesScreen', {data: packageJson.dependencies}),
  134. icon: 'developer-board',
  135. text: i18n.t('aboutScreen.libs'),
  136. showChevron: true
  137. },
  138. ];
  139. /**
  140. * Get a clickable card item to be rendered inside a card.
  141. *
  142. * @param onPressCallback The callback to use when the item is clicked
  143. * @param icon The icon name to use from MaterialCommunityIcons
  144. * @param text The text to show
  145. * @param showChevron Whether to show a chevron indicating this button will change screen
  146. * @param showOnlyInDebug Should we show te current item only in debug mode?
  147. * @returns {React.Node}
  148. */
  149. getCardItem(onPressCallback: Function, icon: string, text: string, showChevron: boolean, showOnlyInDebug: boolean) {
  150. let shouldShow = !showOnlyInDebug || (showOnlyInDebug && this.state.isDebugUnlocked);
  151. if (shouldShow) {
  152. return (
  153. <CardItem button
  154. onPress={onPressCallback}>
  155. <Left>
  156. <CustomMaterialIcon icon={icon}/>
  157. <Text>{text}</Text>
  158. </Left>
  159. {showChevron ?
  160. <Right>
  161. <CustomMaterialIcon icon="chevron-right"
  162. fontSize={20}/>
  163. </Right>
  164. :
  165. <Right/>
  166. }
  167. </CardItem>)
  168. ;
  169. } else {
  170. return <View/>
  171. }
  172. }
  173. tryUnlockDebugMode() {
  174. this.debugTapCounter = this.debugTapCounter + 1;
  175. console.log(this.debugTapCounter);
  176. if (this.debugTapCounter >= 4) {
  177. this.unlockDebugMode();
  178. }
  179. }
  180. unlockDebugMode() {
  181. console.log('unlocked');
  182. this.setState({isDebugUnlocked: true});
  183. let key = AsyncStorageManager.getInstance().preferences.debugUnlocked.key;
  184. AsyncStorageManager.getInstance().savePref(key, '1');
  185. }
  186. render() {
  187. const nav = this.props.navigation;
  188. return (
  189. <Container>
  190. <CustomHeader navigation={nav} title={i18n.t('screens.about')} hasBackButton={true}/>
  191. <Content padder>
  192. <Card>
  193. <CardItem>
  194. <Left>
  195. <Thumbnail square source={require('../../assets/icon.png')}/>
  196. <Body>
  197. <H1>{appJson.expo.name}</H1>
  198. <Text note>
  199. v.{appJson.expo.version}
  200. </Text>
  201. </Body>
  202. </Left>
  203. </CardItem>
  204. <FlatList
  205. data={this.appData}
  206. extraData={this.state}
  207. keyExtractor={(item) => item.icon}
  208. renderItem={({item}) =>
  209. this.getCardItem(item.onPressCallback, item.icon, item.text, item.showChevron, item.showOnlyDebug)
  210. }
  211. />
  212. </Card>
  213. <Card>
  214. <CardItem header>
  215. <Text>{i18n.t('aboutScreen.author')}</Text>
  216. </CardItem>
  217. <FlatList
  218. data={this.authorData}
  219. extraData={this.state}
  220. keyExtractor={(item) => item.icon}
  221. renderItem={({item}) =>
  222. this.getCardItem(item.onPressCallback, item.icon, item.text, item.showChevron, item.showOnlyDebug)
  223. }
  224. />
  225. </Card>
  226. <Card>
  227. <CardItem header>
  228. <Text>{i18n.t('aboutScreen.technologies')}</Text>
  229. </CardItem>
  230. <FlatList
  231. data={this.technoData}
  232. extraData={this.state}
  233. keyExtractor={(item) => item.icon}
  234. renderItem={({item}) =>
  235. this.getCardItem(item.onPressCallback, item.icon, item.text, item.showChevron, item.showOnlyDebug)
  236. }
  237. />
  238. </Card>
  239. </Content>
  240. </Container>
  241. );
  242. }
  243. }