maui icon indicating copy to clipboard operation
maui copied to clipboard

Fix for picker on hidden page opens after back navigation in Android

Open BagavathiPerumal opened this issue 1 year ago • 7 comments

Root cause

The root cause of the issue is that the picker on MainPage unexpectedly opens the Picker dialog popup in FirstPage when navigating back, even though MainPage is not currently visible. This occurs because the Picker's focus changes during navigation back to FirstPage using Navigation.PopModalAsync(), triggering a click operation on the Picker, which opens the dialog regardless of MainPage's visibility.

Description of Issue Fix

The fix involves removing the auto-open behavior on focus from the Pickers by eliminating the FocusChanged event, which handled the Picker's OnClick operation when focus changed. This adjustment prevents the Picker dialog from opening during page navigation.

Specifically, when the Picker gains focus, the previous implementation would trigger PlatformView.CallOnClick() or OnClick(PlatformView, EventArgs.Empty), leading to the unwanted dialog popup. Additionally, the FocusableInTouchMode property is set to false to ensure that the Pickers do not gain focus unexpectedly.

Tested the behavior in the following platforms.

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

Issues Fixed

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

Reference

Similar code changes have been applied to the DatePicker and TimePicker dialogs to enable auto-opening after resolving the navigation issue. The link to the PR containing the changes is mentioned below.

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

Output

Before Issue Fix After Issue Fix

BagavathiPerumal avatar Oct 16 '24 10:10 BagavathiPerumal

/azp run

jsuarezruiz avatar Oct 16 '24 13:10 jsuarezruiz

Azure Pipelines successfully started running 3 pipeline(s).

azure-pipelines[bot] avatar Oct 16 '24 13:10 azure-pipelines[bot]

Azure Pipelines successfully started running 3 pipeline(s).

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

/azp run

jsuarezruiz avatar Oct 22 '24 13:10 jsuarezruiz

Azure Pipelines successfully started running 3 pipeline(s).

azure-pipelines[bot] avatar Oct 22 '24 13:10 azure-pipelines[bot]

/rebase

PureWeen avatar Oct 24 '24 16:10 PureWeen

Unfortunately, I don't think we'll be able to take this PR as is.

I wish on the PR you referenced we would have also applied this logic to Picker but since we didn't, this isn't really a behavior we can change right now especially if there isn't a replace API to open the picker from code.

My current thought here is

  1. We can keep this code how it currently is
  2. We try to add code so that if the user calls "Focus" directly then we have that trigger the opening of the picker.

@PureWeen, Thank you for the feedback. I understand the limitations here. I'll keep the current code as is and look into alternative solutions for this issue.

BagavathiPerumal avatar Oct 28 '24 06:10 BagavathiPerumal

/rebase

jsuarezruiz avatar Nov 26 '24 12:11 jsuarezruiz

/azp run

jsuarezruiz avatar Mar 25 '25 07:03 jsuarezruiz

Azure Pipelines successfully started running 3 pipeline(s).

azure-pipelines[bot] avatar Mar 25 '25 07:03 azure-pipelines[bot]

Closing in favor of https://github.com/dotnet/maui/pull/29068

PureWeen avatar Jun 14 '25 15:06 PureWeen