-
Notifications
You must be signed in to change notification settings - Fork 1.9k
[Android] -Picker dialog causes crash when page is popped while dialo… #31747
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 3 commits
f9a753c
e1e7a9f
eb6f7d1
e5bc189
7a4989d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,89 @@ | ||
| namespace Maui.Controls.Sample.Issues | ||
| { | ||
| [Issue(IssueTracker.Github, 31731, "Picker dialog causes crash when page is popped while dialog is open", PlatformAffected.Android)] | ||
| public class Issue31731 : NavigationPage | ||
| { | ||
| public Issue31731() : base(new MainPage()) | ||
| { | ||
| } | ||
|
|
||
| public class MainPage : ContentPage | ||
| { | ||
| public MainPage() | ||
| { | ||
| var button = new Button | ||
| { | ||
| Text = "Navigate to Picker Page", | ||
| AutomationId = "navigateButton" | ||
| }; | ||
|
|
||
| button.Clicked += OnNavigateClicked; | ||
|
|
||
| var statusLabel = new Label | ||
| { | ||
| Text = "Status: Ready", | ||
| AutomationId = "statusLabel" | ||
| }; | ||
|
|
||
| Content = new StackLayout | ||
| { | ||
| Padding = new Thickness(20), | ||
| Children = { statusLabel, button } | ||
| }; | ||
| } | ||
|
|
||
| private void OnNavigateClicked(object sender, EventArgs e) | ||
| { | ||
| Navigation.PushAsync(new PickerPage()); | ||
| } | ||
| } | ||
|
|
||
| public class PickerPage : ContentPage | ||
| { | ||
| public PickerPage() | ||
| { | ||
| var picker = new Picker | ||
| { | ||
| Title = "Select a color", | ||
| ItemsSource = new List<string> { "Red", "Green", "Blue", "Yellow", "Purple" }, | ||
| AutomationId = "colorPicker" | ||
| }; | ||
|
|
||
| var instructionsLabel = new Label | ||
| { | ||
| Text = "Tap the picker to open the dialog, then wait for auto navigation back (3 seconds). The app should not crash.", | ||
| AutomationId = "instructionsLabel", | ||
| Margin = new Thickness(0, 0, 0, 20) | ||
| }; | ||
|
|
||
| var statusLabel = new Label | ||
| { | ||
| Text = "Status: Page loaded", | ||
| AutomationId = "pageStatusLabel" | ||
| }; | ||
|
|
||
| Content = new StackLayout | ||
| { | ||
| Padding = new Thickness(20), | ||
| Children = { instructionsLabel, statusLabel, picker } | ||
| }; | ||
| } | ||
|
|
||
| protected override void OnNavigatedTo(NavigatedToEventArgs args) | ||
| { | ||
| base.OnNavigatedTo(args); | ||
|
|
||
| // Simulate the scenario: navigate back after 3 seconds | ||
| // This can cause a crash if the picker dialog is open | ||
| _ = Task.Run(async () => | ||
| { | ||
| await Task.Delay(3000); | ||
| await Dispatcher.DispatchAsync(async () => | ||
| { | ||
| await Navigation.PopToRootAsync(); | ||
| }); | ||
| }); | ||
| } | ||
| } | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| using NUnit.Framework; | ||
| using UITest.Appium; | ||
| using UITest.Core; | ||
|
|
||
| namespace Microsoft.Maui.TestCases.Tests.Issues; | ||
|
|
||
| public class Issue31731 : _IssuesUITest | ||
| { | ||
| public Issue31731(TestDevice testDevice) : base(testDevice) | ||
| { | ||
| } | ||
|
|
||
| public override string Issue => "Picker dialog causes crash when page is popped while dialog is open"; | ||
|
|
||
| [Test] | ||
| [Category(UITestCategories.Picker)] | ||
| public void PickerDialogDoesNotCrashWhenPagePoppedWhileDialogOpen() | ||
| { | ||
| // Wait for the main page to load | ||
| App.WaitForElement("statusLabel"); | ||
| App.WaitForElement("navigateButton"); | ||
|
|
||
| // Navigate to the picker page | ||
| App.Tap("navigateButton"); | ||
|
|
||
| // Wait for picker page to load | ||
| App.WaitForElement("colorPicker"); | ||
| App.WaitForElement("pageStatusLabel"); | ||
|
|
||
| // Open the picker dialog | ||
| App.Tap("colorPicker"); | ||
|
|
||
| // Wait for a moment to ensure dialog is open, then wait for auto navigation | ||
| // The page will automatically pop after 3 seconds | ||
| // If the bug exists, this would cause a crash | ||
| System.Threading.Thread.Sleep(4000); // Wait longer than the 3-second delay | ||
|
|
||
| // If we reach this point without crashing, the test passes | ||
| // Verify we're back on the main page | ||
| App.WaitForElement("statusLabel"); | ||
sheiksyedm marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| App.WaitForElement("navigateButton"); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -28,6 +28,15 @@ protected override void DisconnectHandler(MauiPicker platformView) | |
| { | ||
| platformView.Click -= OnClick; | ||
|
|
||
| if (_dialog != null) | ||
| { | ||
| _dialog.ShowEvent -= OnDialogShown; | ||
| _dialog.DismissEvent -= OnDialogDismiss; | ||
| _dialog.Hide(); | ||
|
||
| _dialog.Dispose(); | ||
| _dialog = null; | ||
| } | ||
|
|
||
| base.DisconnectHandler(platformView); | ||
| } | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.