daniellochner / simple-scroll-snap

“Simple Scroll-Snap” is an elegantly designed, intuitive solution that allows for elements within a ScrollView to be snapped to, offering a wide range of customization options.
MIT License
143 stars 20 forks source link

Excess snapping animation to Starting Panel with no 'Use Automatic Layout' #16

Open Maligan opened 1 year ago

Maligan commented 1 year ago

In case of using non automatic scroll-snap layout there is a problem with excess animation lerp to the first panel.

These lines in Setup can fix this behaviour:

private void Setup()
{
    ...

    // Starting Panel
    ...

    Vector2 targetPosition = -Panels[CenteredPanel].anchoredPosition + offset;
    Content.anchoredPosition = targetPosition;

    // Buttons
    ...
}

Or may be you can consider another solution.

Maligan commented 1 year ago

Oh, I've made a mistake, there is already start Content.anchoredPosition calcualtion.

The problem is Setup() is calling from Start() which execute before Unity Layout system calculate new correct positions for layout elements.

Possible solution is move Setup() method at the very first Update() call...