Search
 
SCRIPT & CODE EXAMPLE
 

TYPESCRIPT

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} />
  ) : (
    <></>
  );
}

Comment

PREVIOUS NEXT
Code Example
Typescript :: how to link locally installed fonts to css 
Typescript :: sonar ignore rule 
Typescript :: string to date in typescript 
Typescript :: selenium get all child elements python 
Typescript :: typescript loop 
Typescript :: serenity.is LinkingSetRelation add column-picker-button 
Typescript :: useWindowsize hook in react 
Typescript :: angular get current date yyyy-mm-dd 
Typescript :: react native navigation current screen 
Typescript :: insert value to the top of array in angular 
Typescript :: DbQueryEventNode 
Typescript :: typescript style type 
Typescript :: google chrome extensions content scripts matches 
Typescript :: andonis many to many attach 
Typescript :: how to take two inputs in a single line in python 
Typescript :: typescript string interpolation 
Typescript :: ionic pasword visible inside ion-input 
Typescript :: email validation pattern angular 
Typescript :: aws sts get-caller-identity extract account 
Typescript :: full call signature in ts 
Typescript :: react-native loading bar 
Typescript :: df.value_counts to dataframe 
Typescript :: vue 3 bootstrap 5 tooltip 
Typescript :: ionic 5 formarray 
Typescript :: how to get just the ports in kubernetes 
Typescript :: ts(7053) 
Typescript :: npx creat redux-typescript app 
Typescript :: how to erase elemts accoding to index c++ 
Typescript :: custom fonts vue 
Typescript :: advantages of automation 
ADD CONTENT
Topic
Content
Source link
Name
2+8 =