xamarin / Xamarin.Forms

Xamarin.Forms is no longer supported. Migrate your apps to .NET MAUI.
https://aka.ms/xamarin-upgrade
Other
5.62k stars 1.87k forks source link

[Bug] Pan gesture on android updating two value #13863

Open kdbhalala opened 3 years ago

kdbhalala commented 3 years ago

Description

PanGesture On android Updating Two Value On the same point

Steps to Reproduce

  1. Pan Gesture On Frame
  2. Update Height As pan gesture updates value

Code

<Grid>

        <!-- Any Content -->

        <Frame BackgroundColor="Purple"
        x:Name="BottomSheet"
        HeightRequest="65"
        HorizontalOptions="FillAndExpand"
        VerticalOptions="End">

        <Frame.GestureRecognizers>
            <PanGestureRecognizer PanUpdated="PanGestureRecognizer_PanUpdated" />
        </Frame.GestureRecognizers>

    </Frame>

</Grid>

code Behind

    bool up;
    bool down;
    bool isTurnY;
    int ScreenHeight = 400;
    double valueY = 2;
    void PanGestureRecognizer_PanUpdated(object sender, PanUpdatedEventArgs e)
    {
        Debug.WriteLine("Y --> " + e.TotalY);
        switch (e.StatusType)
        {
            case GestureStatus.Running:
                if (e.TotalY >= 5 || e.TotalY <= -5 && !isTurnY)
                {
                    isTurnY = true;
                }
                if (isTurnY)
                {
                    if (e.TotalY <= valueY)
                    {
                        up = true;
                    }
                    if (e.TotalY >= valueY)
                    {
                        down = true;
                    }
                }
                if (up)
                {
                    var height = ScreenHeight - Math.Abs(e.TotalY) < 65 ? 65 : ScreenHeight - Math.Abs(e.TotalY);
                    BottomSheet.HeightRequest = height;
                }
                else
                {
                    var height = Math.Abs(e.TotalY) > ScreenHeight ? ScreenHeight : Math.Abs(e.TotalY);
                    BottomSheet.HeightRequest = height;
                }

                break;
            case GestureStatus.Completed:

                break;
        }
    }
}

Debug Value e.TotalY

Expected Behavior

Y --> 314.999993172559
Y --> 314.999993172559
Y --> 314.999993172559
Y --> 314.999993172559
Y --> 314.999993172559
Y --> 314.999993172559
Y --> 314.999993172559
Y --> 314.999993172559

Actual Behavior

Y --> 277.272721263003
Y --> 314.999993172559
Y --> 277.727266707696
Y --> 316.569373465248
Y --> 278.387556110999
Y --> 318.387555244022
Y --> 279.751192445079
Y --> 319.545447619493

Basic Information

StephaneDelcroix commented 3 years ago

Thanks for the code sample, but I'm not sure I understand the problem. could you please explain a bit more in the description ? thanks

kdbhalala commented 3 years ago

Thanks for the code sample, but I'm not sure I understand the problem. could you please explain a bit more in the description? thanks

If We pan On android up to bottom or bottom to up at any point we stop but not lift finger from a screen then it gives me multiple values not one single value where i stopped pan

MichaelNovikov commented 2 years ago

Any updates? I have the same problem.