cancel
Showing results for 
Search instead for 
Did you mean: 

Swipe in 2 dimensions

Bob Bailey
Senior

I want to create something that is almost a 2D swipe container. but in reality I think the best solution is several screens, each with swipe containers, and a vertical swipe on any one will transition North/South to the next page.

Is there documentation on this? Perhaps some example code?

Thanks!

Bob

6 REPLIES 6
Martin KJELDSEN
Chief III

There's no doc on what you want outside of what there is on screen transitions.

But it should be easy to do. depending on what you want. When you swipe, do you want to be able to see the old and new screens at the same time? e.g. stopping your swipe mid-way would show half of each. Or are you just looking for gesture recognition

/Martin

Bob Bailey
Senior

Being able to see new and old during the vertical swipe would be great, its not critical. Just capturing the vertical swipe and triggering a slide transition to the next screen should suffice.

since both new and old screens will be swipe containers, I would want them to remember which page they were on. both from previous power cycles (non-volatile), as well as just in one session. (swipe up then back down would return you to the same page)

Bob

Martin KJELDSEN
Chief III

You can record which page you're on by storing that information inside the model. The view has a pointer to its presenter, the presenter has a pointer to the model. When you enter a screen, the activate() method of the presenter can then retrieve the stored value for that page from the model and set the value on the view. Does that make sense? Classic MVP architecture.

You can practice then by registering a drag in each direction (handleDragEvent) on a view and then calling the presenter to perform a particular screen transition. Just laying out the basics here until you start coding.

/Martin

Bob Bailey
Senior

Thanks, I'll follow your suggestion and see if I can get it going.

This is my first exposure to MVP, learning as I go.

Thanks

Bob

Bob Bailey
Senior

I got it basically working. I have a swipe container on my main screen, and am using

void mainView::handleGestureEvent(const GestureEvent & evt)
{
 
    if (vert_swipe_detected)  // an attempt to prevent inadvertent additional triggers
    {
        return;
    }
 
    if (evt.getType() == evt.SWIPE_VERTICAL)
    {
        if (evt.getVelocity() > 20)  // down
        {
            vert_swipe_detected = 1;
            application().gotoScreen2ScreenSlideTransitionNorth();  // north slides down
        }
        else if (evt.getVelocity() < -20 )
        {
            vert_swipe_detected = 1;
            application().gotoOtherScreenNoTransition();
            // this is copied from button interaction code
        }
    }
}

it will trigger a page change if the swipe is vertical. but it seems that more distinctive detection is needed to keep from getting the wrong action, i.e. swiping horizontal but getting an accidental vertical trigger.

Any hints? Should I use the dragEvent instead of the Gesture? Perhaps I should modify the Gesture detection to be more discerning. (where is this I could not find it)

Any example code? The documentation is full of "A gesture event indicates a gesture" sort of non-information.

Making progress, for sure, thanks for any additional direction you can provide.

Bob

Bob Bailey
Senior

another idea would be to derive from swipe container (or copy it into a new class) and use the draw and gesture sections to determine the action.

Bob