KEMBAR78
Fix for picker on hidden page opens after back navigation in Android by BagavathiPerumal · Pull Request #25319 · dotnet/maui · GitHub
Skip to content

Conversation

@BagavathiPerumal
Copy link
Contributor

@BagavathiPerumal BagavathiPerumal commented Oct 16, 2024

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.

  • Android
  • Windows
  • Mac
  • iOS

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

Before Issue Fix After Issue Fix
24862-BeforeFix.mp4
24862-AfterFix.mp4

… only pop up when tapped or the Enter key is pressed.
@jsuarezruiz
Copy link
Contributor

jsuarezruiz commented Oct 16, 2024

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 3 pipeline(s).

@BagavathiPerumal BagavathiPerumal marked this pull request as ready for review October 18, 2024 05:27
@BagavathiPerumal BagavathiPerumal requested a review from a team as a code owner October 18, 2024 05:27
@azure-pipelines
Copy link

Azure Pipelines successfully started running 3 pipeline(s).

@jsuarezruiz
Copy link
Contributor

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 3 pipeline(s).

@PureWeen
Copy link
Member

/rebase

Copy link
Member

@PureWeen PureWeen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@BagavathiPerumal
Copy link
Contributor Author

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.

@jsuarezruiz
Copy link
Contributor

/rebase

@sheiksyedm sheiksyedm added the partner/syncfusion Issues / PR's with Syncfusion collaboration label Dec 6, 2024
@BagavathiPerumal BagavathiPerumal marked this pull request as draft February 25, 2025 05:33
@jsuarezruiz
Copy link
Contributor

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 3 pipeline(s).

Copy link
Contributor

@jsuarezruiz jsuarezruiz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The build is failing:

C:\a\_work\1\s\src\Controls\samples\Controls.Sample\Pages\UserInterface\VisualStatesPage.xaml(56,34): XamlC warning XC0022: Binding could be compiled to improve runtime performance if x:DataType is specified. See https://learn.microsoft.com/dotnet/maui/fundamentals/data-binding/compiled-bindings for more information. [C:\a\_work\1\s\src\Controls\samples\Controls.Sample\Maui.Controls.Sample.csproj::TargetFramework=net9.0-windows10.0.20348.0]
C:\a\_work\1\s\src\Controls\tests\TestCases.HostApp\Issues\Issue24862.cs(12,15): error CS0101: The namespace 'Maui.Controls.Sample.Issues' already contains a definition for 'MainPage' [C:\a\_work\1\s\src\Controls\tests\TestCases.HostApp\Controls.TestCases.HostApp.csproj::TargetFramework=net9.0-maccatalyst]
C:\a\_work\1\s\src\Controls\tests\TestCases.HostApp\Issues\Issue24862.cs(14,10): error CS0111: Type 'MainPage' already defines a member called 'MainPage' with the same parameter types [C:\a\_work\1\s\src\Controls\tests\TestCases.HostApp\Controls.TestCases.HostApp.csproj::TargetFramework=net9.0-maccatalyst]
C:\a\_work\1\s\src\Controls\tests\TestCases.HostApp\Issues\Issue24862.cs(12,15): error CS0101: The namespace 'Maui.Controls.Sample.Issues' already contains a definition for 'MainPage' [C:\a\_work\1\s\src\Controls\tests\TestCases.HostApp\Controls.TestCases.HostApp.csproj::TargetFramework=net9.0-ios]
C:\a\_work\1\s\src\Controls\tests\TestCases.HostApp\Issues\Issue24862.cs(14,10): error CS0111: Type 'MainPage' already defines a member called 'MainPage' with the same parameter types [C:\a\_work\1\s\src\Controls\tests\TestCases.HostApp\Controls.TestCases.HostApp.csproj::TargetFramework=net9.0-ios]
C:\a\_work\1\s\src\Controls\tests\TestCases.HostApp\Issues\Issue24862.cs(12,15): error CS0101: The namespace 'Maui.Controls.Sample.Issues' already contains a definition for 'MainPage' [C:\a\_work\1\s\src\Controls\tests\TestCases.HostApp\Controls.TestCases.HostApp.csproj::TargetFramework=net9.0-tizen]
C:\a\_work\1\s\src\Controls\tests\TestCases.HostApp\Issues\Issue24862.cs(14,10): error CS0111: Type 'MainPage' already defines a member called 'MainPage' with the same parameter types [C:\a\_work\1\s\src\Controls\tests\TestCases.HostApp\Controls.TestCases.HostApp.csproj::TargetFramework=net9.0-tizen]
C:\a\_work\1\s\src\Controls\tests\TestCases.HostApp\Issues\Issue24862.cs(12,15): error CS0101: The namespace 'Maui.Controls.Sample.Issues' already contains a definition for 'MainPage' [C:\a\_work\1\s\src\Controls\tests\TestCases.HostApp\Controls.TestCases.HostApp.csproj::TargetFramework=net9.0-android]
C:\a\_work\1\s\src\Controls\tests\TestCases.HostApp\Issues\Issue24862.cs(14,10): error CS0111: Type 'MainPage' already defines a member called 'MainPage' with the same parameter types [C:\a\_work\1\s\src\Controls\tests\TestCases.HostApp\Controls.TestCases.HostApp.csproj::TargetFramework=net9.0-android]
C:\a\_work\1\s\src\Controls\tests\TestCases.HostApp\Issues\Issue24862.cs(12,15): error CS0101: The namespace 'Maui.Controls.Sample.Issues' already contains a definition for 'MainPage' [C:\a\_work\1\s\src\Controls\tests\TestCases.HostApp\Controls.TestCases.HostApp.csproj::TargetFramework=net9.0-windows10.0.20348.0]
C:\a\_work\1\s\src\Controls\tests\TestCases.HostApp\Issues\Issue24862.cs(14,10): error CS0111: Type 'MainPage' already defines a member called 'MainPage' with the same parameter types [C:\a\_work\1\s\src\Controls\tests\TestCases.HostApp\Controls.TestCases.HostApp.csproj::TargetFramework=net9.0-windows10.0.20348.0]
C:\a\_work\1\s\src\Controls\tests\TestCases.HostApp\Issues\Issue24862.cs(12,15): error CS0101: The namespace 'Maui.Controls.Sample.Issues' already contains a definition for 'MainPage' [C:\a\_work\1\s\src\Controls\tests\TestCases.HostApp\Controls.TestCases.HostApp.csproj::TargetFramework=net9.0-windows10.0.19041.0]
C:\a\_work\1\s\src\Controls\tests\TestCases.HostApp\Issues\Issue24862.cs(14,10): error CS0111: Type 'MainPage' already defines a member called 'MainPage' with the same parameter types [C:\a\_work\1\s\src\Controls\tests\TestCases.HostApp\Controls.TestCases.HostApp.csproj::TargetFramework=net9.0-windows10.0.19041.0]
    12 Error(s)

}
}

public class MainPage : ContentPage
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rename to something like Issue24862MainPage.

@PureWeen
Copy link
Member

Closing in favor of #29068

@PureWeen PureWeen closed this Jun 14, 2025
@github-actions github-actions bot locked and limited conversation to collaborators Jul 15, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

area-controls-picker Picker community ✨ Community Contribution partner/syncfusion Issues / PR's with Syncfusion collaboration platform/android

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Android - picker on hidden page opens after back navigation

4 participants