[Native] Error pluggable widget to disable Android device back button
0
Hi, I'm struggling trying to create a pluggable widget to disable the native back button on Android devices. So far I've followed the docs on https://reactnavigation.org/docs/4.x/custom-android-back-button-handling and https://reactnavigation.org/docs/4.x/connecting-navigation-prop to create the proper JSX but I'm failing.. I can't seem to get past: TypeError: undefined is not an object (evaluating 't.displayName') I've used the https://docs.mendix.com/howto/extensibility/build-native-widget to create an empty widget and this is my sourcefile based on the docs without much changes: import { Component } from "react"; import { BackHandler } from 'react-native'; import { withNavigation } from 'react-navigation'; class DisableDeviceBackButton extends Component { componentDidMount() { BackHandler.addEventListener( 'hardwareBackPress', this.handleBackButtonPressAndroid ); } componentWillUnmount() { BackHandler.removeEventListener( 'hardwareBackPress', this.handleBackButtonPressAndroid ); } handleBackButtonPressAndroid = () => { if (!this.props.navigation.isFocused()) { // The screen is not focused, so don't do anything return false; } if (this.isSelectionModeEnabled()) { this.disableSelectionMode(); // We have handled the back button // Return `true` to prevent react-navigation from handling it return true; } else { return true;//SS: was false } }; render() { return null; // SS:needs something to escape error of empty render function } } export default withNavigation(DisableDeviceBackButton); //SS: pass the this.navigation.props Can someone point me in the right direction? I've been endlessly tweaking, running npm run dev, sync project directory and running in Make It Native App.
asked
Sjors Schultz
2 answers
0
There might be configuration problems in your widget.xml file. Below link gives you clear idea how to declare widget properties.