Fix for picker on hidden page opens after back navigation in Android
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 |
|---|---|
/azp run
Azure Pipelines successfully started running 3 pipeline(s).
Azure Pipelines successfully started running 3 pipeline(s).
/azp run
Azure Pipelines successfully started running 3 pipeline(s).
/rebase
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
Pickerbut 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
- We can keep this code how it currently is
- 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.
/rebase
/azp run
Azure Pipelines successfully started running 3 pipeline(s).
Closing in favor of https://github.com/dotnet/maui/pull/29068