Search Unity

Resolved ListView selection on Android

Discussion in 'UI Toolkit' started by marekzd, Feb 1, 2021.

  1. marekzd

    marekzd

    Joined:
    Jul 1, 2016
    Posts:
    33
    Hi,

    I'm using ListView.onSelectionChange for handling selection on ListView.
    But it turned out it doesn't work well on Android.
    It makes scrolling impossible, because when you touch the screen it's interpreted as a selection, not as a scoll start.

    How can I fix this ?

    Cheers.
     
  2. griendeau_unity

    griendeau_unity

    Unity Technologies

    Joined:
    Aug 25, 2020
    Posts:
    248
    Hi,

    Registering to the
    onSelectionChange
    event should have no impact on the scrolling unless the code does something special in response to that event. Can you give us more info on what your code is doing when it receives the event?

    Thanks!
     
  3. marekzd

    marekzd

    Joined:
    Jul 1, 2016
    Posts:
    33
    I'm listening for
    onSelectionChange
    and show a dialog box.

    I suspect that
    onSelectionChange
    is triggered on a
    MouseDown
    event.
    Whereas it is ok for mouse pointer, on touch device it won't work so well.
    Android list, for example, triggers list item selection on
    MouseUp
    , but only if scrolling haven't already started.
     
  4. griendeau_unity

    griendeau_unity

    Unity Technologies

    Joined:
    Aug 25, 2020
    Posts:
    248
    I see yes, the dialog box interrupts the rest of the click/drag because it from the OS.
    I think it makes sense to move this callback to the PointerUpEvent instead of PointerDownEvent.

    Could you report a demo project with Help->Report a bug... and we'll look into it in more depth. That way we'll have more info about the code and settings/versions you are using as well. Thanks!
     
  5. marekzd

    marekzd

    Joined:
    Jul 1, 2016
    Posts:
    33
    The dialog doesn't come from the OS. It's written in UIToolkit :)

    You will also need to ignore PointerUpEvent when scrolling already started.
    Try to play with Android or iOS settings application. There is a list and it's pretty neat how it works.

    Ok
     
  6. marekzd

    marekzd

    Joined:
    Jul 1, 2016
    Posts:
    33
    I've uploaded a demo project.
    Issue id: 1312139
     
  7. griendeau_unity

    griendeau_unity

    Unity Technologies

    Joined:
    Aug 25, 2020
    Posts:
    248
  8. marekzd

    marekzd

    Joined:
    Jul 1, 2016
    Posts:
    33
    Hi, unity_griendeau,

    Do you have any progress on this issue ?

    When can I expect a fix ? Or maybe you found some hack around this issue in the meantime ?
     
  9. griendeau_unity

    griendeau_unity

    Unity Technologies

    Joined:
    Aug 25, 2020
    Posts:
    248
    Hi marekzd,

    Someone from the team is looking at the issue at the moment. The fix will need to be backported to previous engine versions as well, so it could take a few weeks to reach the public.

    A potential workaround would be to register to pointer events on a parent of the ListView, and react on
    TrickleDown
    to stop the propagation (with
    evt.StopPropagation()
    ) of undesired events upfront and control the selection manually on pointer up as desired. Stopping propagation before it reaches its target might cause side effects for other controls that are part of the list, so it is a workaround to use with caution.

    Or you could disable selection on the ListView
    listView.selectionType = SelectionType.None
    and instead of using the onSelectionChange callback on the list view, add a
    Clickable
    manipulator to your element in the makeItem. It should support correctly the click vs drag in scrollview on mobile.

    I'll keep you posted for the fix!
     
    Last edited: May 19, 2021
  10. marekzd

    marekzd

    Joined:
    Jul 1, 2016
    Posts:
    33
    It was fixed in UIToolkit-1.0.0-preview.17:
    - Fixed selection on pointer up on mobile to allow touch scrolling. (case 1312139)

    Thanks :)
     
    griendeau_unity likes this.