Fix NavMenu Interaction Handler bug

This commit is contained in:
polarboy 2024-09-28 22:08:56 +08:00
parent 74bd9e4aa2
commit c8caabbde8
2 changed files with 15 additions and 12 deletions

View File

@ -16,6 +16,7 @@ internal class DefaultNavMenuInteractionHandler : INavMenuInteractionHandler
private IDisposable? _inputManagerSubscription;
private IRenderRoot? _root;
private IDisposable? _currentDelayRunDisposable;
private bool _currentPressedIsValid = false;
public DefaultNavMenuInteractionHandler()
: this(AvaloniaLocator.Current.GetService<IInputManager>(), DefaultDelayRun)
@ -154,6 +155,8 @@ internal class DefaultNavMenuInteractionHandler : INavMenuInteractionHandler
{
return;
}
_currentPressedIsValid = true;
if (sender is Visual visual &&
e.GetCurrentPoint(visual).Properties.IsLeftButtonPressed)
{
@ -192,22 +195,16 @@ internal class DefaultNavMenuInteractionHandler : INavMenuInteractionHandler
protected virtual void PointerReleased(object? sender, PointerReleasedEventArgs e)
{
var item = GetMenuItemCore(e.Source as Control);
if (item is null)
if (item is null || !_currentPressedIsValid)
{
return;
}
if (item is NavMenuItem navMenuItem)
_currentPressedIsValid = false;
if (e.InitialPressMouseButton == MouseButton.Left && item?.HasSubMenu == false)
{
if (!navMenuItem.PointInNavMenuItemHeader(e.GetCurrentPoint(navMenuItem).Position))
{
return;
}
if (e.InitialPressMouseButton == MouseButton.Left && item?.HasSubMenu == false)
{
Click(item);
e.Handled = true;
}
Click(item);
e.Handled = true;
}
}

View File

@ -11,6 +11,8 @@ internal class InlineNavMenuInteractionHandler : INavMenuInteractionHandler
public void Attach(NavMenuBase navMenu) => AttachCore(navMenu);
public void Detach(NavMenuBase navMenu) => DetachCore(navMenu);
private bool _currentPressedIsValid = false;
internal void AttachCore(INavMenu navMenu)
{
if (NavMenu != null)
@ -40,6 +42,8 @@ internal class InlineNavMenuInteractionHandler : INavMenuInteractionHandler
{
return;
}
_currentPressedIsValid = true;
if (sender is Visual visual &&
e.GetCurrentPoint(visual).Properties.IsLeftButtonPressed)
@ -71,11 +75,13 @@ internal class InlineNavMenuInteractionHandler : INavMenuInteractionHandler
protected virtual void PointerReleased(object? sender, PointerReleasedEventArgs e)
{
var item = GetMenuItemCore(e.Source as Control);
if (item is null || !item.PointInNavMenuItemHeader(e.GetCurrentPoint(item).Position))
if (item is null || !_currentPressedIsValid)
{
return;
}
_currentPressedIsValid = false;
if (e.InitialPressMouseButton == MouseButton.Left && !item.HasSubMenu)
{
Click(item);