I have an scrollabe layout with an Editor inside that I'd like to make scrollable or auto resizable to fit the contents.
I can't find how to do it.
I tried a custom renderer but I can't find how to set InputMethods to the Control.
Any ideas?
With the help of this post: https://forums.xamarin.com/discussion/80360/editor-inside-scrollview-not-scrolling
That fixed the scrolling on Android (iOS works by default). It avoids the parent scroll event when touching inside the Editor, triggering only the Editor scroll.
First a class on Android project:
using Android.Views;
namespace MyApp.Droid
{
    public class DroidTouchListener : Java.Lang.Object, View.IOnTouchListener
    {
        public bool OnTouch(View v, MotionEvent e)
        {
            v.Parent?.RequestDisallowInterceptTouchEvent(true);
            if ((e.Action & MotionEventActions.Up) != 0 && (e.ActionMasked & MotionEventActions.Up) != 0)
            {
                v.Parent?.RequestDisallowInterceptTouchEvent(false);
            }
            return false;
        }
    }
}
And then use it on the Android Custom EditorRenderer:
protected override void OnElementChanged(ElementChangedEventArgs<Editor> e)
{
    base.OnElementChanged(e);
    if (e.OldElement == null)
    {
        var nativeEditText = (global::Android.Widget.EditText)Control;
        //While scrolling inside Editor stop scrolling parent view.
        nativeEditText.OverScrollMode = OverScrollMode.Always;
        nativeEditText.ScrollBarStyle = ScrollbarStyles.InsideInset;
        nativeEditText.SetOnTouchListener(new DroidTouchListener());
        //For Scrolling in Editor innner area
        Control.VerticalScrollBarEnabled = true;
        Control.MovementMethod = ScrollingMovementMethod.Instance;
        Control.ScrollBarStyle = Android.Views.ScrollbarStyles.InsideInset;
        //Force scrollbars to be displayed
        Android.Content.Res.TypedArray a = Control.Context.Theme.ObtainStyledAttributes(new int[0]);
        InitializeScrollbars(a);
        a.Recycle();
    }
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With