maui icon indicating copy to clipboard operation
maui copied to clipboard

Picker in ListView works on Windows but not on Android

Open NanthiniMahalingam opened this issue 1 year ago • 42 comments

Root cause :

  • The issue arises because the SelectedItem of the Picker is updated before the ItemsSource. As a result, in the OnItemsSourceChanged method of the Picker class, the SelectedItem is cleared when the new ItemsSource is set, causing the picker to lose its selected item and leaving the SelectedIndex unchanged.

Description of change :

  • I updated the SelectedIndex when the SelectedItem has a value and the SelectedIndex is -1, before applying the ClampSelectedIndex check while updating the ItemsSource.

Tested the behaviour in the following platforms.

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

Issues Fixed

Fixes #13558

Output

Before

image

After

image

NanthiniMahalingam avatar Aug 23 '24 13:08 NanthiniMahalingam

/azp run

jfversluis avatar Aug 27 '24 14:08 jfversluis

Azure Pipelines successfully started running 3 pipeline(s).

azure-pipelines[bot] avatar Aug 27 '24 14:08 azure-pipelines[bot]

Azure Pipelines successfully started running 3 pipeline(s).

azure-pipelines[bot] avatar Aug 28 '24 07:08 azure-pipelines[bot]

/azp run

rmarinho avatar Aug 28 '24 15:08 rmarinho

Azure Pipelines successfully started running 3 pipeline(s).

azure-pipelines[bot] avatar Aug 28 '24 15:08 azure-pipelines[bot]

/azp run

PureWeen avatar Oct 21 '24 15:10 PureWeen

Azure Pipelines successfully started running 3 pipeline(s).

azure-pipelines[bot] avatar Oct 21 '24 15:10 azure-pipelines[bot]

/azp run

jsuarezruiz avatar Oct 25 '24 09:10 jsuarezruiz

Azure Pipelines successfully started running 3 pipeline(s).

azure-pipelines[bot] avatar Oct 25 '24 09:10 azure-pipelines[bot]

/azp run

jsuarezruiz avatar Oct 28 '24 11:10 jsuarezruiz

Azure Pipelines successfully started running 3 pipeline(s).

azure-pipelines[bot] avatar Oct 28 '24 11:10 azure-pipelines[bot]

/rebase

jsuarezruiz avatar Nov 12 '24 11:11 jsuarezruiz

/azp run

jsuarezruiz avatar Nov 12 '24 11:11 jsuarezruiz

Azure Pipelines successfully started running 3 pipeline(s).

azure-pipelines[bot] avatar Nov 12 '24 11:11 azure-pipelines[bot]

/rebase

jsuarezruiz avatar Nov 18 '24 12:11 jsuarezruiz

/azp run

jsuarezruiz avatar Nov 18 '24 12:11 jsuarezruiz

Azure Pipelines successfully started running 3 pipeline(s).

azure-pipelines[bot] avatar Nov 18 '24 12:11 azure-pipelines[bot]

/azp run

jsuarezruiz avatar Nov 22 '24 10:11 jsuarezruiz

Azure Pipelines successfully started running 3 pipeline(s).

azure-pipelines[bot] avatar Nov 22 '24 10:11 azure-pipelines[bot]

This unit tests is failing based on the changes in TemplatedItemsList.cs:

 Failed HookAndUnhookContentOnReplace [1 ms]
 Error Message:
 Assert.Equal() Failure: Values differ
Expected: Baz
Actual:   null

Hi @jsuarezruiz ,

The unit test HookAndUnhookContentOnReplace is passing successfully on my local machine, and I have attached a screenshot for your reference. Please let us know if you have any further concerns. image

NanthiniMahalingam avatar Nov 28 '24 05:11 NanthiniMahalingam

Azure Pipelines successfully started running 3 pipeline(s).

azure-pipelines[bot] avatar Dec 17 '24 13:12 azure-pipelines[bot]

/rebase

jfversluis avatar Jan 06 '25 08:01 jfversluis

Azure Pipelines successfully started running 3 pipeline(s).

azure-pipelines[bot] avatar Jan 06 '25 08:01 azure-pipelines[bot]

There are a couple of ListView related unit tests failing:

  • HookAndUnhookContentOnReplace
  • SetupContentOnCreation

Could you take a look?

Hi @jsuarezruiz ,

I’ve updated the fix and applied it to the Picker control. Could you please review the changes and let me know if you have any concerns?

KarthikRajaKalaimani avatar Jan 20 '25 13:01 KarthikRajaKalaimani

/azp run

jsuarezruiz avatar Jan 21 '25 12:01 jsuarezruiz

Azure Pipelines successfully started running 3 pipeline(s).

azure-pipelines[bot] avatar Jan 21 '25 12:01 azure-pipelines[bot]

/azp run

jsuarezruiz avatar Jan 23 '25 07:01 jsuarezruiz

Azure Pipelines successfully started running 3 pipeline(s).

azure-pipelines[bot] avatar Jan 23 '25 07:01 azure-pipelines[bot]

@NanthiniMahalingam is this PR related https://github.com/dotnet/maui/pull/26777 ?

PureWeen avatar Jan 23 '25 21:01 PureWeen

@NanthiniMahalingam is this PR related #26777 ?

@PureWeen The scenario #26777 mentioned does not get resolved by this PR. I also tested the fix in this PR with scenario #26777, but it did not resolve the issue either. Additionally the fix implemented in #26777 does not fix this PR scenario. This PR resolves the case where the SelectedItem is set before the ItemsSource is set for the Picker.

KarthikRajaKalaimani avatar Jan 24 '25 06:01 KarthikRajaKalaimani