"React Native: Double back press to Exit App" Code Answer's
You're definitely familiar with the best coding language TypeScript that developers use to develop their projects and they get all their queries like "React Native: Double back press to Exit App" answered properly. Developers are finding an appropriate answer about React Native: Double back press to Exit App related to the TypeScript coding language. By visiting this online portal developers get answers concerning TypeScript codes question like React Native: Double back press to Exit App. Enter your desired code related query in the search bar and get every piece of information about TypeScript code related question on React Native: Double back press to Exit App.
React Native: Double back press to Exit App
import * as React from 'react';
import {useEffect, useState} from 'react';
import {Platform, BackHandler, ToastAndroid} from 'react-native';
export const ExecuteOnlyOnAndroid = (props) => {
const {message} = props;
const [exitApp, setExitApp] = useState(0);
const backAction = () => {
setTimeout(() => {
setExitApp(0);
}, 2000); // 2 seconds to tap second-time
if (exitApp === 0) {
setExitApp(exitApp + 1);
ToastAndroid.show(message, ToastAndroid.SHORT);
} else if (exitApp === 1) {
BackHandler.exitApp();
}
return true;
};
useEffect(() => {
const backHandler = BackHandler.addEventListener(
'hardwareBackPress',
backAction,
);
return () => backHandler.remove();
});
return <></>;
};
export default function DoubleTapToClose(props) {
const {message = 'tap back again to exit the App'} = props;
return Platform.OS !== 'ios' ? (
<ExecuteOnlyOnAndroid message={message} />
) : (
<></>
);
}
Source: stackoverflow.com
All those coders who are working on the TypeScript based application and are stuck on React Native: Double back press to Exit App can get a collection of related answers to their query. Programmers need to enter their query on React Native: Double back press to Exit App related to TypeScript code and they'll get their ambiguities clear immediately. On our webpage, there are tutorials about React Native: Double back press to Exit App for the programmers working on TypeScript code while coding their module. Coders are also allowed to rectify already present answers of React Native: Double back press to Exit App while working on the TypeScript language code. Developers can add up suggestions if they deem fit any other answer relating to "React Native: Double back press to Exit App". Visit this developer's friendly online web community, CodeProZone, and get your queries like React Native: Double back press to Exit App resolved professionally and stay updated to the latest TypeScript updates.