Search code examples
c#eventsanimationxamarin.formsmr.gestures

Block event while animations is running


I'm working on a app where i have implanted a swipe function.

When the user swipe a box it's fire a event where the box is animated to slide a side. where i created the animations like shown below

boxview.Swiped += (s, e) =>
{
    if (e.Direction == MR.Gestures.Direction.Right)
    {
        boxview.TranslateTo(-600, 0, 500, null);
    }
}

So what i wanna do is to ignore this if, if it's called again within the 500ms timespan it takes to complete the animations.

Been thinking about just take the event(e) and cancelled it. but i still need a way to say it should only do it within the timespan. and haven't had luck getting it working.

anyway thanks for any input you may have, and thanks for your time.


Solution

  • Since I'm not familiar with Xamarin itself, this answer is theoretical. TranslateTo seems to be awaitable, so you could use a flag that you are swiping, await the translate to and reset the flag after that

    bool swiping;
    boxview.Swiped += async (s, e) =>
    {
        if (e.Direction == MR.Gestures.Direction.Right && !swiping)
        {
            swiping = true;
            await boxview.TranslateTo(-600, 0, 500, null);
            swiping =false;
        }
    }