maui icon indicating copy to clipboard operation
maui copied to clipboard

Fix for ItemSpacing value being retained when re-entering CollectionView with ItemsLayout set to vertical or horizontal list after navigating back.

Open BagavathiPerumal opened this issue 7 months ago • 7 comments

Root cause

The issue was caused because LinearItemsLayout.Vertical and LinearItemsLayout.Horizontal were used as static instances instead of creating new instances in the layout type converter. As these static instances were reused, properties like ItemSpacing retained their previous values when returning to the page using PopAsync. Since the internal items layout property defaulted to the static LinearItemsLayout.Vertical, the layout did not refresh properly, leading to inconsistent or unexpected behavior across all platforms.

Description of Issue Fix

The fix involves replacing the use of static instances (LinearItemsLayout.Vertical and LinearItemsLayout.Horizontal) with newly created instances of LinearItemsLayout to prevent shared state across navigations. This was achieved by updating the layout initialization to use a defaultValueCreator that returns a new LinearItemsLayout instance, and modifying the ItemsLayoutTypeConverter to return new instances based on the orientation string, rather than reusing static ones. This ensures each layout has its own settings, so ItemSpacing doesn't carry over when the page is popped with the back button and opened again using GoToAsync.

Tested the behavior in the following platforms.

  • [x] Windows
  • [x] Mac
  • [x] iOS
  • [x] Android

Issues Fixed

Fixes https://github.com/dotnet/maui/issues/28023

Output

Before Issue Fix After Issue Fix

BagavathiPerumal avatar Apr 25 '25 06:04 BagavathiPerumal

Hey there @@BagavathiPerumal! Thank you so much for your PR! Someone from the team will get assigned to your PR shortly and we'll get it reviewed.

/azp run MAUI-UITests-public

jsuarezruiz avatar Apr 25 '25 11:04 jsuarezruiz

Azure Pipelines successfully started running 1 pipeline(s).

azure-pipelines[bot] avatar Apr 25 '25 11:04 azure-pipelines[bot]

/azp run MAUI-UITests-public

jsuarezruiz avatar Apr 28 '25 06:04 jsuarezruiz

Azure Pipelines successfully started running 1 pipeline(s).

azure-pipelines[bot] avatar Apr 28 '25 06:04 azure-pipelines[bot]

/azp run MAUI-UITests-public

jsuarezruiz avatar May 06 '25 06:05 jsuarezruiz

Azure Pipelines successfully started running 1 pipeline(s).

azure-pipelines[bot] avatar May 06 '25 06:05 azure-pipelines[bot]

https://github.com/dotnet/maui/pull/29683

PureWeen avatar Sep 11 '25 22:09 PureWeen