Skip to content

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

@tataelm

Description

@tataelm

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions