Commit d794fa83 authored by norhalimah's avatar norhalimah

backhandler fixed

parent 58a0fc00
...@@ -17,7 +17,7 @@ class App extends React.PureComponent { ...@@ -17,7 +17,7 @@ class App extends React.PureComponent {
componentDidMount() { componentDidMount() {
Orientation.lockToPortrait(); Orientation.lockToPortrait();
} }
componentDidUpdate(){ componentDidUpdate() {
Orientation.lockToPortrait(); Orientation.lockToPortrait();
} }
......
...@@ -10,9 +10,11 @@ import { ...@@ -10,9 +10,11 @@ import {
StyleSheet, StyleSheet,
ScrollView, ScrollView,
Image, Image,
BackHandler,
} from 'react-native'; } from 'react-native';
import {Icon} from 'react-native-elements'; import {Icon} from 'react-native-elements';
import Orientation from 'react-native-orientation'; import Orientation from 'react-native-orientation';
const exitApp = () => BackHandler.exitApp();
class Home extends React.PureComponent { class Home extends React.PureComponent {
...@@ -26,7 +28,9 @@ class Home extends React.PureComponent { ...@@ -26,7 +28,9 @@ class Home extends React.PureComponent {
// Orientation.lockAsync(Orientation.OrientationLock.PORTRAIT_UP); // Orientation.lockAsync(Orientation.OrientationLock.PORTRAIT_UP);
} }
render() { render() {
BackHandler.addEventListener('hardwareBackPress', exitApp);
return ( return (
<View style={styles.container}> <View style={styles.container}>
<ImageBackground <ImageBackground
......
...@@ -10,6 +10,7 @@ import { ...@@ -10,6 +10,7 @@ import {
StyleSheet, StyleSheet,
ScrollView, ScrollView,
// Alert, // Alert,
BackHandler,
} from 'react-native'; } from 'react-native';
import AsyncStorage from '@react-native-async-storage/async-storage'; import AsyncStorage from '@react-native-async-storage/async-storage';
import Orientation from 'react-native-orientation'; import Orientation from 'react-native-orientation';
...@@ -43,8 +44,13 @@ class LogBook extends React.PureComponent { ...@@ -43,8 +44,13 @@ class LogBook extends React.PureComponent {
this.displayData(); this.displayData();
} }
homeExit = async () => {
this.props.navigation.navigate('1');
//Orientation.lockToPortrait();
};
render() { render() {
BackHandler.addEventListener('hardwareBackPress', this.homeExit);
return ( return (
<View style={styles.container}> <View style={styles.container}>
<ImageBackground <ImageBackground
......
...@@ -599,9 +599,9 @@ class Quiz extends React.Component { ...@@ -599,9 +599,9 @@ class Quiz extends React.Component {
} }
}; };
homeExit = () => { homeExit = async () => {
// this.props.navigation.navigate('1'); // this.props.navigation.navigate('1');
Alert.alert('Hold on!', 'Are you sure you want to stop?', [ Alert.alert('Hold on!', 'Are you sure you want to exit?', [
{ {
text: 'Cancel', text: 'Cancel',
onPress: () => null, onPress: () => null,
...@@ -617,16 +617,16 @@ class Quiz extends React.Component { ...@@ -617,16 +617,16 @@ class Quiz extends React.Component {
Orientation.lockToPortrait(); Orientation.lockToPortrait();
}; };
async componentDidMount() { componentDidMount() {
//this.removeArray(); //this.removeArray();
BackHandler.addEventListener('hardwareBackPress', this.homeExit); // BackHandler.addEventListener('hardwareBackPress', this.homeExit);
Orientation.lockToLandscape(); Orientation.lockToLandscape();
this.displayData(); this.displayData();
} }
componentWillUnmount() { componentWillUnmount() {
this.removeArray(); this.removeArray();
BackHandler.addEventListener('hardwareBackPress', this.homeExit); // BackHandler.addEventListener('hardwareBackPress', this.homeExit);
//clearInterval(this.interval); //clearInterval(this.interval);
// Orientation.lockToLandscape(); // Orientation.lockToLandscape();
} }
...@@ -752,6 +752,7 @@ this.setState({records: []}); ...@@ -752,6 +752,7 @@ this.setState({records: []});
}; };
render() { render() {
BackHandler.addEventListener('hardwareBackPress', this.homeExit);
const { const {
selectedKeywordStyle, selectedKeywordStyle,
buttonStyle, buttonStyle,
......
...@@ -12,6 +12,7 @@ import { ...@@ -12,6 +12,7 @@ import {
ScrollView, ScrollView,
Dimensions, Dimensions,
// TextInput, // TextInput,
BackHandler,
} from 'react-native'; } from 'react-native';
import Orientation from 'react-native-orientation'; import Orientation from 'react-native-orientation';
import Notes from './data'; import Notes from './data';
...@@ -172,7 +173,14 @@ export default class Settings extends React.Component { ...@@ -172,7 +173,14 @@ export default class Settings extends React.Component {
} }
} }
homeExit = async () => {
this.props.navigation.navigate('1');
//Orientation.lockToPortrait();
};
render() { render() {
BackHandler.addEventListener('hardwareBackPress', this.homeExit);
return ( return (
<View style={styles.container}> <View style={styles.container}>
<SafeAreaView> <SafeAreaView>
......
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