com.unity.uiextensions icon indicating copy to clipboard operation
com.unity.uiextensions copied to clipboard

Infinite HSS NextPage Broken

Open SimonDarksideJ opened this issue 3 years ago • 3 comments

Issue created by Matt as Bitbucket Issue #​257 on 2018.07.31 19:36. When calling the NextScreen function on a horizontal snap scroller that has UI_InfiniteScroll component, HSS appears to 'take the long way' to the next item when the current item is either: -The 0th item going to the 1st item -The Xth item going to the X-1 item Rather than jump to the item right beside the current one, the scroller will back track all the way back to the next item.From what I can figure out, there appears to be an issue inside the GetPositionForPage function inside the ScrollSnapBase.cs file, but I am unfamiliar with the code.

Seems to be somewhat related to issue #132.

SimonDarksideJ avatar Apr 25 '22 19:04 SimonDarksideJ

Will this be fixed?!

ROBYER1 avatar Mar 19 '24 15:03 ROBYER1

Thanks for the reminder, this wasn't in the 2.3.3 list, so I've added it to the queue now

SimonDarksideJ avatar Mar 19 '24 16:03 SimonDarksideJ

Its no PR but I wrote a workaround script here for swipes and disabled interaction on the HSS to use this. Hope it helps others.

using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI.Extensions;

public class SwipeGallery : MonoBehaviour, IDragHandler, IEndDragHandler
{
    public HorizontalScrollSnap scroller;

    public void OnDrag(PointerEventData eventData)
    {
    }
    public void OnEndDrag(PointerEventData eventData)
    {
        Vector3 dragVectorDirection = (eventData.position - eventData.pressPosition).normalized;
        GetDragDirection(dragVectorDirection);
    }
    private enum DraggedDirection
    {
        Up,
        Down,
        Right,
        Left
    }
    private DraggedDirection GetDragDirection(Vector3 dragVector)
    {
        float positiveX = Mathf.Abs(dragVector.x);
        float positiveY = Mathf.Abs(dragVector.y);
        DraggedDirection draggedDir;
        if (positiveX > positiveY)
        {
            draggedDir = (dragVector.x > 0) ? DraggedDirection.Right : DraggedDirection.Left;
        }
        else
        {
            draggedDir = (dragVector.y > 0) ? DraggedDirection.Up : DraggedDirection.Down;
        }
        if (draggedDir == DraggedDirection.Right)
        {
            SwipeRight();
        }
        else if (draggedDir == DraggedDirection.Left)
        {
            SwipeLeft();
        }

        Debug.Log(draggedDir);
        return draggedDir;
    }

    public void SwipeLeft()
    {
        if (scroller.CurrentPage == (scroller.ChildObjects.Length - 1))
        {
            scroller.ChangePage(0);
            Debug.Log("changing page to: " + 0);
        }
        else
        {
            scroller.ChangePage(scroller.CurrentPage + 1);
            Debug.Log("changing page to: " + (scroller.CurrentPage + 1));
        }
    }

    public void SwipeRight()
    {
        if (scroller.CurrentPage == 0)
        {
            scroller.ChangePage(scroller.ChildObjects.Length - 1);
            Debug.Log("changing page to: " + (scroller.ChildObjects.Length - 1));
        }
        else
        {
            scroller.ChangePage(scroller.CurrentPage - 1);
            Debug.Log("changing page to: " + (scroller.CurrentPage - 1));
        }
    }
}

ROBYER1 avatar Mar 20 '24 10:03 ROBYER1