2020-09-30 18:19:35 +02:00
|
|
|
import { Component, ReactNode, createElement } from "react";
|
|
|
|
|
import { TextStyle, ViewStyle, BackHandler, View } from "react-native";
|
|
|
|
|
|
|
|
|
|
import { Style } from "@mendix/pluggable-widgets-tools";
|
|
|
|
|
|
|
|
|
|
import { BackhandlerProps } from "../typings/BackhandlerProps";
|
|
|
|
|
|
|
|
|
|
export interface CustomStyle extends Style {
|
|
|
|
|
container: ViewStyle;
|
|
|
|
|
label: TextStyle;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export class Backhandler extends Component<BackhandlerProps<CustomStyle>> {
|
|
|
|
|
constructor(props: BackhandlerProps<CustomStyle>){
|
|
|
|
|
super(props)
|
|
|
|
|
this.handleBackButtonClick = this.handleBackButtonClick.bind(this);
|
|
|
|
|
}
|
|
|
|
|
|
2020-10-01 10:30:49 +02:00
|
|
|
//We have to have a render block, or else Mendix Native will crash. Render block is expected.
|
2020-09-30 18:19:35 +02:00
|
|
|
render(): ReactNode {
|
|
|
|
|
return (
|
|
|
|
|
<View></View>
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
|
2020-10-29 10:20:36 +01:00
|
|
|
componentDidMount() {
|
2020-10-01 10:30:49 +02:00
|
|
|
BackHandler.addEventListener('hardwareBackPress', this.handleBackButtonClick);
|
2020-09-30 18:19:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
componentWillUnmount() {
|
|
|
|
|
BackHandler.removeEventListener('hardwareBackPress', this.handleBackButtonClick);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
handleBackButtonClick() {
|
2020-10-01 10:30:49 +02:00
|
|
|
this.props.onBack?.execute();
|
2020-09-30 18:19:35 +02:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|