Skip to content

Commit

Permalink
fix(menuflyout): Ensure MenuFlyout nested submenus stay on screen
Browse files Browse the repository at this point in the history
Fix bug where nested submenus could be shown offscreen on the 2nd and later times they appeared.
  • Loading branch information
davidjohnoliver committed Sep 23, 2021
1 parent 779e773 commit cd13998
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/Uno.UI/UI/Xaml/Controls/MenuFlyout/CascadingMenuHelper.cs
Expand Up @@ -53,6 +53,9 @@ internal class CascadingMenuHelper
// This fallback is used if we fail to retrieve a value from the MenuShowDelay RegKey
const int DefaultMenuShowDelay = 400; // in milliseconds

// Uno-specific workaround (see comment below)
private Point? _lastTargetPoint;

public CascadingMenuHelper()
{
m_isPointerOver = false;
Expand Down Expand Up @@ -567,6 +570,13 @@ internal void OpenSubMenu()
}

ownerAsSubMenuOwner.OpenSubMenu(targetPoint);
if (_lastTargetPoint is { } lastTargetPoint)
{
// Uno-specific workaround: reapply the location calculated in OnPresenterSizeChanged(), since that one properly
// adjusts to keep submenu within screen bounds. (WinUI seemingly relies upon presenter.SizeChanged being raised
// every time submenu opens? On Uno it isn't.)
ownerAsSubMenuOwner.PositionSubMenu(lastTargetPoint);
}
ownerAsSubMenuOwner.RaiseAutomationPeerExpandCollapse(true /* isOpen */);
ElementSoundPlayer.RequestInteractionSoundForElement(ElementSoundKind.Invoke, ownerAsControl);
}
Expand Down Expand Up @@ -932,6 +942,7 @@ public void OnVisibilityChanged()
}
}

_lastTargetPoint = targetPoint;
ownerAsSubMenuOwner.PositionSubMenu(targetPoint);
}
}
Expand Down

0 comments on commit cd13998

Please sign in to comment.