Commit 12a0c461 authored by norhalimah's avatar norhalimah

backhandler

parent b295c1d1
......@@ -18,10 +18,12 @@ class Home extends React.PureComponent {
async componentDidMount() {
Orientation.lockToPortrait();
// Orientation.lockAsync(Orientation.OrientationLock.PORTRAIT_UP);
}
componentWillUnmount() {
Orientation.lockToPortrait();
Orientation.lockToPortrait();
// Orientation.lockAsync(Orientation.OrientationLock.PORTRAIT_UP);
}
render() {
......
......@@ -11,10 +11,11 @@ import {
TouchableHighlight,
Button,
Image,
///Alert,
Alert,
Modal,
TouchableOpacity,
Dimensions,
BackHandler,
} from 'react-native';
import {Stopwatch} from 'react-native-stopwatch-timer';
import Orientation from 'react-native-orientation';
......@@ -171,8 +172,7 @@ class Quiz extends React.Component {
this.setState({showDone: true});
this.handlerArgCall((this.state.correct + 1), this.state.wrong, stime);
console.log('finish');
this.props.navigation.navigate('1');
Orientation.lockToPortrait();
this.backAction();
}
else {
keywordsList.splice(0, keywordsList.length);
......@@ -185,8 +185,7 @@ class Quiz extends React.Component {
this.setState({showDone: true});
this.handlerArgCall(this.state.correct, (this.state.wrong + 1), stime);
console.log('finish');
this.props.navigation.navigate('1');
Orientation.lockToPortrait();
this.backAction();
}
else {
this.setState({showW: true});
......@@ -204,8 +203,7 @@ class Quiz extends React.Component {
this.setState({showDone: true});
this.handlerArgCall((this.state.correct + 1), this.state.wrong, stime);
console.log('finish');
this.props.navigation.navigate('1');
Orientation.lockToPortrait();
this.backAction();
}
else {
keywordsList.splice(0, keywordsList.length);
......@@ -218,8 +216,7 @@ class Quiz extends React.Component {
this.setState({showDone: true});
this.handlerArgCall(this.state.correct, (this.state.wrong + 1), stime);
console.log('finish');
this.props.navigation.navigate('1');
Orientation.lockToPortrait();
this.backAction();
}
else {
this.setState({showW: true});
......@@ -237,8 +234,7 @@ class Quiz extends React.Component {
this.setState({showDone: true});
this.handlerArgCall((this.state.correct + 1), this.state.wrong, stime);
console.log('finish');
this.props.navigation.navigate('1');
Orientation.lockToPortrait();
this.backAction();
}
else {
keywordsList.splice(0, keywordsList.length);
......@@ -251,8 +247,7 @@ class Quiz extends React.Component {
this.setState({showDone: true});
this.handlerArgCall(this.state.correct, (this.state.wrong + 1), stime);
console.log('finish');
this.props.navigation.navigate('1');
Orientation.lockToPortrait();
this.backAction();
}
else {
this.setState({showW: true});
......@@ -270,8 +265,7 @@ class Quiz extends React.Component {
this.setState({showDone: true});
this.handlerArgCall((this.state.correct + 1), this.state.wrong, stime);
console.log('finish');
this.props.navigation.navigate('1');
Orientation.lockToPortrait();
this.backAction();
}
else {
keywordsList.splice(0, keywordsList.length);
......@@ -284,8 +278,7 @@ class Quiz extends React.Component {
this.setState({showDone: true});
this.handlerArgCall(this.state.correct, (this.state.wrong + 1), stime);
console.log('finish');
this.props.navigation.navigate('1');
Orientation.lockToPortrait();
this.backAction();
}
else {
this.setState({showW: true});
......@@ -298,13 +291,12 @@ class Quiz extends React.Component {
ansFMajor = () => {
if (keywordsList.toString() === 'F1,G1,A1,A#1,C2,D2,E2,F2') {
if ( (this.state.count + 1) > this.state.maxCount) {
if ( (this.state.count + 1) > this.state.maxCount) {
this.setState({correct : this.state.correct + 1});
this.setState({showDone: true});
this.handlerArgCall((this.state.correct + 1), this.state.wrong, stime);
console.log('finish');
this.props.navigation.navigate('1');
Orientation.lockToPortrait();
this.backAction();
}
else {
keywordsList.splice(0, keywordsList.length);
......@@ -317,8 +309,7 @@ class Quiz extends React.Component {
this.setState({showDone: true});
this.handlerArgCall(this.state.correct, (this.state.wrong + 1), stime);
console.log('finish');
this.props.navigation.navigate('1');
Orientation.lockToPortrait();
this.backAction();
}
else {
this.setState({showW: true});
......@@ -330,14 +321,13 @@ class Quiz extends React.Component {
};
ansEbMajor = () => {
if (keywordsList.toString() === 'D#1,F1,G1,G#1,A#1,C2,D2,D#2') {
if (keywordsList.toString() === 'D#1,F1,G1,G#1,A#1,C2,D2,D#2') {
if ( (this.state.count + 1) > this.state.maxCount) {
this.setState({correct : this.state.correct + 1});
this.setState({showDone: true});
this.handlerArgCall((this.state.correct + 1), this.state.wrong, stime);
console.log('finish');
this.props.navigation.navigate('1');
Orientation.lockToPortrait();
this.backAction();
}
else {
keywordsList.splice(0, keywordsList.length);
......@@ -350,8 +340,7 @@ class Quiz extends React.Component {
this.setState({showDone: true});
this.handlerArgCall(this.state.correct, (this.state.wrong + 1), stime);
console.log('finish');
this.props.navigation.navigate('1');
Orientation.lockToPortrait();
this.backAction();
}
else {
this.setState({showW: true});
......@@ -369,8 +358,7 @@ class Quiz extends React.Component {
this.setState({showDone: true});
this.handlerArgCall((this.state.correct + 1), this.state.wrong, stime);
console.log('finish');
this.props.navigation.navigate('1');
Orientation.lockToPortrait();
this.backAction();
}
else {
keywordsList.splice(0, keywordsList.length);
......@@ -383,8 +371,7 @@ class Quiz extends React.Component {
this.setState({showDone: true});
this.handlerArgCall(this.state.correct, (this.state.wrong + 1), stime);
console.log('finish');
this.props.navigation.navigate('1');
Orientation.lockToPortrait();
this.backAction();
}
else {
this.setState({showW: true});
......@@ -402,8 +389,7 @@ class Quiz extends React.Component {
this.setState({showDone: true});
this.handlerArgCall((this.state.correct + 1), this.state.wrong, stime);
console.log('finish');
this.props.navigation.navigate('1');
Orientation.lockToPortrait();
this.backAction();
}
else {
keywordsList.splice(0, keywordsList.length);
......@@ -416,8 +402,7 @@ class Quiz extends React.Component {
this.setState({showDone: true});
this.handlerArgCall(this.state.correct, (this.state.wrong + 1), stime);
console.log('finish');
this.props.navigation.navigate('1');
Orientation.lockToPortrait();
this.backAction();
}
else {
this.setState({showW: true});
......@@ -429,14 +414,13 @@ class Quiz extends React.Component {
};
ansAMajor = () => {
if (keywordsList.toString() === 'A1,B1,C#2,D2,E2,F#2,G#2,A2') {
if (keywordsList.toString() === 'A1,B1,C#2,D2,E2,F#2,G#2,A2') {
if ( (this.state.count + 1) > this.state.maxCount) {
this.setState({correct : this.state.correct + 1});
this.setState({showDone: true});
this.handlerArgCall((this.state.correct + 1), this.state.wrong, stime);
console.log('finish');
this.props.navigation.navigate('1');
Orientation.lockToPortrait();
this.backAction();
}
else {
keywordsList.splice(0, keywordsList.length);
......@@ -449,8 +433,7 @@ class Quiz extends React.Component {
this.setState({showDone: true});
this.handlerArgCall(this.state.correct, (this.state.wrong + 1), stime);
console.log('finish');
this.props.navigation.navigate('1');
Orientation.lockToPortrait();
this.backAction();
}
else {
this.setState({showW: true});
......@@ -462,14 +445,13 @@ class Quiz extends React.Component {
};
ansBMajor = () => {
if (keywordsList.toString() === 'B1,C#2,D#2,E2,F#2,G#2,A#2,B2') {
if (keywordsList.toString() === 'B1,C#2,D#2,E2,F#2,G#2,A#2,B2') {
if ( (this.state.count + 1) > this.state.maxCount) {
this.setState({correct : this.state.correct + 1});
this.setState({showDone: true});
this.handlerArgCall((this.state.correct + 1), this.state.wrong, stime);
console.log('finish');
this.props.navigation.navigate('1');
Orientation.lockToPortrait();
this.backAction();
}
else {
keywordsList.splice(0, keywordsList.length);
......@@ -482,8 +464,7 @@ class Quiz extends React.Component {
this.setState({showDone: true});
this.handlerArgCall(this.state.correct, (this.state.wrong + 1), stime);
console.log('finish');
this.props.navigation.navigate('1');
Orientation.lockToPortrait();
this.backAction();
}
else {
this.setState({showW: true});
......@@ -501,8 +482,7 @@ class Quiz extends React.Component {
this.setState({showDone: true});
this.handlerArgCall((this.state.correct + 1), this.state.wrong, stime);
console.log('finish');
this.props.navigation.navigate('1');
Orientation.lockToPortrait();
this.backAction();
}
else {
keywordsList.splice(0, keywordsList.length);
......@@ -515,8 +495,7 @@ class Quiz extends React.Component {
this.setState({showDone: true});
this.handlerArgCall(this.state.correct, (this.state.wrong + 1), stime);
console.log('finish');
this.props.navigation.navigate('1');
Orientation.lockToPortrait();
this.backAction();
}
else {
this.setState({showW: true});
......@@ -534,8 +513,7 @@ class Quiz extends React.Component {
this.setState({showDone: true});
this.handlerArgCall((this.state.correct + 1), this.state.wrong, stime);
console.log('finish');
this.props.navigation.navigate('1');
Orientation.lockToPortrait();
this.backAction();
}
else {
keywordsList.splice(0, keywordsList.length);
......@@ -548,8 +526,7 @@ class Quiz extends React.Component {
this.setState({showDone: true});
this.handlerArgCall(this.state.correct, (this.state.wrong + 1), stime);
console.log('finish');
this.props.navigation.navigate('1');
Orientation.lockToPortrait();
this.backAction();
}
else {
this.setState({showW: true});
......@@ -561,14 +538,13 @@ class Quiz extends React.Component {
};
ansAbMajor = () => {
if (keywordsList.toString() === 'G#1,A#1,C2,C#2,D#2,F2,G2,G#2') {
if (keywordsList.toString() === 'G#1,A#1,C2,C#2,D#2,F2,G2,G#2') {
if ( (this.state.count + 1) > this.state.maxCount) {
this.setState({correct : this.state.correct + 1});
this.setState({showDone: true});
this.handlerArgCall((this.state.correct + 1), this.state.wrong, stime);
console.log('finish');
this.props.navigation.navigate('1');
Orientation.lockToPortrait();
this.backAction();
}
else {
keywordsList.splice(0, keywordsList.length);
......@@ -581,8 +557,7 @@ class Quiz extends React.Component {
this.setState({showDone: true});
this.handlerArgCall(this.state.correct, (this.state.wrong + 1), stime);
console.log('finish');
this.props.navigation.navigate('1');
Orientation.lockToPortrait();
this.backAction();
}
else {
this.setState({showW: true});
......@@ -600,8 +575,7 @@ class Quiz extends React.Component {
this.setState({showDone: true});
this.handlerArgCall((this.state.correct + 1), this.state.wrong, stime);
console.log('finish');
this.props.navigation.navigate('1');
Orientation.lockToPortrait();
this.backAction();
}
else {
keywordsList.splice(0, keywordsList.length);
......@@ -614,8 +588,7 @@ class Quiz extends React.Component {
this.setState({showDone: true});
this.handlerArgCall(this.state.correct, (this.state.wrong + 1), stime);
console.log('finish');
this.props.navigation.navigate('1');
Orientation.lockToPortrait();
this.backAction();
}
else {
this.setState({showW: true});
......@@ -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() {
//this.removeArray();
//BackHandler.addEventListener('hardwareBackPress', this.homeExit);
Orientation.lockToLandscape();
this.displayData();
}
componentWillUnmount() {
this.removeArray();
BackHandler.addEventListener('hardwareBackPress', this.homeExit);
//clearInterval(this.interval);
// 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