Search Unity

TMP_InputField and scrolling via drag (or touch)

Discussion in 'UGUI & TextMesh Pro' started by btschumy, Apr 12, 2021.

  1. btschumy

    btschumy

    Joined:
    Jul 31, 2019
    Posts:
    93
    I have a TMP_InputField that l contains multiline text. By default the text is not editable but it can be edited by clicking an "Edit" button. I toggle between making the textfield editable by setting its "intractable" property.

    On desktops, you can easily scroll the text via a trackpad or a scroll wheel. However, if you try to click and drag to scroll, nothing happens.

    This is a real problem on mobile devices where tap and drag is the only way to scroll. This doesn't work for touch either.

    Is there a setting I'm missing that will enable scroll via dragging the text?

    I do have the textfields vertical scrollbar set to "none" because I don't want a visible scrollbar here. Could that be a problem? If so I'm surprised you can scroll via the trackpad.
     
  2. btschumy

    btschumy

    Joined:
    Jul 31, 2019
    Posts:
    93
    Still looking for a solution here. How do you make a multiline TMP_InputField scrollable?
     
  3. aegis60918

    aegis60918

    Joined:
    Apr 24, 2017
    Posts:
    1
    I'm using TextMesh Pro 3.0.6 with Unity 2020.3.16f1 and facing the same problem.

    When using TMP_InputField with multiline text, we can use a trackpad to scroll the text on desktop. However, on mobile devices (Android / iOS) the scrolling for multiline text doesn't work anymore.

    We finally created another TMP_ScrollableInputField inherited from TMP_InputField and override the OnDrag function:

    Code (CSharp):
    1. using TMPro;
    2. using UnityEngine.EventSystems;
    3.  
    4. public class TMP_ScrollableInputField : TMP_InputField
    5. {
    6.     public override void OnDrag(PointerEventData eventData)
    7.     {
    8.         eventData.scrollDelta = -eventData.delta / 50;  // We use 50 for the drag-scroll text. Adjust for your own input field
    9.         base.OnScroll(eventData);
    10.     }
    11. }
    The above TMP_ScrollableInputField with multiline text can now drag and scroll on mobile devices (tested on Android / iOS). However, the original OnDrag behavior is override by the new drag-scroll behavior. So if you still need the OnDrag behavior of TMP_InputField (you can drag select texts on Editor), the method above may not work.
     
  4. Serbusz

    Serbusz

    Joined:
    Apr 12, 2014
    Posts:
    6
    Anyone found a workaround or fix for this?

    having the same issue using 2020.3.48.f1