Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,7 @@ public class ElementViewHolder : RecyclerView.ViewHolder
Element _element;
AView _itemView;
bool _disposed;
bool _updatingVisualState;
Shell _shell;
Action<ElementViewHolder> _disposedCallback;
readonly NativeElementRegistrationSet _nativeElementRegistrations = new NativeElementRegistrationSet();
Expand Down Expand Up @@ -357,10 +358,20 @@ public Element Element

void UpdateVisualState()
{
if (Element is BaseShellItem baseShellItem)
if (_updatingVisualState || Element is not BaseShellItem baseShellItem)
{
return;
}

try
{
_updatingVisualState = true;
VisualStateManager.GoToState(View, baseShellItem.IsChecked ? "Selected" : "Normal", force: true);
}
finally
{
_updatingVisualState = false;
}
}

void OnElementPropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public class UIContainerCell : UITableViewCell
readonly NativeElementRegistrationSet _nativeElementRegistrations = new NativeElementRegistrationSet();
[UnconditionalSuppressMessage("Memory", "MEM0002", Justification = "Resources changed listener is removed and the reference cleared in Disconnect.")]
IElementDefinition _viewResource;
bool _updatingVisualState;

[UnconditionalSuppressMessage("Memory", "MEM0002", Justification = "Measure callback is cleared in Disconnect before the cell is released.")]
internal Action<UIContainerCell> ViewMeasureInvalidated { get; set; }
Expand Down Expand Up @@ -162,10 +163,20 @@ public override void LayoutSubviews()

void UpdateVisualState()
{
if (BindingContext is BaseShellItem bsi)
if (_updatingVisualState || BindingContext is not BaseShellItem bsi)
{
return;
}

try
{
_updatingVisualState = true;
VisualStateManager.GoToState(View, bsi.IsChecked ? "Selected" : "Normal", force: true);
}
finally
{
_updatingVisualState = false;
}
}

void OnElementPropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public partial class ShellFlyoutItemView : ContentControl
View _content;
object _previousDataContext;
Shell _shell;
bool _updatingVisualState;
ShellView ShellView => _shell.Handler?.PlatformView as ShellView;

public ShellFlyoutItemView()
Expand Down Expand Up @@ -148,10 +149,20 @@ void ShellElementPropertyChanged(object sender, PropertyChangedEventArgs e)

void UpdateVisualState()
{
if (_content?.BindingContext is BaseShellItem baseShellItem)
if (_updatingVisualState || _content?.BindingContext is not BaseShellItem baseShellItem)
{
return;
}

try
{
_updatingVisualState = true;
VisualStateManager.GoToState(_content, baseShellItem.IsChecked ? "Selected" : "Normal", force: true);
}
finally
{
_updatingVisualState = false;
}
}

void OnResourcesChanged(object sender, ResourcesChangedEventArgs e)
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
115 changes: 115 additions & 0 deletions src/Controls/tests/TestCases.HostApp/Issues/Issue38813.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
namespace Maui.Controls.Sample.Issues;

[Issue(IssueTracker.Github, 38813, "Shell flyout should not hang", PlatformAffected.All)]
public class Issue38813 : Shell
{
public Issue38813()
{
FlyoutBehavior = FlyoutBehavior.Flyout;

ItemTemplate = new DataTemplate(() =>
{
var grid = new Grid
{
HeightRequest = 50
};

var normalState = new VisualState
{
Name = "Normal"
};

normalState.Setters.Add(new Setter
{
Property = BackgroundProperty,
Value = Colors.White
});

var selectedState = new VisualState
{
Name = "Selected"
};

selectedState.Setters.Add(new Setter
{
Property = BackgroundProperty,
Value = Colors.Blue
});

var visualStateGroup = new VisualStateGroup
{
Name = "CommonStates"
};

visualStateGroup.States.Add(normalState);
visualStateGroup.States.Add(selectedState);

var visualStateGroups = new VisualStateGroupList
{
visualStateGroup
};

VisualStateManager.SetVisualStateGroups(grid, visualStateGroups);

var label = new Label
{
AutomationId = "Issue38813Label",
VerticalTextAlignment = TextAlignment.Center,
Margin = new Thickness(20, 0, 0, 0)
};

label.SetBinding(Label.TextProperty, "Title");

grid.Add(label);

return grid;
});

Items.Add(CreateFlyoutItem("One", "one"));
Items.Add(CreateFlyoutItem("Two", "two"));
Items.Add(CreateFlyoutItem("Three", "three"));
}

static FlyoutItem CreateFlyoutItem(string title, string route)
{
var flyoutItem = new FlyoutItem
{
Title = title,
Route = route
};

flyoutItem.Items.Add(new ShellContent
{
ContentTemplate = new DataTemplate(() => new Issue38813MainPage())
});

return flyoutItem;
}
}

public class Issue38813MainPage : ContentPage
{
public Issue38813MainPage()
{
var button = new Button
{
AutomationId = "Issue38813Button",
Text = "Click To Open Flyout",
HorizontalOptions = LayoutOptions.Center,
VerticalOptions = LayoutOptions.Center
};

button.Clicked += (s, e) =>
{
Shell.Current.FlyoutIsPresented = true;
};

Content = new StackLayout
{
Children =
{
button
}
};
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using NUnit.Framework;
using UITest.Appium;
using UITest.Core;

namespace Microsoft.Maui.TestCases.Tests.Issues;

public class Issue38813 : _IssuesUITest
{
public Issue38813(TestDevice testDevice) : base(testDevice)
{
}

public override string Issue => "Shell flyout should not hang";

[Test]
[Category(UITestCategories.Shell)]
public void ShellFlyoutShouldNotHang()
{
App.WaitForElement("Issue38813Button");
App.Tap("Issue38813Button");
VerifyScreenshot();
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading