Commit 12a0c461 authored by norhalimah's avatar norhalimah

backhandler

parent b295c1d1
...@@ -18,10 +18,12 @@ class Home extends React.PureComponent { ...@@ -18,10 +18,12 @@ class Home extends React.PureComponent {
async componentDidMount() { async componentDidMount() {
Orientation.lockToPortrait(); Orientation.lockToPortrait();
// Orientation.lockAsync(Orientation.OrientationLock.PORTRAIT_UP);
} }
componentWillUnmount() { componentWillUnmount() {
Orientation.lockToPortrait(); Orientation.lockToPortrait();
// Orientation.lockAsync(Orientation.OrientationLock.PORTRAIT_UP);
} }
render() { render() {
......
...@@ -11,10 +11,11 @@ import { ...@@ -11,10 +11,11 @@ import {
TouchableHighlight, TouchableHighlight,
Button, Button,
Image, Image,
///Alert, Alert,
Modal, Modal,
TouchableOpacity, TouchableOpacity,
Dimensions, Dimensions,
BackHandler,
} from 'react-native'; } from 'react-native';
import {Stopwatch} from 'react-native-stopwatch-timer'; import {Stopwatch} from 'react-native-stopwatch-timer';
import Orientation from 'react-native-orientation'; import Orientation from 'react-native-orientation';
...@@ -171,8 +172,7 @@ class Quiz extends React.Component { ...@@ -171,8 +172,7 @@ class Quiz extends React.Component {
this.setState({showDone: true}); this.setState({showDone: true});
this.handlerArgCall((this.state.correct + 1), this.state.wrong, stime); this.handlerArgCall((this.state.correct + 1), this.state.wrong, stime);
console.log('finish'); console.log('finish');
this.props.navigation.navigate('1'); this.backAction();
Orientation.lockToPortrait();
} }
else { else {
keywordsList.splice(0, keywordsList.length); keywordsList.splice(0, keywordsList.length);
...@@ -185,8 +185,7 @@ class Quiz extends React.Component { ...@@ -185,8 +185,7 @@ class Quiz extends React.Component {
this.setState({showDone: true}); this.setState({showDone: true});
this.handlerArgCall(this.state.correct, (this.state.wrong + 1), stime); this.handlerArgCall(this.state.correct, (this.state.wrong + 1), stime);
console.log('finish'); console.log('finish');
this.props.navigation.navigate('1'); this.backAction();
Orientation.lockToPortrait();
} }
else { else {
this.setState({showW: true}); this.setState({showW: true});
...@@ -204,8 +203,7 @@ class Quiz extends React.Component { ...@@ -204,8 +203,7 @@ class Quiz extends React.Component {
this.setState({showDone: true}); this.setState({showDone: true});
this.handlerArgCall((this.state.correct + 1), this.state.wrong, stime); this.handlerArgCall((this.state.correct + 1), this.state.wrong, stime);
console.log('finish'); console.log('finish');
this.props.navigation.navigate('1'); this.backAction();
Orientation.lockToPortrait();
} }
else { else {
keywordsList.splice(0, keywordsList.length); keywordsList.splice(0, keywordsList.length);
...@@ -218,8 +216,7 @@ class Quiz extends React.Component { ...@@ -218,8 +216,7 @@ class Quiz extends React.Component {
this.setState({showDone: true}); this.setState({showDone: true});
this.handlerArgCall(this.state.correct, (this.state.wrong + 1), stime); this.handlerArgCall(this.state.correct, (this.state.wrong + 1), stime);
console.log('finish'); console.log('finish');
this.props.navigation.navigate('1'); this.backAction();
Orientation.lockToPortrait();
} }
else { else {
this.setState({showW: true}); this.setState({showW: true});
...@@ -237,8 +234,7 @@ class Quiz extends React.Component { ...@@ -237,8 +234,7 @@ class Quiz extends React.Component {
this.setState({showDone: true}); this.setState({showDone: true});
this.handlerArgCall((this.state.correct + 1), this.state.wrong, stime); this.handlerArgCall((this.state.correct + 1), this.state.wrong, stime);
console.log('finish'); console.log('finish');
this.props.navigation.navigate('1'); this.backAction();
Orientation.lockToPortrait();
} }
else { else {
keywordsList.splice(0, keywordsList.length); keywordsList.splice(0, keywordsList.length);
...@@ -251,8 +247,7 @@ class Quiz extends React.Component { ...@@ -251,8 +247,7 @@ class Quiz extends React.Component {
this.setState({showDone: true}); this.setState({showDone: true});
this.handlerArgCall(this.state.correct, (this.state.wrong + 1), stime); this.handlerArgCall(this.state.correct, (this.state.wrong + 1), stime);
console.log('finish'); console.log('finish');
this.props.navigation.navigate('1'); this.backAction();
Orientation.lockToPortrait();
} }
else { else {
this.setState({showW: true}); this.setState({showW: true});
...@@ -270,8 +265,7 @@ class Quiz extends React.Component { ...@@ -270,8 +265,7 @@ class Quiz extends React.Component {
this.setState({showDone: true}); this.setState({showDone: true});
this.handlerArgCall((this.state.correct + 1), this.state.wrong, stime); this.handlerArgCall((this.state.correct + 1), this.state.wrong, stime);
console.log('finish'); console.log('finish');
this.props.navigation.navigate('1'); this.backAction();
Orientation.lockToPortrait();
} }
else { else {
keywordsList.splice(0, keywordsList.length); keywordsList.splice(0, keywordsList.length);
...@@ -284,8 +278,7 @@ class Quiz extends React.Component { ...@@ -284,8 +278,7 @@ class Quiz extends React.Component {
this.setState({showDone: true}); this.setState({showDone: true});
this.handlerArgCall(this.state.correct, (this.state.wrong + 1), stime); this.handlerArgCall(this.state.correct, (this.state.wrong + 1), stime);
console.log('finish'); console.log('finish');
this.props.navigation.navigate('1'); this.backAction();
Orientation.lockToPortrait();
} }
else { else {
this.setState({showW: true}); this.setState({showW: true});
...@@ -303,8 +296,7 @@ class Quiz extends React.Component { ...@@ -303,8 +296,7 @@ class Quiz extends React.Component {
this.setState({showDone: true}); this.setState({showDone: true});
this.handlerArgCall((this.state.correct + 1), this.state.wrong, stime); this.handlerArgCall((this.state.correct + 1), this.state.wrong, stime);
console.log('finish'); console.log('finish');
this.props.navigation.navigate('1'); this.backAction();
Orientation.lockToPortrait();
} }
else { else {
keywordsList.splice(0, keywordsList.length); keywordsList.splice(0, keywordsList.length);
...@@ -317,8 +309,7 @@ class Quiz extends React.Component { ...@@ -317,8 +309,7 @@ class Quiz extends React.Component {
this.setState({showDone: true}); this.setState({showDone: true});
this.handlerArgCall(this.state.correct, (this.state.wrong + 1), stime); this.handlerArgCall(this.state.correct, (this.state.wrong + 1), stime);
console.log('finish'); console.log('finish');
this.props.navigation.navigate('1'); this.backAction();
Orientation.lockToPortrait();
} }
else { else {
this.setState({showW: true}); this.setState({showW: true});
...@@ -336,8 +327,7 @@ class Quiz extends React.Component { ...@@ -336,8 +327,7 @@ class Quiz extends React.Component {
this.setState({showDone: true}); this.setState({showDone: true});
this.handlerArgCall((this.state.correct + 1), this.state.wrong, stime); this.handlerArgCall((this.state.correct + 1), this.state.wrong, stime);
console.log('finish'); console.log('finish');
this.props.navigation.navigate('1'); this.backAction();
Orientation.lockToPortrait();
} }
else { else {
keywordsList.splice(0, keywordsList.length); keywordsList.splice(0, keywordsList.length);
...@@ -350,8 +340,7 @@ class Quiz extends React.Component { ...@@ -350,8 +340,7 @@ class Quiz extends React.Component {
this.setState({showDone: true}); this.setState({showDone: true});
this.handlerArgCall(this.state.correct, (this.state.wrong + 1), stime); this.handlerArgCall(this.state.correct, (this.state.wrong + 1), stime);
console.log('finish'); console.log('finish');
this.props.navigation.navigate('1'); this.backAction();
Orientation.lockToPortrait();
} }
else { else {
this.setState({showW: true}); this.setState({showW: true});
...@@ -369,8 +358,7 @@ class Quiz extends React.Component { ...@@ -369,8 +358,7 @@ class Quiz extends React.Component {
this.setState({showDone: true}); this.setState({showDone: true});
this.handlerArgCall((this.state.correct + 1), this.state.wrong, stime); this.handlerArgCall((this.state.correct + 1), this.state.wrong, stime);
console.log('finish'); console.log('finish');
this.props.navigation.navigate('1'); this.backAction();
Orientation.lockToPortrait();
} }
else { else {
keywordsList.splice(0, keywordsList.length); keywordsList.splice(0, keywordsList.length);
...@@ -383,8 +371,7 @@ class Quiz extends React.Component { ...@@ -383,8 +371,7 @@ class Quiz extends React.Component {
this.setState({showDone: true}); this.setState({showDone: true});
this.handlerArgCall(this.state.correct, (this.state.wrong + 1), stime); this.handlerArgCall(this.state.correct, (this.state.wrong + 1), stime);
console.log('finish'); console.log('finish');
this.props.navigation.navigate('1'); this.backAction();
Orientation.lockToPortrait();
} }
else { else {
this.setState({showW: true}); this.setState({showW: true});
...@@ -402,8 +389,7 @@ class Quiz extends React.Component { ...@@ -402,8 +389,7 @@ class Quiz extends React.Component {
this.setState({showDone: true}); this.setState({showDone: true});
this.handlerArgCall((this.state.correct + 1), this.state.wrong, stime); this.handlerArgCall((this.state.correct + 1), this.state.wrong, stime);
console.log('finish'); console.log('finish');
this.props.navigation.navigate('1'); this.backAction();
Orientation.lockToPortrait();
} }
else { else {
keywordsList.splice(0, keywordsList.length); keywordsList.splice(0, keywordsList.length);
...@@ -416,8 +402,7 @@ class Quiz extends React.Component { ...@@ -416,8 +402,7 @@ class Quiz extends React.Component {
this.setState({showDone: true}); this.setState({showDone: true});
this.handlerArgCall(this.state.correct, (this.state.wrong + 1), stime); this.handlerArgCall(this.state.correct, (this.state.wrong + 1), stime);
console.log('finish'); console.log('finish');
this.props.navigation.navigate('1'); this.backAction();
Orientation.lockToPortrait();
} }
else { else {
this.setState({showW: true}); this.setState({showW: true});
...@@ -435,8 +420,7 @@ class Quiz extends React.Component { ...@@ -435,8 +420,7 @@ class Quiz extends React.Component {
this.setState({showDone: true}); this.setState({showDone: true});
this.handlerArgCall((this.state.correct + 1), this.state.wrong, stime); this.handlerArgCall((this.state.correct + 1), this.state.wrong, stime);
console.log('finish'); console.log('finish');
this.props.navigation.navigate('1'); this.backAction();
Orientation.lockToPortrait();
} }
else { else {
keywordsList.splice(0, keywordsList.length); keywordsList.splice(0, keywordsList.length);
...@@ -449,8 +433,7 @@ class Quiz extends React.Component { ...@@ -449,8 +433,7 @@ class Quiz extends React.Component {
this.setState({showDone: true}); this.setState({showDone: true});
this.handlerArgCall(this.state.correct, (this.state.wrong + 1), stime); this.handlerArgCall(this.state.correct, (this.state.wrong + 1), stime);
console.log('finish'); console.log('finish');
this.props.navigation.navigate('1'); this.backAction();
Orientation.lockToPortrait();
} }
else { else {
this.setState({showW: true}); this.setState({showW: true});
...@@ -468,8 +451,7 @@ class Quiz extends React.Component { ...@@ -468,8 +451,7 @@ class Quiz extends React.Component {
this.setState({showDone: true}); this.setState({showDone: true});
this.handlerArgCall((this.state.correct + 1), this.state.wrong, stime); this.handlerArgCall((this.state.correct + 1), this.state.wrong, stime);
console.log('finish'); console.log('finish');
this.props.navigation.navigate('1'); this.backAction();
Orientation.lockToPortrait();
} }
else { else {
keywordsList.splice(0, keywordsList.length); keywordsList.splice(0, keywordsList.length);
...@@ -482,8 +464,7 @@ class Quiz extends React.Component { ...@@ -482,8 +464,7 @@ class Quiz extends React.Component {
this.setState({showDone: true}); this.setState({showDone: true});
this.handlerArgCall(this.state.correct, (this.state.wrong + 1), stime); this.handlerArgCall(this.state.correct, (this.state.wrong + 1), stime);
console.log('finish'); console.log('finish');
this.props.navigation.navigate('1'); this.backAction();
Orientation.lockToPortrait();
} }
else { else {
this.setState({showW: true}); this.setState({showW: true});
...@@ -501,8 +482,7 @@ class Quiz extends React.Component { ...@@ -501,8 +482,7 @@ class Quiz extends React.Component {
this.setState({showDone: true}); this.setState({showDone: true});
this.handlerArgCall((this.state.correct + 1), this.state.wrong, stime); this.handlerArgCall((this.state.correct + 1), this.state.wrong, stime);
console.log('finish'); console.log('finish');
this.props.navigation.navigate('1'); this.backAction();
Orientation.lockToPortrait();
} }
else { else {
keywordsList.splice(0, keywordsList.length); keywordsList.splice(0, keywordsList.length);
...@@ -515,8 +495,7 @@ class Quiz extends React.Component { ...@@ -515,8 +495,7 @@ class Quiz extends React.Component {
this.setState({showDone: true}); this.setState({showDone: true});
this.handlerArgCall(this.state.correct, (this.state.wrong + 1), stime); this.handlerArgCall(this.state.correct, (this.state.wrong + 1), stime);
console.log('finish'); console.log('finish');
this.props.navigation.navigate('1'); this.backAction();
Orientation.lockToPortrait();
} }
else { else {
this.setState({showW: true}); this.setState({showW: true});
...@@ -534,8 +513,7 @@ class Quiz extends React.Component { ...@@ -534,8 +513,7 @@ class Quiz extends React.Component {
this.setState({showDone: true}); this.setState({showDone: true});
this.handlerArgCall((this.state.correct + 1), this.state.wrong, stime); this.handlerArgCall((this.state.correct + 1), this.state.wrong, stime);
console.log('finish'); console.log('finish');
this.props.navigation.navigate('1'); this.backAction();
Orientation.lockToPortrait();
} }
else { else {
keywordsList.splice(0, keywordsList.length); keywordsList.splice(0, keywordsList.length);
...@@ -548,8 +526,7 @@ class Quiz extends React.Component { ...@@ -548,8 +526,7 @@ class Quiz extends React.Component {
this.setState({showDone: true}); this.setState({showDone: true});
this.handlerArgCall(this.state.correct, (this.state.wrong + 1), stime); this.handlerArgCall(this.state.correct, (this.state.wrong + 1), stime);
console.log('finish'); console.log('finish');
this.props.navigation.navigate('1'); this.backAction();
Orientation.lockToPortrait();
} }
else { else {
this.setState({showW: true}); this.setState({showW: true});
...@@ -567,8 +544,7 @@ class Quiz extends React.Component { ...@@ -567,8 +544,7 @@ class Quiz extends React.Component {
this.setState({showDone: true}); this.setState({showDone: true});
this.handlerArgCall((this.state.correct + 1), this.state.wrong, stime); this.handlerArgCall((this.state.correct + 1), this.state.wrong, stime);
console.log('finish'); console.log('finish');
this.props.navigation.navigate('1'); this.backAction();
Orientation.lockToPortrait();
} }
else { else {
keywordsList.splice(0, keywordsList.length); keywordsList.splice(0, keywordsList.length);
...@@ -581,8 +557,7 @@ class Quiz extends React.Component { ...@@ -581,8 +557,7 @@ class Quiz extends React.Component {
this.setState({showDone: true}); this.setState({showDone: true});
this.handlerArgCall(this.state.correct, (this.state.wrong + 1), stime); this.handlerArgCall(this.state.correct, (this.state.wrong + 1), stime);
console.log('finish'); console.log('finish');
this.props.navigation.navigate('1'); this.backAction();
Orientation.lockToPortrait();
} }
else { else {
this.setState({showW: true}); this.setState({showW: true});
...@@ -600,8 +575,7 @@ class Quiz extends React.Component { ...@@ -600,8 +575,7 @@ class Quiz extends React.Component {
this.setState({showDone: true}); this.setState({showDone: true});
this.handlerArgCall((this.state.correct + 1), this.state.wrong, stime); this.handlerArgCall((this.state.correct + 1), this.state.wrong, stime);
console.log('finish'); console.log('finish');
this.props.navigation.navigate('1'); this.backAction();
Orientation.lockToPortrait();
} }
else { else {
keywordsList.splice(0, keywordsList.length); keywordsList.splice(0, keywordsList.length);
...@@ -614,8 +588,7 @@ class Quiz extends React.Component { ...@@ -614,8 +588,7 @@ class Quiz extends React.Component {
this.setState({showDone: true}); this.setState({showDone: true});
this.handlerArgCall(this.state.correct, (this.state.wrong + 1), stime); this.handlerArgCall(this.state.correct, (this.state.wrong + 1), stime);
console.log('finish'); console.log('finish');
this.props.navigation.navigate('1'); this.backAction();
Orientation.lockToPortrait();
} }
else { else {
this.setState({showW: true}); this.setState({showW: true});
...@@ -626,14 +599,34 @@ class Quiz extends React.Component { ...@@ -626,14 +599,34 @@ class Quiz extends React.Component {
} }
}; };
homeExit = () => {
// this.props.navigation.navigate('1');
Alert.alert('Hold on!', 'Are you sure you want to stop?', [
{
text: 'Cancel',
onPress: () => null,
style: 'cancel',
},
{ text: 'YES', onPress: () => [ this.props.navigation.navigate('1'), Orientation.lockToPortrait()]},
]);
return true;
};
backAction = () => {
this.props.navigation.navigate('1');
Orientation.lockToPortrait();
};
async componentDidMount() { async componentDidMount() {
//this.removeArray(); //this.removeArray();
//BackHandler.addEventListener('hardwareBackPress', this.homeExit);
Orientation.lockToLandscape(); Orientation.lockToLandscape();
this.displayData(); this.displayData();
} }
componentWillUnmount() { componentWillUnmount() {
this.removeArray(); this.removeArray();
BackHandler.addEventListener('hardwareBackPress', this.homeExit);
//clearInterval(this.interval); //clearInterval(this.interval);
// Orientation.lockToLandscape(); // Orientation.lockToLandscape();
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment