dotnet / maui

.NET MAUI is the .NET Multi-platform App UI, a framework for building native device applications spanning mobile, tablet, and desktop.
https://dot.net/maui
MIT License
21.98k stars 1.71k forks source link

Scrollview doesn't recognize scroll command after any gesture recognizer implemented #22666

Open tataelm opened 3 months ago

tataelm commented 3 months ago

Description

            <ScrollView x:Name="scrollView">
                <StackLayout
                    x:Name="stackpanel_preview_vertical"
                    Grid.Column="0"
                    Margin="15"
                    Orientation="Vertical"
                    Scale="1">
                    <StackLayout.GestureRecognizers>
                        <PinchGestureRecognizer PinchUpdated="StackLayout_Zoom_OnPinchUpdated" />
                    </StackLayout.GestureRecognizers>
                </StackLayout>
            </ScrollView>

If any gesture recognizer is implemented to ScrollView or any child element under ScrollView, scrolling stops working. Scrolling is essentially a "pan gesture", yet implementing other gestures will make it stop too.

I also tested it like this, outcome is the same.

            <ScrollView x:Name="scrollView">
                <ScrollView.GestureRecognizers>
                    <PinchGestureRecognizer PinchUpdated="StackLayout_Zoom_OnPinchUpdated" />
                </ScrollView.GestureRecognizers>

                <StackLayout
                    x:Name="stackpanel_preview_vertical"
                    Grid.Column="0"
                    Margin="15"
                    Orientation="Vertical"
                    Scale="1" />
            </ScrollView>

Steps to Reproduce

No response

Link to public reproduction project repository

No response

Version with bug

9.0.0-preview.3.10457

Is this a regression from previous behavior?

No, this is something new, Not sure, did not test other versions

Last version that worked well

Unknown/Other

Affected platforms

Android

Affected platform versions

No response

Did you find any workaround?

As a workaround I implemented my own scroll event by adding "PanGestureRecognizer", yet the native scroll behaviours would be better.

            <ScrollView x:Name="scrollView">
                <ScrollView.GestureRecognizers>
                    <PinchGestureRecognizer PinchUpdated="StackLayout_Zoom_OnPinchUpdated" />
                    <PanGestureRecognizer PanUpdated="PanGestureRecognizer_PanUpdated" />
                </ScrollView.GestureRecognizers>

                <StackLayout
                    x:Name="stackpanel_preview_vertical"
                    Grid.Column="0"
                    Margin="15"
                    Orientation="Vertical"
                    Scale="1" />
            </ScrollView>

private void PanGestureRecognizer_PanUpdated(object sender, PanUpdatedEventArgs e)
{      
    switch (e.StatusType)
    {
        case GestureStatus.Started:
            // do something with it.
            break;

        case GestureStatus.Running:

            double translateY = e.TotalY;
            var maxScrollOffset = (stackpanel_preview_vertical.Height * _currentScale) - this.Height;

            var absoluteYOffsetLocation = Math.Abs(_yOffsetLocation);
            var positiveTranslateY = Math.Abs(translateY);

            if (translateY < 0) // scrolling down
            {
                var calculatedTranslationY = absoluteYOffsetLocation + positiveTranslateY;
                if (calculatedTranslationY > maxScrollOffset)
                    stackpanel_preview_vertical.TranslationY = maxScrollOffset * -1;
                else
                    stackpanel_preview_vertical.TranslationY = _yOffsetLocation + translateY;
            }
            else if (translateY > 0)// scrolling up
            {
                var calculatedTranslationY = absoluteYOffsetLocation - positiveTranslateY;
                if (calculatedTranslationY <= 0)
                    stackpanel_preview_vertical.TranslationY = 0;
                else
                    stackpanel_preview_vertical.TranslationY = _yOffsetLocation + translateY;

            }
            else
            {
                if (absoluteYOffsetLocation < 0)
                    stackpanel_preview_vertical.TranslationY = 0;
                else if (absoluteYOffsetLocation > maxScrollOffset)
                    stackpanel_preview_vertical.TranslationY = maxScrollOffset * -1;
            }

            break;

        case GestureStatus.Completed:
            _yOffsetLocation = stackpanel_preview_vertical.TranslationY;
            break;
    }
}

Relevant log output

No response

github-actions[bot] commented 3 months ago

Hi I'm an AI powered bot that finds similar issues based off the issue title.

Please view the issues below to see if they solve your problem, and if the issue describes your problem please consider closing this one and thumbs upping the other issue to help us prioritize it. Thank you!

Open similar issues:

Closed similar issues:

Note: You can give me feedback by thumbs upping or thumbs downing this comment.

mattleibow commented 3 months ago

Duplicate of #10213

RoiChen001 commented 3 months ago

Can repro this issue at Android platform on the latest 17.11.0 Preview 1.0(8.0.40/9.0.0-preview.2.10293/9.0.0-preview.3.10457).