| Before Width: | Height: | Size: 185 KiB | 
| Before Width: | Height: | Size: 156 KiB | 
| Before Width: | Height: | Size: 212 KiB | 
| Before Width: | Height: | Size: 489 KiB | 
| Before Width: | Height: | Size: 305 KiB | 
| Before Width: | Height: | Size: 286 KiB | 
| Before Width: | Height: | Size: 244 KiB | 
| Before Width: | Height: | Size: 422 KiB | 
| Before Width: | Height: | Size: 521 KiB | 
| Before Width: | Height: | Size: 207 KiB | 
| Before Width: | Height: | Size: 426 KiB | 
| After Width: | Height: | Size: 605 KiB | 
| After Width: | Height: | Size: 714 KiB | 
| After Width: | Height: | Size: 330 KiB | 
| After Width: | Height: | Size: 420 KiB | 
| After Width: | Height: | Size: 592 KiB | 
| After Width: | Height: | Size: 371 KiB | 
| After Width: | Height: | Size: 370 KiB | 
| After Width: | Height: | Size: 694 KiB | 
| After Width: | Height: | Size: 678 KiB | 
| After Width: | Height: | Size: 644 KiB | 
| After Width: | Height: | Size: 569 KiB | 
| After Width: | Height: | Size: 438 KiB | 
| After Width: | Height: | Size: 478 KiB | 
| After Width: | Height: | Size: 679 KiB | 
| Before Width: | Height: | Size: 126 KiB | 
| Before Width: | Height: | Size: 89 KiB | 
| Before Width: | Height: | Size: 184 KiB | 
| Before Width: | Height: | Size: 147 KiB After Width: | Height: | Size: 219 KiB | 
| Before Width: | Height: | Size: 19 KiB After Width: | Height: | Size: 18 KiB | 
| After Width: | Height: | Size: 605 KiB | 
| After Width: | Height: | Size: 714 KiB | 
| After Width: | Height: | Size: 330 KiB | 
| After Width: | Height: | Size: 370 KiB | 
| After Width: | Height: | Size: 678 KiB | 
| After Width: | Height: | Size: 644 KiB | 
| After Width: | Height: | Size: 478 KiB | 
| After Width: | Height: | Size: 679 KiB | 
| Before Width: | Height: | Size: 14 KiB After Width: | Height: | Size: 18 KiB | 
| Before Width: | Height: | Size: 13 KiB After Width: | Height: | Size: 16 KiB | 
| Before Width: | Height: | Size: 21 KiB After Width: | Height: | Size: 24 KiB | 
| Before Width: | Height: | Size: 106 KiB After Width: | Height: | Size: 808 KiB | 
| @ -0,0 +1,47 @@ | |||||
|  | import aerodynamicsQuestions from "../data/aerodynamics" | ||||
|  | import firstAidQuestions from "../data/firstAid" | ||||
|  | import flightSafetyQuestions from "../data/flightSafety" | ||||
|  | import instrumentsQuestions from "../data/instruments" | ||||
|  | import legislationQuestions from "../data/legislation" | ||||
|  | import materialsQuestions from "../data/materials" | ||||
|  | import meteorologyQuestions from "../data/meteorology" | ||||
|  | import physiopathologyQuestions from "../data/physiopathology" | ||||
|  | import pilotingTechniquesQuestions from "../data/pilotingTechniques" | ||||
|  | 
 | ||||
|  | import { examScheme } from "../components/Variables" | ||||
|  | 
 | ||||
|  | let tmpQuestions = [] | ||||
|  | 
 | ||||
|  | const allQuestions = { | ||||
|  |   aerodynamics: aerodynamicsQuestions, | ||||
|  |   firstAid: firstAidQuestions, | ||||
|  |   flightSafety: flightSafetyQuestions, | ||||
|  |   instruments: instrumentsQuestions, | ||||
|  |   legislation: legislationQuestions, | ||||
|  |   materials: materialsQuestions, | ||||
|  |   meteorology: meteorologyQuestions, | ||||
|  |   physiopathology: physiopathologyQuestions, | ||||
|  |   pilotingTechniques: pilotingTechniquesQuestions | ||||
|  | } | ||||
|  | 
 | ||||
|  | const generateQuestions = () => { | ||||
|  |   let fullQuestions = [] | ||||
|  | 
 | ||||
|  |   examScheme.forEach( (elem) => { | ||||
|  |     let currentSection = allQuestions[elem.section] | ||||
|  |     for(let i=0; i<currentSection.length; i++) { | ||||
|  |       fullQuestions.push(currentSection[i]) | ||||
|  |     } | ||||
|  |   }) | ||||
|  | 
 | ||||
|  |   for(let i=0; i<10; i++) { | ||||
|  |     const currentIndex = Math.floor(Math.random() * fullQuestions.length) | ||||
|  |     tmpQuestions.push(fullQuestions[currentIndex]) | ||||
|  |     fullQuestions = fullQuestions.filter( (item, index) => index != currentIndex) | ||||
|  |   } | ||||
|  | 
 | ||||
|  | } | ||||
|  | 
 | ||||
|  | generateQuestions() | ||||
|  | 
 | ||||
|  | export const trueFalseQuestions = tmpQuestions | ||||
| @ -0,0 +1,193 @@ | |||||
|  | import React from "react" | ||||
|  | import { View, ScrollView, StyleSheet, StatusBar, Text, SafeAreaView, Dimensions, Image, ImageBackground, BackHandler} from "react-native" | ||||
|  | import { AdMobBanner } from "expo-ads-admob" | ||||
|  | 
 | ||||
|  | import { Button, ButtonContainer } from "../components/Button" | ||||
|  | import { colors, texts, examScheme, credentials } from "../components/Variables" | ||||
|  | 
 | ||||
|  | import aerodynamicsQuestions from "../data/aerodynamics" | ||||
|  | import firstAidQuestions from "../data/firstAid" | ||||
|  | import flightSafetyQuestions from "../data/flightSafety" | ||||
|  | import instrumentsQuestions from "../data/instruments" | ||||
|  | import legislationQuestions from "../data/legislation" | ||||
|  | import materialsQuestions from "../data/materials" | ||||
|  | import meteorologyQuestions from "../data/meteorology" | ||||
|  | import physiopathologyQuestions from "../data/physiopathology" | ||||
|  | import pilotingTechniquesQuestions from "../data/pilotingTechniques" | ||||
|  | 
 | ||||
|  | const screen = Dimensions.get("window") | ||||
|  | const header = require("../assets/header.png") | ||||
|  | const bgImage = require("../assets/bg.jpg") | ||||
|  | 
 | ||||
|  | const allQuestions = { | ||||
|  |   aerodynamics: aerodynamicsQuestions, | ||||
|  |   firstAid: firstAidQuestions, | ||||
|  |   flightSafety: flightSafetyQuestions, | ||||
|  |   instruments: instrumentsQuestions, | ||||
|  |   legislation: legislationQuestions, | ||||
|  |   materials: materialsQuestions, | ||||
|  |   meteorology: meteorologyQuestions, | ||||
|  |   physiopathology: physiopathologyQuestions, | ||||
|  |   pilotingTechniques: pilotingTechniquesQuestions | ||||
|  | } | ||||
|  | 
 | ||||
|  | const styles = StyleSheet.create({ | ||||
|  |   container: { | ||||
|  |     backgroundColor: colors.blue, | ||||
|  |     flex: 1 | ||||
|  |   }, | ||||
|  |   safearea: { | ||||
|  |     flex: 1, | ||||
|  |     marginTop: 0, | ||||
|  |     justifyContent: "space-between", | ||||
|  |     paddingHorizontal: 20, | ||||
|  |     paddingBottom: 40 | ||||
|  |   }, | ||||
|  |   headerContainer: { | ||||
|  |     marginTop: -40, | ||||
|  |     alignItems: "center", | ||||
|  |     justifyContent: "center", | ||||
|  |     width: "100%", | ||||
|  |     height: screen.width/1.5 | ||||
|  |   }, | ||||
|  |   header: { | ||||
|  |     width: "100%" | ||||
|  |   }, | ||||
|  |   box: { | ||||
|  |     marginTop: 30, | ||||
|  |     borderColor: colors.black_alpha, | ||||
|  |     borderWidth: 1, | ||||
|  |     padding: 15, | ||||
|  |     borderRadius: 5, | ||||
|  |     backgroundColor: colors.white_alpha | ||||
|  |   }, | ||||
|  |   text: { | ||||
|  |     color: colors.white, | ||||
|  |     fontSize: 20, | ||||
|  |     textAlign: "center", | ||||
|  |     fontWeight: "600", | ||||
|  |     paddingTop: 10 | ||||
|  |   }, | ||||
|  |   textBig: { | ||||
|  |     color: colors.white, | ||||
|  |     fontSize: 22, | ||||
|  |     textAlign: "center", | ||||
|  |     fontWeight: "400", | ||||
|  |     paddingBottom: 15, | ||||
|  |     textTransform: "uppercase", | ||||
|  |     textShadowColor: 'rgba(0, 0, 0, 0.75)', | ||||
|  |     textShadowOffset: {width: -1, height: 1}, | ||||
|  |     textShadowRadius: 10 | ||||
|  |   }, | ||||
|  |   bg: { | ||||
|  |     width: "100%", | ||||
|  |     height: "100%" | ||||
|  |   }, | ||||
|  |   bannerContainer: { | ||||
|  |     flex: 1, | ||||
|  |     alignItems: "center", | ||||
|  |     justifyContent: "center" | ||||
|  |   }, | ||||
|  |   banner: { | ||||
|  |     width: 320, | ||||
|  |     height: 100, | ||||
|  |     marginVertical: 20 | ||||
|  |   } | ||||
|  | }) | ||||
|  | 
 | ||||
|  | class RecapTrueFalse extends React.Component { | ||||
|  | 
 | ||||
|  |   componentDidMount() { | ||||
|  |     BackHandler.addEventListener('hardwareBackPress', this.handleBackButton) | ||||
|  |   } | ||||
|  | 
 | ||||
|  |   componentWillUnmount() { | ||||
|  |     BackHandler.removeEventListener('hardwareBackPress', this.handleBackButton) | ||||
|  |   } | ||||
|  | 
 | ||||
|  |   handleBackButton = () => { | ||||
|  | 
 | ||||
|  |     let tmpQuestions = [] | ||||
|  |     let fullQuestions = [] | ||||
|  | 
 | ||||
|  |     examScheme.forEach( (elem) => { | ||||
|  |       let currentSection = allQuestions[elem.section] | ||||
|  |       for(let i=0; i<currentSection.length; i++) { | ||||
|  |         fullQuestions.push(currentSection[i]) | ||||
|  |       } | ||||
|  |     }) | ||||
|  | 
 | ||||
|  |     for(let i=0; i<10; i++) { | ||||
|  |       const currentIndex = Math.floor(Math.random() * fullQuestions.length) | ||||
|  |       tmpQuestions.push(fullQuestions[currentIndex]) | ||||
|  |       fullQuestions = fullQuestions.filter( (item, index) => index != currentIndex) | ||||
|  |     } | ||||
|  | 
 | ||||
|  |     this.props.navigation.navigate("Splash", { | ||||
|  |       trueFalseQuestions: tmpQuestions | ||||
|  |     }) | ||||
|  |     return true | ||||
|  |   } | ||||
|  | 
 | ||||
|  |   render() { | ||||
|  | 
 | ||||
|  |     const questions = this.props.navigation.getParam("wrongAnswers", []) | ||||
|  | 
 | ||||
|  |     return ( | ||||
|  |       <View style={styles.container} > | ||||
|  |         <View style={styles.headerContainer} > | ||||
|  |           <Image source={header} style={styles.header} resizeMode="contain" /> | ||||
|  |         </View> | ||||
|  | 
 | ||||
|  |         <Text style={styles.textBig}>{texts.recapTitle}</Text> | ||||
|  | 
 | ||||
|  |         <ScrollView> | ||||
|  |           <SafeAreaView style={styles.safearea}> | ||||
|  |             {questions.map( (question, index) => ( | ||||
|  |               <View style={styles.box} key={question.id}> | ||||
|  |                 <Text style={styles.text}>{question.text}</Text> | ||||
|  | 
 | ||||
|  |                 <ButtonContainer> | ||||
|  |                   {question.answers.map( (answer, index) => { | ||||
|  |                     if(question.clicked == answer.id) { | ||||
|  |                       return ( | ||||
|  |                         <Button | ||||
|  |                           noBorder={true} | ||||
|  |                           key={answer.id} | ||||
|  |                           text={answer.text} | ||||
|  |                           colorize={{id: answer.id, clicked: question.clicked, answered: true, isCorrect: answer.correct}} | ||||
|  |                         /> | ||||
|  |                       )} | ||||
|  |                     } | ||||
|  |                   )} | ||||
|  |                 </ButtonContainer> | ||||
|  |               </View> | ||||
|  |             ))} | ||||
|  | 
 | ||||
|  |             <View style={styles.button}> | ||||
|  |               <Button | ||||
|  |                 color={colors.white_alpha2} | ||||
|  |                 hasShadow={true} | ||||
|  |                 text={texts.restart} | ||||
|  |                 onPress={() => {this.handleBackButton()} | ||||
|  |                 } | ||||
|  |               /> | ||||
|  |             </View> | ||||
|  |           </SafeAreaView> | ||||
|  | 
 | ||||
|  |           <View style={styles.bannerContainer}> | ||||
|  |             <AdMobBanner | ||||
|  |               style={styles.banner} | ||||
|  |               bannerSize="largeBanner" | ||||
|  |               adUnitID={credentials.adMobUnitIDFooter} | ||||
|  |               onDidFailToReceiveAdWithError={this.bannerError} /> | ||||
|  |           </View> | ||||
|  |         </ScrollView> | ||||
|  | 
 | ||||
|  |       </View> | ||||
|  | 
 | ||||
|  |     ) | ||||
|  |   } | ||||
|  | } | ||||
|  | 
 | ||||
|  | export default RecapTrueFalse | ||||
| @ -0,0 +1,230 @@ | |||||
|  | import React from "react" | ||||
|  | import { View, ScrollView, StyleSheet, StatusBar, Text, SafeAreaView, Dimensions, Image, BackHandler} from "react-native" | ||||
|  | 
 | ||||
|  | import { Button, ButtonContainer } from "../components/Button" | ||||
|  | import { colors, texts, examScheme } from "../components/Variables" | ||||
|  | 
 | ||||
|  | import aerodynamicsQuestions from "../data/aerodynamics" | ||||
|  | import firstAidQuestions from "../data/firstAid" | ||||
|  | import flightSafetyQuestions from "../data/flightSafety" | ||||
|  | import instrumentsQuestions from "../data/instruments" | ||||
|  | import legislationQuestions from "../data/legislation" | ||||
|  | import materialsQuestions from "../data/materials" | ||||
|  | import meteorologyQuestions from "../data/meteorology" | ||||
|  | import physiopathologyQuestions from "../data/physiopathology" | ||||
|  | import pilotingTechniquesQuestions from "../data/pilotingTechniques" | ||||
|  | 
 | ||||
|  | const screen = Dimensions.get("window") | ||||
|  | const header = require("../assets/header.png") | ||||
|  | const maxTime = 0 // 10
 | ||||
|  | let interval = null | ||||
|  | 
 | ||||
|  | const allQuestions = { | ||||
|  |   aerodynamics: aerodynamicsQuestions, | ||||
|  |   firstAid: firstAidQuestions, | ||||
|  |   flightSafety: flightSafetyQuestions, | ||||
|  |   instruments: instrumentsQuestions, | ||||
|  |   legislation: legislationQuestions, | ||||
|  |   materials: materialsQuestions, | ||||
|  |   meteorology: meteorologyQuestions, | ||||
|  |   physiopathology: physiopathologyQuestions, | ||||
|  |   pilotingTechniques: pilotingTechniquesQuestions | ||||
|  | } | ||||
|  | 
 | ||||
|  | const styles = StyleSheet.create({ | ||||
|  |   container: { | ||||
|  |     backgroundColor: colors.dark_blue, | ||||
|  |     flex: 1 | ||||
|  |   }, | ||||
|  |   safearea: { | ||||
|  |     flex: 1, | ||||
|  |     marginTop: 0, | ||||
|  |     justifyContent: "space-between", | ||||
|  |     paddingHorizontal: 20, | ||||
|  |     paddingBottom: 40 | ||||
|  |   }, | ||||
|  |   headerContainer: { | ||||
|  |     marginTop: -40, | ||||
|  |     alignItems: "center", | ||||
|  |     justifyContent: "center", | ||||
|  |     width: "100%", | ||||
|  |     height: screen.width/1.5 | ||||
|  |   }, | ||||
|  |   header: { | ||||
|  |     width: "100%" | ||||
|  |   }, | ||||
|  |   box: { | ||||
|  |     marginTop: 20, | ||||
|  |     marginBottom: 20, | ||||
|  |     marginHorizontal: 20, | ||||
|  |     width: screen.width-80, | ||||
|  |     borderRadius: 20, | ||||
|  |     borderBottomEndRadius: 80, | ||||
|  |     borderTopStartRadius: 100, | ||||
|  |     backgroundColor: colors.white_alpha, | ||||
|  |     borderColor: colors.white, | ||||
|  |     borderWidth: 2, | ||||
|  |     paddingVertical: 30 | ||||
|  |   }, | ||||
|  |   boxCorrect: { | ||||
|  |     backgroundColor: colors.green_light, | ||||
|  |   }, | ||||
|  |   boxWrong: { | ||||
|  |     backgroundColor: colors.red, | ||||
|  |   }, | ||||
|  |   boxUnsafe: { | ||||
|  |     backgroundColor: colors.orange, | ||||
|  |   }, | ||||
|  |   button: { | ||||
|  |     width: screen.width-80, | ||||
|  |     marginHorizontal: 20 | ||||
|  |   }, | ||||
|  |   text: { | ||||
|  |     color: colors.white, | ||||
|  |     fontSize: 22, | ||||
|  |     textAlign: "center", | ||||
|  |     fontWeight: "400", | ||||
|  |     lineHeight: 40, | ||||
|  |     textShadowColor: 'rgba(0, 0, 0, 0.75)', | ||||
|  |     textShadowOffset: {width: -1, height: 1}, | ||||
|  |     textShadowRadius: 10 | ||||
|  |   }, | ||||
|  |   textSmall: { | ||||
|  |     color: colors.white, | ||||
|  |     marginTop: 20, | ||||
|  |     fontSize: 26, | ||||
|  |     textAlign: "center", | ||||
|  |     fontWeight: "500", | ||||
|  |     lineHeight: 30, | ||||
|  |     textShadowColor: 'rgba(0, 0, 0, 0.75)', | ||||
|  |     textShadowOffset: {width: -1, height: 1}, | ||||
|  |     textShadowRadius: 10 | ||||
|  |   }, | ||||
|  |   textLabel: { | ||||
|  |     paddingHorizontal: 20, | ||||
|  |     paddingVertical: 20 | ||||
|  |   }, | ||||
|  |   correct: { | ||||
|  |     color: colors.green | ||||
|  |   }, | ||||
|  |   wrong: { | ||||
|  |     color: colors.red | ||||
|  |   }, | ||||
|  |   unsafe: { | ||||
|  |     color: colors.yellow | ||||
|  |   } | ||||
|  | }) | ||||
|  | 
 | ||||
|  | class Results extends React.Component { | ||||
|  | 
 | ||||
|  |   state = { | ||||
|  |     bannerExpanded: true, | ||||
|  |     timer: maxTime | ||||
|  |   } | ||||
|  | 
 | ||||
|  |   componentDidMount() { | ||||
|  |     BackHandler.addEventListener('hardwareBackPress', this.handleBackButton) | ||||
|  |   } | ||||
|  | 
 | ||||
|  |   componentWillUnmount() { | ||||
|  |     BackHandler.removeEventListener('hardwareBackPress', this.handleBackButton) | ||||
|  |   } | ||||
|  | 
 | ||||
|  |   handleBackButton = () => { | ||||
|  | 
 | ||||
|  |     let tmpQuestions = [] | ||||
|  |     let fullQuestions = [] | ||||
|  | 
 | ||||
|  |     examScheme.forEach( (elem) => { | ||||
|  |       let currentSection = allQuestions[elem.section] | ||||
|  |       for(let i=0; i<currentSection.length; i++) { | ||||
|  |         fullQuestions.push(currentSection[i]) | ||||
|  |       } | ||||
|  |     }) | ||||
|  | 
 | ||||
|  |     for(let i=0; i<10; i++) { | ||||
|  |       const currentIndex = Math.floor(Math.random() * fullQuestions.length) | ||||
|  |       tmpQuestions.push(fullQuestions[currentIndex]) | ||||
|  |       fullQuestions = fullQuestions.filter( (item, index) => index != currentIndex) | ||||
|  |     } | ||||
|  | 
 | ||||
|  |     this.props.navigation.navigate("Splash", { | ||||
|  |       trueFalseQuestions: tmpQuestions | ||||
|  |     }) | ||||
|  |     return true | ||||
|  |   } | ||||
|  | 
 | ||||
|  |   render() { | ||||
|  | 
 | ||||
|  |     const currentResults = this.props.navigation.getParam("results") | ||||
|  |     const wrongAnswers = currentResults.wrongAnswers || null | ||||
|  |     const percentage = currentResults.total ? (100/currentResults.total) * currentResults.correct : 0 | ||||
|  |     let resultStyle = '' | ||||
|  |     let boxStyle = currentResults.points >= 80 ? currentResults.points >= 85 ? styles.boxCorrect : styles.boxUnsafe : styles.boxWrong | ||||
|  | 
 | ||||
|  |     if(!currentResults.isExam) { | ||||
|  |       resultStyle = '' | ||||
|  |       boxStyle = percentage >= 80 ? percentage >= 85 ? styles.boxCorrect : styles.boxUnsafe : styles.boxWrong | ||||
|  |     } | ||||
|  | 
 | ||||
|  |     //console.log(currentResults)
 | ||||
|  | 
 | ||||
|  |     return ( | ||||
|  |       <View style={styles.container} > | ||||
|  |         <View style={styles.headerContainer} > | ||||
|  |           <Image source={header} style={styles.header} resizeMode="contain" /> | ||||
|  |         </View> | ||||
|  |         <ScrollView> | ||||
|  |           <SafeAreaView style={styles.safearea}> | ||||
|  |             <View style={[styles.box, boxStyle]}> | ||||
|  |               <Text style={styles.text}> | ||||
|  |                 <Text style={styles.textLabel}>{`${texts.corrects}: ${currentResults.correct}`}</Text> | ||||
|  |               </Text> | ||||
|  |               <Text style={styles.text}> | ||||
|  |                 <Text style={styles.textLabel}>{`${texts.wrongs}: ${currentResults.wrong}`}</Text> | ||||
|  |               </Text> | ||||
|  |               <Text style={styles.text}> | ||||
|  |                 <Text style={styles.textLabel}>{`${texts.percentage}: ${Math.round(percentage)}%`}</Text> | ||||
|  |               </Text> | ||||
|  | 
 | ||||
|  |             </View> | ||||
|  | 
 | ||||
|  |             {wrongAnswers.length ? | ||||
|  |               <View style={styles.button}> | ||||
|  |                 <Button | ||||
|  |                   color={colors.red_light} | ||||
|  |                   text={texts.recap} | ||||
|  |                   onPress={ ()=> { | ||||
|  |                     this.props.navigation.navigate("RecapTrueFalse", { | ||||
|  |                       wrongAnswers: wrongAnswers | ||||
|  |                     }) | ||||
|  |                   }}/> | ||||
|  |                 <Button | ||||
|  |                   isBig={false} | ||||
|  |                   color={colors.white_alpha} | ||||
|  |                   text={texts.restart} | ||||
|  |                   onPress={() => {this.handleBackButton()} | ||||
|  |                   } | ||||
|  |                 /> | ||||
|  | 
 | ||||
|  |               </View> : | ||||
|  |               <View style={styles.button}> | ||||
|  |                 <Button | ||||
|  |                   isBig={false} | ||||
|  |                   color={colors.white_alpha} | ||||
|  |                   text={texts.restart} | ||||
|  |                   onPress={() => {this.handleBackButton()} | ||||
|  |                   } | ||||
|  |                 /> | ||||
|  |               </View> | ||||
|  |             } | ||||
|  | 
 | ||||
|  |           </SafeAreaView> | ||||
|  |         </ScrollView> | ||||
|  | 
 | ||||
|  |       </View> | ||||
|  |     ) | ||||
|  |   } | ||||
|  | } | ||||
|  | 
 | ||||
|  | export default Results | ||||
| @ -0,0 +1,260 @@ | |||||
|  | import React from "react" | ||||
|  | import { View, ScrollView, StyleSheet, StatusBar, Text, SafeAreaView, Dimensions, ImageBackground, BackHandler } from "react-native" | ||||
|  | import { AdMobBanner } from "expo-ads-admob" | ||||
|  | 
 | ||||
|  | import { Button, ButtonContainer } from "../components/Button" | ||||
|  | import { texts, colors, examScheme, credentials } from "../components/Variables" | ||||
|  | 
 | ||||
|  | import aerodynamicsQuestions from "../data/aerodynamics" | ||||
|  | import firstAidQuestions from "../data/firstAid" | ||||
|  | import flightSafetyQuestions from "../data/flightSafety" | ||||
|  | import instrumentsQuestions from "../data/instruments" | ||||
|  | import legislationQuestions from "../data/legislation" | ||||
|  | import materialsQuestions from "../data/materials" | ||||
|  | import meteorologyQuestions from "../data/meteorology" | ||||
|  | import physiopathologyQuestions from "../data/physiopathology" | ||||
|  | import pilotingTechniquesQuestions from "../data/pilotingTechniques" | ||||
|  | 
 | ||||
|  | const allQuestions = { | ||||
|  |   aerodynamics: aerodynamicsQuestions, | ||||
|  |   firstAid: firstAidQuestions, | ||||
|  |   flightSafety: flightSafetyQuestions, | ||||
|  |   instruments: instrumentsQuestions, | ||||
|  |   legislation: legislationQuestions, | ||||
|  |   materials: materialsQuestions, | ||||
|  |   meteorology: meteorologyQuestions, | ||||
|  |   physiopathology: physiopathologyQuestions, | ||||
|  |   pilotingTechniques: pilotingTechniquesQuestions | ||||
|  | } | ||||
|  | 
 | ||||
|  | const bgImage = require("../assets/bg.jpg") | ||||
|  | const screen = Dimensions.get("window") | ||||
|  | 
 | ||||
|  | const styles = StyleSheet.create({ | ||||
|  |   container: { | ||||
|  |     flex: 1 | ||||
|  |   }, | ||||
|  |   text: { | ||||
|  |     color: colors.white, | ||||
|  |     fontSize: 20, | ||||
|  |     textAlign: "center", | ||||
|  |     fontWeight: "600", | ||||
|  |     paddingVertical: 20 | ||||
|  |   }, | ||||
|  |   textAnswer: { | ||||
|  |     color: colors.black, | ||||
|  |     backgroundColor: colors.white, | ||||
|  |     fontSize: 18, | ||||
|  |     textAlign: "center", | ||||
|  |     fontWeight: "400", | ||||
|  |     marginTop: 20, | ||||
|  |     paddingVertical: 20, | ||||
|  |     paddingHorizontal: 20, | ||||
|  |     borderRadius: 10 | ||||
|  |   }, | ||||
|  |   safearea: { | ||||
|  |     flex: 1, | ||||
|  |     paddingHorizontal: 20, | ||||
|  |     paddingTop: 40, | ||||
|  |     justifyContent: "space-between" | ||||
|  |   }, | ||||
|  |   box: { | ||||
|  |     width: screen.width, | ||||
|  |     paddingVertical: 10, | ||||
|  |     overflow: "hidden" | ||||
|  |   }, | ||||
|  |   scrollView: { | ||||
|  |     //margin: 10,
 | ||||
|  |     height: screen.height-150 | ||||
|  |   }, | ||||
|  | 
 | ||||
|  |   bg: { | ||||
|  |     width: "100%", | ||||
|  |     height: "100%" | ||||
|  |   }, | ||||
|  |   bannerContainer: { | ||||
|  |     flex: 1, | ||||
|  |     alignItems: "center", | ||||
|  |     justifyContent: "center" | ||||
|  |   }, | ||||
|  |   banner: { | ||||
|  |     flex: 1, | ||||
|  |     alignItems: "center", | ||||
|  |     justifyContent: "center", | ||||
|  |     width: 320 | ||||
|  |   } | ||||
|  | }) | ||||
|  | 
 | ||||
|  | class Quiz extends React.Component { | ||||
|  | 
 | ||||
|  |   state = { | ||||
|  |     correctCount: 0, | ||||
|  |     wrongCount: 0, | ||||
|  |     wrongAnswers: [], | ||||
|  |     totalCount: this.props.navigation.getParam("questions", []).length, | ||||
|  |     availableIds: this.props.navigation.getParam("questions", []).map(a => a.id), | ||||
|  |     activeQuestionId: this.props.navigation.getParam("questions", [])[ | ||||
|  |                         Math.floor(Math.random() * this.props.navigation.getParam("questions", []).length) | ||||
|  |                       ].id, | ||||
|  |     activeAnswerId: Math.floor(Math.random() * 3), | ||||
|  |     clickedAnswer: false, | ||||
|  |     answered: false, | ||||
|  |     results: false | ||||
|  |   } | ||||
|  | 
 | ||||
|  |   bannerError = (e) => { | ||||
|  |     console.log("Banner error (footer): ", e) | ||||
|  |   } | ||||
|  | 
 | ||||
|  |   componentDidMount() { | ||||
|  |     BackHandler.addEventListener('hardwareBackPress', this.handleBackButton) | ||||
|  |   } | ||||
|  | 
 | ||||
|  |   componentWillUnmount() { | ||||
|  |     BackHandler.removeEventListener('hardwareBackPress', this.handleBackButton) | ||||
|  |   } | ||||
|  | 
 | ||||
|  |   handleBackButton = () => { | ||||
|  | 
 | ||||
|  |     let tmpQuestions = [] | ||||
|  |     let fullQuestions = [] | ||||
|  | 
 | ||||
|  |     examScheme.forEach( (elem) => { | ||||
|  |       let currentSection = allQuestions[elem.section] | ||||
|  |       for(let i=0; i<currentSection.length; i++) { | ||||
|  |         fullQuestions.push(currentSection[i]) | ||||
|  |       } | ||||
|  |     }) | ||||
|  | 
 | ||||
|  |     for(let i=0; i<10; i++) { | ||||
|  |       const currentIndex = Math.floor(Math.random() * fullQuestions.length) | ||||
|  |       tmpQuestions.push(fullQuestions[currentIndex]) | ||||
|  |       fullQuestions = fullQuestions.filter( (item, index) => index != currentIndex) | ||||
|  |     } | ||||
|  | 
 | ||||
|  |     this.props.navigation.navigate("Splash", { | ||||
|  |       trueFalseQuestions: tmpQuestions | ||||
|  |     }) | ||||
|  |     return true | ||||
|  |   } | ||||
|  | 
 | ||||
|  |   answer = (answer, correct, id, question) => { | ||||
|  |     this.setState( | ||||
|  |       state => { | ||||
|  |         const nextState = { answered: true, clickedId: id, clickedAnswer: answer } | ||||
|  | 
 | ||||
|  |         if ((correct && answer) || (!correct && !answer)) { | ||||
|  |           //console.log('ok')
 | ||||
|  |           nextState.correctCount = state.correctCount + 1 | ||||
|  |         } else { | ||||
|  |           //console.log('ko')
 | ||||
|  |           nextState.wrongCount = state.wrongCount + 1 | ||||
|  |           nextState.wrongAnswers = state.wrongAnswers | ||||
|  |           nextState.wrongAnswers.push( | ||||
|  |             { text: question.question, | ||||
|  |               id: question.id, | ||||
|  |               clicked: question.answers[state.activeAnswerId].id, | ||||
|  |               answers: question.answers | ||||
|  |             } | ||||
|  |           ) | ||||
|  | 
 | ||||
|  |         } | ||||
|  | 
 | ||||
|  |         return nextState | ||||
|  |       }, | ||||
|  |       () => { | ||||
|  |         setTimeout(() => this.nextQuestion(), 2000) | ||||
|  |       } | ||||
|  |     ) | ||||
|  |   } | ||||
|  | 
 | ||||
|  |   nextQuestion = () => { | ||||
|  | 
 | ||||
|  |     const updatedIndexes = this.state.availableIds.filter( item => item != this.state.activeQuestionId) | ||||
|  |     const nextId = updatedIndexes[Math.floor(Math.random() * updatedIndexes.length)] | ||||
|  | 
 | ||||
|  |     if (!updatedIndexes.length) { | ||||
|  |       //console.log(this.state.wrongAnswers)
 | ||||
|  |       this.props.navigation.navigate("ResultsTrueFalse", { | ||||
|  |         results: { | ||||
|  |           isExam: false, | ||||
|  |           total: this.state.totalCount, | ||||
|  |           correct: this.state.correctCount, | ||||
|  |           wrong: this.state.wrongCount, | ||||
|  |           wrongAnswers: this.state.wrongAnswers | ||||
|  |         } | ||||
|  |       }) | ||||
|  | 
 | ||||
|  |     } else { | ||||
|  |       this.setState( (state) => { | ||||
|  |         return { | ||||
|  |           availableIds: updatedIndexes, | ||||
|  |           activeQuestionId: nextId, | ||||
|  |           activeAnswerId: Math.floor(Math.random() * 3), | ||||
|  |           answered: false | ||||
|  |         } | ||||
|  |       }) | ||||
|  |     } | ||||
|  |   } | ||||
|  | 
 | ||||
|  |   render() { | ||||
|  |     const questions = this.props.navigation.getParam("questions", []) | ||||
|  |     const question = questions.filter(item => item.id == this.state.activeQuestionId)[0] || questions[0] | ||||
|  |     const randomAnswer = question.answers[this.state.activeAnswerId] | ||||
|  | 
 | ||||
|  |     //console.log({id: randomAnswer.id, clicked: this.state.clickedId, answered: this.state.answered, isCorrect: randomAnswer.correct || false})
 | ||||
|  | 
 | ||||
|  |     return ( | ||||
|  |       <ImageBackground source={bgImage} style={styles.bg} resizeMode="cover"> | ||||
|  |         <View style={styles.box}> | ||||
|  |           <View style={styles.scrollView}> | ||||
|  | 
 | ||||
|  |             <ScrollView style={ styles.container } > | ||||
|  |               <StatusBar barStyle="light-content" /> | ||||
|  | 
 | ||||
|  |               {!this.state.results ? | ||||
|  |               <SafeAreaView style={styles.safearea}> | ||||
|  |                 <View> | ||||
|  |                   <Text style={styles.text}>{question.question}</Text> | ||||
|  |                   <Text style={styles.textAnswer}>{randomAnswer.text}</Text> | ||||
|  | 
 | ||||
|  |                   <ButtonContainer> | ||||
|  |                     <Button | ||||
|  |                       halfSize={true} | ||||
|  |                       text={texts.true} | ||||
|  |                       colorize={{id: randomAnswer.id, clicked: this.state.clickedAnswer ? randomAnswer.id : false, answered: this.state.answered, isCorrect: randomAnswer.correct || false}} | ||||
|  |                       onPress={() => this.answer(true, randomAnswer.correct || false, randomAnswer.id, question)} | ||||
|  |                     /> | ||||
|  | 
 | ||||
|  |                     <Button | ||||
|  |                       halfSize={true} | ||||
|  |                       text={texts.false} | ||||
|  |                       colorize={{id: randomAnswer.id, clicked: !this.state.clickedAnswer ? randomAnswer.id : false, answered: this.state.answered, isCorrect: !randomAnswer.correct}} | ||||
|  |                       onPress={() => this.answer(false, randomAnswer.correct || false, randomAnswer.id, question)} | ||||
|  |                     /> | ||||
|  |                   </ButtonContainer> | ||||
|  | 
 | ||||
|  |                 </View> | ||||
|  | 
 | ||||
|  |                 <Text style={styles.text}> | ||||
|  |                   {`${this.state.correctCount+this.state.wrongCount}/${this.state.totalCount}`} | ||||
|  |                 </Text> | ||||
|  |               </SafeAreaView> | ||||
|  |               : <SafeAreaView></SafeAreaView>} | ||||
|  | 
 | ||||
|  |             </ScrollView> | ||||
|  |           </View> | ||||
|  |         </View> | ||||
|  |         <View style={styles.bannerContainer}> | ||||
|  |           <AdMobBanner | ||||
|  |             style={styles.banner} | ||||
|  |             bannerSize="largeBanner" | ||||
|  |             adUnitID={credentials.adMobUnitIDFooter} | ||||
|  |             onDidFailToReceiveAdWithError={this.bannerError} /> | ||||
|  |         </View> | ||||
|  |       </ImageBackground> | ||||
|  |     ) | ||||
|  |   } | ||||
|  | } | ||||
|  | 
 | ||||
|  | export default Quiz | ||||