[BUG] Single Child in ContentScrollSnapHorizontal

Issue #362 new
James Davies created an issue

When using the ContentScrollSnapHorizontal from the context menu, and only having 1 item in the content (removing 4 of the 5 added) causes the panel not to snap correctly.

Steps:

  1. Create new scene
  2. Right click Hierarchy
  3. Choose UI > Extensions > Content Scroll Snap Horizontal
  4. Delete Position 2 through to Position 5, so only 1 item exists
  5. Run
  6. Drag the item

Comments (2)

  1. James Davies reporter

    Managed to fix this issue using the following code:

            public void OnBeginDrag(PointerEventData ped)
            {
                if (contentPositions.Count <= 1)
                {
                    return;
                }
    
                StopMovement();
                if (!Moving)
                {
                    MovementStarted.Invoke();
                }
            }
    
            public void OnEndDrag(PointerEventData ped)
            {
                if (contentPositions.Count <= 1)
                {
                    return;
                }
    
                StartCoroutine("SlideAndLerp");
            }
    

    All I do is make sure there’s more than 1 item to call the code.

    It might not be required to have the filter in the BeginDrag, but if there’s going to be no movement, maybe it shouldn’t call the callback.

  2. Log in to comment