You can make a mobile swipe execute an existing action by adding swipe tagged values to the ViewModel class in MDriven Designer.
Configure a swipe action
A swipe action is an action that runs when the user swipes left or right in a ViewModel. Configure the swipe on the ViewModel class, and set the tagged value to the name of the action that you want to execute.
- In MDriven Designer, select the ViewModel class for the view where you want to recognize the swipe.
- Add a tagged value for the swipe direction.
- Set the tagged value's value to the action name to execute.
- Save the model and test the gesture in the client on a mobile device.
| User gesture | Tagged value | Value |
|---|---|---|
| Swipe left | SwipeLeft
|
The name of the action to execute. |
| Swipe right | SwipeRight
|
The name of the action to execute. |
Enable one or both directions
Add the tag for each direction that your ViewModel supports.
| Required behavior | Tags to add to the ViewModel class |
|---|---|
| Execute an action only when the user swipes left | SwipeLeft
|
| Execute an action only when the user swipes right | SwipeRight
|
| Execute actions for swipes in both directions | SwipeLeft and SwipeRight
|
The two tags can point to different actions. For example, if the ViewModel has actions named ShowNext and ShowPrevious, configure the tags as follows:
| Tagged value | Value | Result |
|---|---|---|
SwipeLeft
|
ShowNext
|
A left swipe executes ShowNext.
|
SwipeRight
|
ShowPrevious
|
A right swipe executes ShowPrevious.
|
Choose the action carefully
The tagged-value value is an action name, not EAL code. Define the action and its behavior before referring to it from SwipeLeft or SwipeRight.
For example, an action can use EAL to update the ViewModel's current or selected object. The swipe tags then provide a gesture-based way for the user to execute that action instead of selecting it from the user interface.
Swipe triggering is intended for mobile-device interaction. Keep the result of each gesture clear and predictable; a left and a right swipe should not perform unrelated operations without a visible indication of what changed.
Test the configuration
- Open the ViewModel in the client on a mobile device.
- Swipe in the configured direction.
- Confirm that the named action executes and produces the expected change.
- Test the opposite direction as well. If no corresponding tag is present, do not expect a swipe action for that direction.
