Skip to content

Fix ScrollSnap page positions when the list uses layout group spacing - #541

Open
Labu1 wants to merge 1 commit into
Unity-UI-Extensions:developmentfrom
Labu1:repodestek/issue-313
Open

Labu1 wants to merge 1 commit into
Unity-UI-Extensions:developmentfrom
Labu1:repodestek/issue-313

Conversation

@Labu1

@Labu1 Labu1 commented Nov 23, 2026

Copy link
Copy Markdown

Unity UI Extensions - Pull Request

Overview

ScrollSnap did not snap to the correct positions when the list container had a Horizontal/Vertical Layout Group with spacing set. The page anchor positions (and the CurrentPage() calculation) stepped by the item size only, so every page was off by an extra spacing amount, accumulating with each page.

This change reads the spacing from the list container's HorizontalOrVerticalLayoutGroup (when present) and uses itemSize + spacing as the per-page step for both the anchor positions and the current page calculation. When there is no layout group, or spacing is 0, behaviour is identical to before.

Changes

Breaking Changes

  • None. Setups without layout group spacing behave exactly as before.

Related Submodule Changes

  • None

Testing status

  • No tests have been added.

No automated test command was detected, so tests were not run.

Manual testing status

Not manually verified in the Unity editor as part of this PR. Suggested check: a ScrollSnap with a Horizontal (or Vertical) Layout Group on the content, spacing e.g. 20, several items; use Next/Prev buttons and swipes and confirm each page aligns to the viewport edge.


This PR was prepared with AI assistance (Claude) and reviewed by me before submitting.

SimonDarksideJ
SimonDarksideJ previously approved these changes Dec 1, 2026
@SimonDarksideJ
SimonDarksideJ changed the base branch from release to development December 1, 2026 14:53
@SimonDarksideJ
SimonDarksideJ dismissed their stale review December 1, 2026 14:53

The base branch was changed.

@SimonDarksideJ

Copy link
Copy Markdown
Contributor

@Labu1 , new work needs to target the development branch, I've updated it but now there are conflicts, can you refresh from development and update please

ScrollSnap calculated its page anchor positions and the current page
using only the item size, ignoring the spacing of a Horizontal or
Vertical Layout Group on the list container. With any spacing set, each
page snapped short by an extra spacing amount, so the error grew with
every page.

Read the spacing from the container's HorizontalOrVerticalLayoutGroup
(if present) and use item size + spacing as the per-page step for both
the anchor positions and CurrentPage(). Behaviour is unchanged when no
layout group or zero spacing is used.

Fixes Unity-UI-Extensions#313.
@Labu1
Labu1 force-pushed the repodestek/issue-313 branch from b728f7c to 9016efc Compare December 3, 2026 06:51
@Labu1

Labu1 commented Dec 3, 2026

Copy link
Copy Markdown
Author

@SimonDarksideJ Thanks for retargeting it. I rebuilt the branch on development with just the ScrollSnap fix as a single commit, so the conflicts are gone and the diff only touches Runtime/Scripts/Layout/ScrollSnap.cs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ScrollSnap not working properly with layout group spacing

2 participants