Skip to content

fix: Reuse ListView containers on drag-drop reorder - #23765

Merged
Xiaoy312 merged 2 commits into
masterfrom
dev/xygu/20260714/fix-listview-dnd-reorder-flicker
Jul 15, 2026
Merged

Xiaoy312 merged 2 commits into
masterfrom
dev/xygu/20260714/fix-listview-dnd-reorder-flicker

Conversation

@Xiaoy312

Copy link
Copy Markdown
Contributor

GitHub Issue: Tracked internally (client-reported ListView drag-drop reorder flicker). No public issue.

PR Type:

🐞 Bugfix

What changed? 🚀

Reordering a ListView by drag-and-drop visibly flickered the whole list — every row re-templated — whereas the Move Up / Move Down buttons did not.

On drop, VirtualizingPanelLayout.CompleteReorderingItem called Refresh() unconditionally. Refresh() recycles every materialized container (clearContainer: true) and clears the generator id cache, so on the next measure the containers are re-dealt to different data items — every visible row re-templates (the flicker). The lighter LightRefresh() (used by UpdateReorderingItem / CleanupReordering) just re-measures and preserves container identity.

This PR switches the managed drop path to LightRefresh(). The temp reorder offset is already cleared before the call, so a re-measure re-arranges all items to their final positions while keeping each container instance bound to its data item. This is the same light path the Android layout already takes by default (its heavy recycle is gated behind ForceRecycleOnDrop, which is off by default and documented as "known to cause a flicker of the whole list").

Scope: managed layout (Skia). GridView on Skia uses a non-virtualizing WrapPanel, so CompleteReorderingItem is never invoked for it — the change affects ListView (and any real virtualizing ItemsStackPanel).

Tests — four runtime tests in Given_ListViewBase covering the reorder paths, container identity keyed by data item:

  • When_Reorder_Move_ReusesContainers — ObservableCollection.Move (button path)
  • When_Reorder_RemoveInsert_ReusesContainers — RemoveAt+Insert (drag-drop's collection commit)
  • When_Reorder_DragDrop_ReusesContainers — real pointer-driven drag-drop (fails before this change, passes after)
  • When_Layouter_Refresh_RecreatesContainers — isolates that Refresh() itself churns containers

Validated on Skia Desktop: the drag-drop test flips FAIL→PASS with the fix, and the existing reorder/drag tests (When_UpdateLayout_In_DragDropping, When_Drop_Outside_Bounds, When_UpdateLayout_In_DragDropping_2, When_DragDrop_ItemsSource_Is_Subclass_Of_ObservableCollection, When_INCC_Move_MinimalUpdate) still pass — confirming the dropped item still lands in the correct position via incremental collection-change handling.

PR Checklist ✅

On drop, VirtualizingPanelLayout.CompleteReorderingItem called Refresh()
unconditionally, recycling every materialized container and re-dealing
them to different data, so every row re-templated (the whole-list flicker).
Switch to LightRefresh() (re-measure only): it re-arranges items to their
final positions while preserving container identity, matching the light
path the Android layout already uses by default.

Add runtime tests for the four reorder paths (Move, RemoveAt+Insert, real
drag-drop, and Refresh isolation). The drag-drop test fails before this
change and passes after; the existing reorder/drag tests still pass.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Copilot AI review requested due to automatic review settings July 14, 2026 20:06

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes Skia/managed ListView drag-drop reorder flicker by avoiding a full container recycle/redeal on drop, keeping realized container identity stable across the reorder (matching the lighter refresh behavior used in other reorder paths).

Changes:

  • Switch drop completion (CompleteReorderingItem) from Refresh() to LightRefresh() to preserve container identity and avoid full-list re-templating.
  • Add Skia runtime tests validating container reuse across different reorder/mutation paths, including a pointer-driven drag-drop scenario.
  • Add helper utilities to capture and compare containers by data item (rather than by index) across reorders.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
src/Uno.UI/UI/Xaml/Controls/ListViewBase/VirtualizingPanelLayout.managed.cs Use LightRefresh() on reorder completion to avoid recycling/redealing containers on drop.
src/Uno.UI.RuntimeTests/Tests/Windows_UI_Xaml_Controls/Given_ListViewBase.cs Add runtime tests and helper methods to verify container identity is preserved during reorder operations.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Reword the CaptureContainersByItem doc comment: the helper no longer has a
GridView caller, and note that ObservableCollection<string> binds to the
IEnumerable<object> parameter via IEnumerable<out T> covariance.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Copilot AI review requested due to automatic review settings July 14, 2026 20:15
@agneszitte
agneszitte requested review from MartinZikmund and removed request for MartinZikmund and Copilot July 14, 2026 20:15
@unodevops

Copy link
Copy Markdown
Contributor

@unodevops

Copy link
Copy Markdown
Contributor

⚠️⚠️ The build 222387 has failed on Uno.UI - CI.

@mergify

mergify Bot commented Jul 15, 2026

Copy link
Copy Markdown
Contributor

Tick the box to add this pull request to the merge queue (same as @mergifyio queue).

  • Queue this pull request

@Xiaoy312
Xiaoy312 merged commit 9c61cd6 into master Jul 15, 2026
48 checks passed
@Xiaoy312
Xiaoy312 deleted the dev/xygu/20260714/fix-listview-dnd-reorder-flicker branch July 15, 2026 14:43
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.

4 participants