// @flow import * as React from 'react'; import {Platform, StatusBar, StyleSheet, View} from 'react-native'; import type {MaterialCommunityIconsGlyphs} from 'react-native-vector-icons/MaterialCommunityIcons'; import MaterialCommunityIcons from 'react-native-vector-icons/MaterialCommunityIcons'; import i18n from 'i18n-js'; import AppIntroSlider from 'react-native-app-intro-slider'; import LinearGradient from 'react-native-linear-gradient'; import * as Animatable from 'react-native-animatable'; import {Card} from 'react-native-paper'; import Update from '../../constants/Update'; import ThemeManager from '../../managers/ThemeManager'; import Mascot, {MASCOT_STYLE} from '../Mascot/Mascot'; type PropsType = { onDone: () => void, isUpdate: boolean, isAprilFools: boolean, }; type StateType = { currentSlide: number, }; type IntroSlideType = { key: string, title: string, text: string, view: () => React.Node, mascotStyle: number, colors: [string, string], }; const styles = StyleSheet.create({ mainContent: { paddingBottom: 100, }, text: { color: 'rgba(255, 255, 255, 0.8)', backgroundColor: 'transparent', textAlign: 'center', paddingHorizontal: 16, }, title: { fontSize: 22, color: 'white', backgroundColor: 'transparent', textAlign: 'center', marginBottom: 16, }, center: { marginTop: 'auto', marginBottom: 'auto', marginRight: 'auto', marginLeft: 'auto', }, }); /** * Class used to create intro slides */ export default class CustomIntroSlider extends React.Component< PropsType, StateType, > { sliderRef: {current: null | AppIntroSlider}; introSlides: Array; updateSlides: Array; aprilFoolsSlides: Array; currentSlides: Array; /** * Generates intro slides */ constructor() { super(); this.state = { currentSlide: 0, }; this.sliderRef = React.createRef(); this.introSlides = [ { key: '0', // Mascot title: i18n.t('intro.slideMain.title'), text: i18n.t('intro.slideMain.text'), view: this.getWelcomeView, mascotStyle: MASCOT_STYLE.NORMAL, colors: ['#be1522', '#57080e'], }, { key: '1', title: i18n.t('intro.slidePlanex.title'), text: i18n.t('intro.slidePlanex.text'), view: (): React.Node => CustomIntroSlider.getIconView('calendar-clock'), mascotStyle: MASCOT_STYLE.INTELLO, colors: ['#be1522', '#57080e'], }, { key: '2', title: i18n.t('intro.slideEvents.title'), text: i18n.t('intro.slideEvents.text'), view: (): React.Node => CustomIntroSlider.getIconView('calendar-star'), mascotStyle: MASCOT_STYLE.HAPPY, colors: ['#be1522', '#57080e'], }, { key: '3', title: i18n.t('intro.slideServices.title'), text: i18n.t('intro.slideServices.text'), view: (): React.Node => CustomIntroSlider.getIconView('view-dashboard-variant'), mascotStyle: MASCOT_STYLE.CUTE, colors: ['#be1522', '#57080e'], }, { key: '4', title: i18n.t('intro.slideDone.title'), text: i18n.t('intro.slideDone.text'), view: (): React.Node => this.getEndView(), mascotStyle: MASCOT_STYLE.COOL, colors: ['#9c165b', '#3e042b'], }, ]; // $FlowFixMe this.updateSlides = []; for (let i = 0; i < Update.slidesNumber; i += 1) { this.updateSlides.push({ key: i.toString(), title: Update.getInstance().titleList[i], text: Update.getInstance().descriptionList[i], icon: Update.iconList[i], colors: Update.colorsList[i], }); } this.aprilFoolsSlides = [ { key: '1', title: i18n.t('intro.aprilFoolsSlide.title'), text: i18n.t('intro.aprilFoolsSlide.text'), view: (): React.Node => , mascotStyle: MASCOT_STYLE.NORMAL, colors: ['#e01928', '#be1522'], }, ]; } /** * Render item to be used for the intro introSlides * * @param item The item to be displayed * @param dimensions Dimensions of the item */ getIntroRenderItem = ({ item, dimensions, }: { item: IntroSlideType, dimensions: {width: number, height: number}, }): React.Node => { const {state} = this; const index = parseInt(item.key, 10); return ( {state.currentSlide === index ? ( {item.view()} {index !== 0 && index !== this.introSlides.length - 1 ? ( ) : null} {item.title} {item.text} ) : null} ); }; getEndView = (): React.Node => { return ( ); }; getWelcomeView = (): React.Node => { return ( PABLO ); }; static getIconView(icon: MaterialCommunityIconsGlyphs): React.Node { return ( ); } static setStatusBarColor(color: string) { if (Platform.OS === 'android') StatusBar.setBackgroundColor(color, true); } onSlideChange = (index: number) => { CustomIntroSlider.setStatusBarColor(this.currentSlides[index].colors[0]); this.setState({currentSlide: index}); }; onSkip = () => { CustomIntroSlider.setStatusBarColor( this.currentSlides[this.currentSlides.length - 1].colors[0], ); if (this.sliderRef.current != null) this.sliderRef.current.goToSlide(this.currentSlides.length - 1); }; onDone = () => { const {props} = this; CustomIntroSlider.setStatusBarColor( ThemeManager.getCurrentTheme().colors.surface, ); props.onDone(); }; getRenderNextButton = (): React.Node => { return ( ); }; getRenderDoneButton = (): React.Node => { return ( ); }; render(): React.Node { const {props, state} = this; this.currentSlides = this.introSlides; if (props.isUpdate) this.currentSlides = this.updateSlides; else if (props.isAprilFools) this.currentSlides = this.aprilFoolsSlides; CustomIntroSlider.setStatusBarColor(this.currentSlides[0].colors[0]); return ( ); } }