Fix [iOS]VerticalOffset Not Reset to Zero After Clearing ItemSource in CollectionView #26818
+150
−10
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Issue Details:
When clearing the ItemSource of a CollectionView, the VerticalOffset does not reset to zero on iOS and MacCatalyst. Instead, the last offset value is retained. However, after adding items back to the ItemSource, the VerticalOffset updates as expected when scrolling.
Root Cause:
The UIScrollView.ContentOffset retains its previous value even when the ItemSource is cleared, as there are no visible items in the CollectionView. The VerticalOffset property of the CollectionView depends on the ContentOffset value, which is not reset in such cases.
Description of Change
Reset HorizontalOffset and VerticalOffset to zero when ItemSource is empty and no items are visible.
Issues Fixed
Fixes #26798
Regarding Test case
The test case for this fix is included in this PR
Validated the behaviour in the following platforms
Output Screenshot
BeforeFix.mov
AfterFix.mov