Skip to content
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

fix(popup): fall back to PlacementArrangeOverride when popup would otherwise be placed outside the window #19109

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 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 @@ -26,6 +26,27 @@ namespace Uno.UI.RuntimeTests.Tests.Windows_UI_Xaml_Controls
[RunsOnUIThread]
public class Given_TimePicker
{
#if HAS_UNO
[TestMethod]
[RequiresFullWindow]
public async Task When_TimePickerFlyout_Placed_Outside_Window()
{
var btn = new Button
{
HorizontalAlignment = HorizontalAlignment.Right,
Content = "Open Flyout",
Flyout = new TimePickerFlyout()
};

await UITestHelper.Load(btn);
btn.ProgrammaticClick();
await UITestHelper.WaitForIdle();

var presenter = (TimePickerFlyoutPresenter)VisualTreeHelper.GetOpenPopupsForXamlRoot(TestServices.WindowHelper.XamlRoot)[0].Child;
Assert.IsTrue(presenter.GetAbsoluteBoundsRect().IntersectWith(TestServices.WindowHelper.XamlRoot.VisualTree.VisibleBounds).Equals(presenter.GetAbsoluteBoundsRect()));
}
#endif

[TestMethod]
public async Task When_MinuteIncrement_In_Range_Should_Be_Set_Properly()
{
Expand Down
38 changes: 19 additions & 19 deletions src/Uno.UI/UI/Xaml/Controls/Popup/PopupPanel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -121,25 +121,6 @@ protected override Size ArrangeOverride(Size finalSize)
}
else if (Popup.CustomLayouter == null)
{
// TODO: For now, the layouting logic for managed DatePickerFlyout or TimePickerFlyout does not correctly work
// against the placement target approach.
var isFlyoutManagedDatePicker =
(Popup.AssociatedFlyout is DatePickerFlyout || Popup.AssociatedFlyout is TimePickerFlyout)
#if __ANDROID__ || __IOS__
&& (Popup.AssociatedFlyout is not NativeDatePickerFlyout && Popup.AssociatedFlyout is not NativeTimePickerFlyout)
#endif
;

if (!isFlyoutManagedDatePicker &&
Popup.PlacementTarget is not null
#if __ANDROID__ || __IOS__
|| NativeAnchor is not null
#endif
)
{
return PlacementArrangeOverride(Popup, finalSize);
}

// Gets the location of the popup (or its Anchor) in the VisualTree, so we will align Top/Left with it
// Note: we do not prevent overflow of the popup on any side as UWP does not!
// (And actually it also lets the view appear out of the window ...)
Expand Down Expand Up @@ -175,6 +156,25 @@ Popup.PlacementTarget is not null
size.Width,
size.Height);

// TODO: For now, the layouting logic for managed DatePickerFlyout or TimePickerFlyout does not correctly work
// against the placement target approach.
var isFlyoutManagedDatePicker =
(Popup.AssociatedFlyout is DatePickerFlyout || Popup.AssociatedFlyout is TimePickerFlyout)
#if __ANDROID__ || __IOS__
&& (Popup.AssociatedFlyout is not NativeDatePickerFlyout && Popup.AssociatedFlyout is not NativeTimePickerFlyout)
#endif
;

if (!isFlyoutManagedDatePicker && Popup.PlacementTarget is not null
#if __ANDROID__ || __IOS__
|| NativeAnchor is not null
#endif
|| !finalFrame.IntersectWith(GetVisibleBounds()).Equals(finalFrame) // if the finalFrame spills out of the window, always use PlacementArrangeOverride
)
{
return PlacementArrangeOverride(Popup, finalSize);
}

ArrangeElement(child, finalFrame);

// Temporary workaround to avoid layout cycle on iOS. This block was added specifically for a bug on Android's
Expand Down
Loading