Forum Xamarin.Forms
We are excited to announce that the Xamarin Forums are moving to the new Microsoft Q&A experience. Q&A is the home for technical questions and answers at across all products at Microsoft now including Xamarin!

We encourage you to head over to Microsoft Q&A for .NET for posting new questions and get involved today.

Will Xamarin consider supporting ScrollView that scroll in both directions?

ScrollView in Xamarin.Forms does not scroll in both directions.

I could see that, iOS has a UIScrollView which can scroll in both horizontal and vertical directions and similarly the WindowsPhone and WinRT platforms. Expect Android which alone don't have support for scrollView in both directions, Can Xamarin make some changes in the Android ScrollView Renderer and provide support for a ScrollView that could scroll in both Horizontal and vertical directions.

It would me much helpful for developers of Xamarin to have a ScrollView that scrolls in both direction which would reduce a lot of tweeks and hacks in our side. Can Xamarin consider this?

Answers

  • YkshLeoYkshLeo USMember ✭✭✭✭
    edited December 2015

    @Harikrishnan,

    There is already a similar forum post,

    Was able to fix this by creating a custom renderer with overloaded DispatchTouchEvent for the inner scroll. If this ScrollView is horizontal it will handle horizontal scroll itself and pass vertical scroll to parent for handling. If it is vertical then it will handle vertical itself and pass horizontal to parent.

    class InnerAndroidScrollViewRenderer : ScrollViewRenderer
    {
        float StartX, StartY;
        int IsHorizontal=-1;
    
        protected override void OnElementChanged(VisualElementChangedEventArgs e)
        {
            base.OnElementChanged(e);
            if (((ScrollView)e.NewElement).Orientation == ScrollOrientation.Horizontal) IsHorizontal = 1;
    
        }
        public override bool DispatchTouchEvent(Android.Views.MotionEvent e)
        {
    
            switch (e.Action)
            {
                case MotionEventActions.Down:
                    StartX=e.RawX;
                    StartY=e.RawY;
                    this.Parent.RequestDisallowInterceptTouchEvent(true);
                    break;
                case MotionEventActions.Move:
                    if (IsHorizontal * Math.Abs(StartX - e.RawX) < IsHorizontal * Math.Abs(StartY - e.RawY))
                        this.Parent.RequestDisallowInterceptTouchEvent(false);
                    break;
                case MotionEventActions.Up:
                    this.Parent.RequestDisallowInterceptTouchEvent(false);
                    break;
            }
            
            return base.DispatchTouchEvent(e);
        }
    

    Refer :

  • HarikrishnanHarikrishnan USMember ✭✭
    edited December 2015

    Hi @YkshLeo

    I was aware of this idea. My question was not demanding a way to achieve two way scrolling, but to have a direct support for scrolling in both directions from the pcl project like we have in Xamarin.iOS(UIScrollView which scrolls in both direction).

    Currently xamarin is providing support for only one direction, if they could support a ScrollView that could scroll in both direction directly from pcl, it would be very helpful instead of making some workaround in all the renderer projects like Android, iOS, WindowsPhone and WinRT.

  • YkshLeoYkshLeo USMember ✭✭✭✭
    edited December 2015

    @Harikrishnan,

    We can achieve that feature only through rendering.
    I assume xamarin can't bring a new control which scroll in both directions.

    When we consider about Xamarin.Forms, we also want to consider about Android too.
    And I think still there is no similar native control existed in Android.


    I think you can suggest your idea in Xamarin through : Xamarin's user voice site, so the Xamarin officials can go through your idea, if it's a good one then we will have that feature on next version.

  • HarikrishnanHarikrishnan USMember ✭✭

    @YkshLeo

    You are rite. I was aware of it as well. But my suggestion is, apart from android all the other platforms have ScrollView that scrolls in both direction.

    So if Xamarin could workaround the two way scrolling for Android from their ScrollViewRenderer class, it would be very useful. It is not a great deal to write a scroll view in Android that scrolls in both direction. Infact I have written my own scroll view in android that scrolls in both direction. Why can't Xamarin just try and give this support by doing workaround directly from its ScrollViewRenderer class internally. It would be a great deal if we can have a ScrollView in Xamarin.Forms that scrolls in both the direction.

    Anyway thanks for your information, I would try suggesting my idea in Xamarin's user voice site,

  • YkshLeoYkshLeo USMember ✭✭✭✭
    edited December 2015

    @Harikrishnan,

    The problem is not with Xamarin. It's with Android (Google).

    I prefer you can suggest that feature to Google : https://code.google.com/p/android/, so they can implement it in new version.

    In this case, Xamarin is not able to create a new control for Android.

  • HarikrishnanHarikrishnan USMember ✭✭

    @YkshLeo

    Obviously it is not a problem with Xamarin. But am just suggesting that Xamarin could try and do a workaround like that to achieve two way scrolling in Android too from the ScrollViewRenderer in Android.

    I don't want Xamarin to create a new control for Android, but I just suggest Xamarin to workaround in the Xamarin's Android ScrollViewRenderer class for achieving the two way scrolling.

    Anyway I accept your point and will suggest the feature to Google as well.

  • YkshLeoYkshLeo USMember ✭✭✭✭

    @Harikrishnan, Waiting to see that updation :smile:

  • adamkempadamkemp USInsider, Developer Group Leader mod

    Xamarin can definitely create a 2-direction scroll view for Android. I've done it myself (with zoom, even). It's kind of a pain, but it can definitely be done, and that means they can create a renderer for it. It won't be based on a stock control, but not everything in Forms is based on a stock control. I think this is just a matter of feature prioritization. In the meantime, the community could probably create one.

  • HarikrishnanHarikrishnan USMember ✭✭

    Hi @adamkemp

    Thanks for the comment.
    I accept the fact that its a matter of feature prioritization. But priority differs based on individuals and firms. For me and my application having support for ScrollView that could scroll in all direction is of ultimate priority. I hope for few others as well, I could see this from here. Lets hope Xamarin would give high priority to this and implement it ASAP.

  • SagarPanwalaSagarPanwala USMember ✭✭✭
    edited June 2019

    @Harikrishnan : Thanks , btw Xamarin Forms has Scrollview orientation = "Both".
    Just mentioning so new user can find this helpful.

Sign In or Register to comment.