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.

CustomIntroSlider.js 5.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. // @flow
  2. import * as React from 'react';
  3. import {LinearGradient} from "expo-linear-gradient";
  4. import {Image, StyleSheet, View} from "react-native";
  5. import {MaterialCommunityIcons} from "@expo/vector-icons";
  6. import {Text} from "react-native-paper";
  7. import i18n from 'i18n-js';
  8. import AppIntroSlider from "react-native-app-intro-slider";
  9. import Update from "../../constants/Update";
  10. type Props = {
  11. onDone: Function,
  12. isUpdate: boolean,
  13. isAprilFools: boolean,
  14. };
  15. /**
  16. * Class used to create intro slides
  17. */
  18. export default class CustomIntroSlider extends React.Component<Props> {
  19. introSlides: Array<Object>;
  20. updateSlides: Array<Object>;
  21. aprilFoolsSlides: Array<Object>;
  22. /**
  23. * Generates intro slides
  24. */
  25. constructor() {
  26. super();
  27. this.introSlides = [
  28. {
  29. key: '1',
  30. title: i18n.t('intro.slide1.title'),
  31. text: i18n.t('intro.slide1.text'),
  32. image: require('../../../assets/splash.png'),
  33. colors: ['#e01928', '#be1522'],
  34. },
  35. {
  36. key: '2',
  37. title: i18n.t('intro.slide2.title'),
  38. text: i18n.t('intro.slide2.text'),
  39. icon: 'calendar-range',
  40. colors: ['#d99e09', '#c28d08'],
  41. },
  42. {
  43. key: '3',
  44. title: i18n.t('intro.slide3.title'),
  45. text: i18n.t('intro.slide3.text'),
  46. icon: 'washing-machine',
  47. colors: ['#1fa5ee', '#1c97da'],
  48. },
  49. {
  50. key: '4',
  51. title: i18n.t('intro.slide4.title'),
  52. text: i18n.t('intro.slide4.text'),
  53. icon: 'shopping',
  54. colors: ['#ec5904', '#da5204'],
  55. },
  56. {
  57. key: '5',
  58. title: i18n.t('intro.slide5.title'),
  59. text: i18n.t('intro.slide5.text'),
  60. icon: 'timetable',
  61. colors: ['#7c33ec', '#732fda'],
  62. },
  63. {
  64. key: '6',
  65. title: i18n.t('intro.slide6.title'),
  66. text: i18n.t('intro.slide6.text'),
  67. icon: 'silverware-fork-knife',
  68. colors: ['#ec1213', '#ff372f'],
  69. },
  70. {
  71. key: '7',
  72. title: i18n.t('intro.slide7.title'),
  73. text: i18n.t('intro.slide7.text'),
  74. icon: 'cogs',
  75. colors: ['#37c13e', '#26852b'],
  76. },
  77. ];
  78. this.updateSlides = [
  79. {
  80. key: '1',
  81. title: Update.getInstance().title,
  82. text: Update.getInstance().description,
  83. icon: Update.icon,
  84. colors: ['#e01928', '#be1522'],
  85. },
  86. ];
  87. this.aprilFoolsSlides = [
  88. {
  89. key: '1',
  90. title: i18n.t('intro.aprilFoolsSlide.title'),
  91. text: i18n.t('intro.aprilFoolsSlide.text'),
  92. icon: 'fish',
  93. colors: ['#e01928', '#be1522'],
  94. },
  95. ];
  96. }
  97. /**
  98. * Render item to be used for the intro introSlides
  99. *
  100. * @param item The item to be displayed
  101. * @param dimensions Dimensions of the item
  102. */
  103. static getIntroRenderItem({item, dimensions}: Object) {
  104. return (
  105. <LinearGradient
  106. style={[
  107. styles.mainContent,
  108. dimensions,
  109. ]}
  110. colors={item.colors}
  111. start={{x: 0, y: 0.1}}
  112. end={{x: 0.1, y: 1}}
  113. >
  114. {item.image !== undefined ?
  115. <View style={styles.image}>
  116. <Image
  117. source={item.image}
  118. resizeMode={"contain"}
  119. style={{width: '100%', height: '100%'}}
  120. />
  121. </View>
  122. : <MaterialCommunityIcons
  123. name={item.icon}
  124. color={'#fff'}
  125. size={200}/>}
  126. <View style={{marginTop: 20}}>
  127. <Text style={styles.title}>{item.title}</Text>
  128. <Text style={styles.text}>{item.text}</Text>
  129. </View>
  130. </LinearGradient>
  131. );
  132. }
  133. render() {
  134. let slides = this.introSlides;
  135. if (this.props.isUpdate)
  136. slides = this.updateSlides;
  137. else if (this.props.isAprilFools)
  138. slides = this.aprilFoolsSlides;
  139. return (
  140. <AppIntroSlider
  141. renderItem={CustomIntroSlider.getIntroRenderItem}
  142. data={slides}
  143. onDone={this.props.onDone}
  144. bottomButton
  145. showSkipButton
  146. skipLabel={i18n.t('intro.buttons.skip')}
  147. doneLabel={i18n.t('intro.buttons.done')}
  148. nextLabel={i18n.t('intro.buttons.next')}
  149. />
  150. );
  151. }
  152. }
  153. const styles = StyleSheet.create({
  154. mainContent: {
  155. flex: 1,
  156. alignItems: 'center',
  157. justifyContent: 'center',
  158. paddingBottom: 100
  159. },
  160. image: {
  161. width: 300,
  162. height: 300,
  163. marginBottom: -50,
  164. },
  165. text: {
  166. color: 'rgba(255, 255, 255, 0.8)',
  167. backgroundColor: 'transparent',
  168. textAlign: 'center',
  169. paddingHorizontal: 16,
  170. },
  171. title: {
  172. fontSize: 22,
  173. color: 'white',
  174. backgroundColor: 'transparent',
  175. textAlign: 'center',
  176. marginBottom: 16,
  177. },
  178. });