I am trying to add going back on webview when the android backbutton was pressed and I still couldn\'t manage to make it work.
This is my code:
class MyComponent extends Component {
state = {};
componentDidMount(){
BackHandler.addEventListener('hardwareBackPress', this.backHandler);
}
componentWillUnmount(){
BackHandler.removeEventListener('hardwareBackPress', this.backHandler);
}
backHandler = () => {
if(this.state.backButtonEnabled) {
this.refs[WEBVIEW_REF].goBack();
return true;
}
}
}
1) Bind your handler 2) Do not forget to removeListener on unmount.