yurkinh / Plugin.Maui.Calendar

.NET MAUI port of XF calendar plugin
MIT License
131 stars 12 forks source link

[Suggestion] Remove SwipeAwareContainer #10

Closed FabriBertani closed 9 months ago

FabriBertani commented 9 months ago

Hi @yurkinh, thank you for porting this plugin.

I would like to suggest the removal of the SwipeAwareContainer in favour of the SwipeGestures included in .Net MAUI.

The change will be to use a simple layout that wraps the MonthDaysView in the Calendar that also contains the gestures and let the framework and the platform handle the subscriptions, something like this:

<VerticalStackLayout>
    <VerticalStackLayout.GestureRecognizers>
        <SwipeGestureRecognizer
            Direction="Left"
            Swiped="OnSwipedLeft" />
        <SwipeGestureRecognizer
            Direction="Right"
            Swiped="OnSwipedRight" />
        <SwipeGestureRecognizer
            Direction="Up"
            Swiped="OnSwipedUp" />
    </VerticalStackLayout.GestureRecognizers>

    <controls:MonthDaysView
        ...
        TodayOutlineColor="{Binding TodayOutlineColor, Source={x:Reference calendar}}" />
</VerticalStackLayout>

And change the code behind handlers to receive a SwipedEventArgs, instead of EventArgs:

private void OnSwipedRight(object sender, SwipedEventArgs e)
{
    SwipeRightCommand?.Execute(null);

    if (SwipeToChangeMonthEnabled)
        PrevUnit();
}

private void OnSwipedLeft(object sender, SwipedEventArgs e)
{
    SwipeLeftCommand?.Execute(null);

    if (SwipeToChangeMonthEnabled)
        NextUnit();
}

private void OnSwipedUp(object sender, SwipedEventArgs e)
{
    SwipeUpCommand?.Execute(null);

    if (SwipeUpToHideEnabled)
        ToggleCalendarSectionVisibility();
}

I've tried and it works the same as the container class.

Thank you!

yurkinh commented 9 months ago

Hi @FabriBertani Good point. Thanks for the provided code sample. Yesterday I have fixed DisableSwipeDetection which was ignored. I will take a look at it today

yurkinh commented 9 months ago

I have moved GestureRecognizers to the MonthDaysView cause it is also ContentView no need for an additional vertical stacklayout. Also removed SwipeAwarecontainer. Check please the latest 1.0.10 Nuget version. Thanks for the suggestion!