Changed boolean to event, to execute in Mendix

This commit is contained in:
bartonstee
2020-10-01 10:30:49 +02:00
committed by GitHub
parent 66cb4817cb
commit 786b48de7d
8 changed files with 28 additions and 42 deletions

View File

@@ -1,25 +1,17 @@
## Backhandler ## Backhandler
Widget to disregard back events on page when using Mendix Native. [Disregard back events on page]
## Features
[feature highlights]
## Usage ## Usage
For development: [step by step instructions]
Create customwidgets folder in root of project directory
Git clone this repo into customwidgets folder
Open command prompt in cloned folder
npm i
npm run dev / npm run build
Widget can now be used inside Mendix.
For plain usage:
Copy MPK file in releases to widgets directory.
## Demo project ## Demo project
Not available yet. [link to sandbox]
## Issues, suggestions and feature requests ## Issues, suggestions and feature requests
https://github.com/IncentroBA/backhandler/issues [link to GitHub issues]
## Development and contribution ## Development and contribution
N/A [specify contribute]

Binary file not shown.

View File

@@ -7,13 +7,10 @@
<description>Disregard back events on page</description> <description>Disregard back events on page</description>
<icon/> <icon/>
<properties> <properties>
<propertyGroup caption="General"> <propertyGroup caption="Events">
<property key="disableBack" type="attribute" required="true"> <property key="onBack" type="action" required="false">
<caption>Disable</caption> <caption>On backpress</caption>
<description>Boolean for enabling/disabling backhandler</description> <description>Flow to call when hardware backbutton is used.</description>
<attributeTypes>
<attributeType name="Boolean"/>
</attributeTypes>
</property> </property>
</propertyGroup> </propertyGroup>
</properties> </properties>

View File

@@ -112,14 +112,14 @@ class Backhandler extends react__WEBPACK_IMPORTED_MODULE_0__["Component"] {
return (Object(react__WEBPACK_IMPORTED_MODULE_0__["createElement"])(react_native__WEBPACK_IMPORTED_MODULE_1__["View"], null)); return (Object(react__WEBPACK_IMPORTED_MODULE_0__["createElement"])(react_native__WEBPACK_IMPORTED_MODULE_1__["View"], null));
} }
componentWillMount() { componentWillMount() {
if (this.props.disableBack) {
react_native__WEBPACK_IMPORTED_MODULE_1__["BackHandler"].addEventListener('hardwareBackPress', this.handleBackButtonClick); react_native__WEBPACK_IMPORTED_MODULE_1__["BackHandler"].addEventListener('hardwareBackPress', this.handleBackButtonClick);
} }
}
componentWillUnmount() { componentWillUnmount() {
react_native__WEBPACK_IMPORTED_MODULE_1__["BackHandler"].removeEventListener('hardwareBackPress', this.handleBackButtonClick); react_native__WEBPACK_IMPORTED_MODULE_1__["BackHandler"].removeEventListener('hardwareBackPress', this.handleBackButtonClick);
} }
handleBackButtonClick() { handleBackButtonClick() {
var _a;
(_a = this.props.onBack) === null || _a === void 0 ? void 0 : _a.execute();
return true; return true;
} }
} }

File diff suppressed because one or more lines are too long

View File

@@ -16,6 +16,7 @@ export class Backhandler extends Component<BackhandlerProps<CustomStyle>> {
this.handleBackButtonClick = this.handleBackButtonClick.bind(this); this.handleBackButtonClick = this.handleBackButtonClick.bind(this);
} }
//We have to have a render block, or else Mendix Native will crash. Render block is expected.
render(): ReactNode { render(): ReactNode {
return ( return (
<View></View> <View></View>
@@ -23,16 +24,15 @@ export class Backhandler extends Component<BackhandlerProps<CustomStyle>> {
} }
componentWillMount() { componentWillMount() {
if (this.props.disableBack) {
BackHandler.addEventListener('hardwareBackPress', this.handleBackButtonClick); BackHandler.addEventListener('hardwareBackPress', this.handleBackButtonClick);
} }
}
componentWillUnmount() { componentWillUnmount() {
BackHandler.removeEventListener('hardwareBackPress', this.handleBackButtonClick); BackHandler.removeEventListener('hardwareBackPress', this.handleBackButtonClick);
} }
handleBackButtonClick() { handleBackButtonClick() {
this.props.onBack?.execute();
return true; return true;
} }
} }

View File

@@ -7,13 +7,10 @@
<description>Disregard back events on page</description> <description>Disregard back events on page</description>
<icon/> <icon/>
<properties> <properties>
<propertyGroup caption="General"> <propertyGroup caption="Events">
<property key="disableBack" type="attribute" required="true"> <property key="onBack" type="action" required="false">
<caption>Disable</caption> <caption>On backpress</caption>
<description>Boolean for enabling/disabling backhandler</description> <description>Flow to call when hardware backbutton is used.</description>
<attributeTypes>
<attributeType name="Boolean"/>
</attributeTypes>
</property> </property>
</propertyGroup> </propertyGroup>
</properties> </properties>

View File

@@ -3,16 +3,16 @@
* WARNING: All changes made to this file will be overwritten * WARNING: All changes made to this file will be overwritten
* @author Mendix UI Content Team * @author Mendix UI Content Team
*/ */
import { EditableValue } from "mendix"; import { ActionValue } from "mendix";
export interface BackhandlerProps<Style> { export interface BackhandlerProps<Style> {
name: string; name: string;
style: Style[]; style: Style[];
disableBack: EditableValue<boolean>; onBack?: ActionValue;
} }
export interface BackhandlerPreviewProps { export interface BackhandlerPreviewProps {
class: string; class: string;
style: string; style: string;
disableBack: string; onBack: {} | null;
} }