Fix for picker on hidden page opens after back navigation in Android #25319
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Issues Fixed
Fixes #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.
#8913
Output
24862-BeforeFix.mp4
24862-AfterFix.mp4