Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I disable the device back button on Android (react-native)?

How can I disable the physical device back button on Android with React-Native? I don't want to enable it for the user.

like image 305
Oskar Gusgård Avatar asked Mar 04 '23 21:03

Oskar Gusgård


2 Answers

There is no out of the box support from React Native Navigation as of today on v2. However, you could use BackHandler from React native itself. To handle it and return false to disable it.

Doc on BackHandler

Example

BackHandler.addEventListener('hardwareBackPress', function() {
  return false;
});
like image 164
Bluewings Avatar answered May 16 '23 09:05

Bluewings


In activity you can override the onBackPressed() and comment the calling to super class.

@Override
public void onBackPressed() {
  // super.onBackPressed(); comment this line to disable back button  press
}
like image 29
Velu Loganathan Avatar answered May 16 '23 08:05

Velu Loganathan