import React from "react"; import { View, ScrollView, StyleSheet, StatusBar, Text, Dimensions, Image, Alert, BackHandler } from "react-native"; import AsyncStorage from '@react-native-async-storage/async-storage'; import SafeAreaView from 'react-native-safe-area-view'; import { Button, ButtonContainer } from "../components/Button"; import { Banner } from "../components/Banner"; import { colors, texts } from "../components/Variables"; import { examQuestions } from "../components/ExamQuestions"; import { trueFalseQuestions } from "../components/TrueFalseQuestions"; const screen = Dimensions.get("window"); const header = require("../assets/header.png"); const maxTime = 0; // 10 let interval = null; const styles = StyleSheet.create({ container: { backgroundColor: colors.dark_blue, flex: 1 }, safearea: { flex: 1, justifyContent: "space-between", paddingHorizontal: 20 }, headerContainer: { marginTop: 20, alignItems: "center", justifyContent: "center", width: "100%", height: 150 }, header: { width: "100%" }, bannerContainer: { flex: 1, alignItems: "center", justifyContent: "center" } }); class Splash extends React.Component { constructor(props) { super(props); const params = props.route.params || {}; this.state = { bannerExpanded: true, timer: maxTime, storeWrongAnswers: params.storeWrongAnswers || [], setupData: {} }; } bannerError = (e) => { //console.log("Banner error: ", e) } componentDidMount() { // Save subscription for removal later this.backHandler = BackHandler.addEventListener( 'hardwareBackPress', this.handleBackButton ); AsyncStorage.getItem('storeWrongAnswers').then((value) => { if (!value) AsyncStorage.setItem('storeWrongAnswers', JSON.stringify([])); AsyncStorage.getItem('setupData').then((setup) => { if (!setup) AsyncStorage.setItem('setupData', JSON.stringify({})); this.setState({ storeWrongAnswers: value ? JSON.parse(value) : [], setupData: setup ? JSON.parse(setup) : {} }); }); }); } componentWillUnmount() { // Remove subscription correctly this.backHandler?.remove(); if (interval) clearInterval(interval); } handleBackButton = () => { Alert.alert( texts.exit, texts.exitQuestion, [ { text: 'No', onPress: () => console.log('Cancel Pressed'), style: 'cancel' }, { text: 'Si', onPress: () => BackHandler.exitApp() }, ], { cancelable: false } ); return true; } startTimer = () => { if (this.state.timer === maxTime) { interval = setInterval(() => { this.setState((state) => ({ timer: state.timer - 1 })); }, 1000); } if (this.state.timer < 1 && interval) { clearInterval(interval); interval = null; setTimeout(() => this.setState({ bannerExpanded: false }), 500); } } render() { const { storeWrongAnswers } = this.state; this.startTimer(); return (