Skip to content

Commit

Permalink
fix: Enable support for ContentDialog in Uno Islands
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinZikmund committed Feb 22, 2023
1 parent c940696 commit 693c244
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ private void SizeAndPositionContentInPopup()
double xOffset = 0;
double yOffset = 0;

var windowBounds = Xaml.Window.Current.Bounds;
var xamlRootSize = XamlRoot?.Size ?? Xaml.Window.Current.Bounds.Size;

var flowDirection = FlowDirection;

Expand All @@ -216,13 +216,13 @@ private void SizeAndPositionContentInPopup()

if (m_placementMode == PlacementMode.EntireControlInPopup)
{
Height = windowBounds.Height;
Width = windowBounds.Width;
Height = xamlRootSize.Height;
Width = xamlRootSize.Width;
}
else if (m_tpLayoutRootPart != null)
{
m_tpLayoutRootPart.Height = windowBounds.Height;
m_tpLayoutRootPart.Width = windowBounds.Width;
m_tpLayoutRootPart.Height = xamlRootSize.Height;
m_tpLayoutRootPart.Width = xamlRootSize.Width;
}

// Uno - omitted code related to display regions, which aren't currently supported
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using Uno.Foundation.Logging;
using Uno.UI;
using Uno.UI.DataBinding;
using Uno.UI.Xaml.Core;
using Windows.Foundation;
using Windows.UI.ViewManagement;
using Windows.UI.Xaml.Controls.Primitives;
Expand Down Expand Up @@ -57,6 +58,12 @@ protected override Size ArrangeOverride(Size finalSize)

private Size CalculateDialogAvailableSize(Size availableSize)
{
// Skip calculation if in the context of Uno Islands.
if (CoreServices.Instance.ContentRootCoordinator.CoreWindowContentRoot is null)
{
return availableSize;
}

var visibleBounds = ApplicationView.GetForCurrentView().TrueVisibleBounds;

if (availableSize.Width > visibleBounds.Width)
Expand All @@ -73,7 +80,15 @@ private Size CalculateDialogAvailableSize(Size availableSize)

private Rect CalculateDialogPlacement(Size desiredSize, Size finalSize)
{
var visibleBounds = ApplicationView.GetForCurrentView().TrueVisibleBounds;
Rect visibleBounds;
if (CoreServices.Instance.ContentRootCoordinator.CoreWindowContentRoot is null)
{
visibleBounds = XamlRoot?.Bounds ?? new Rect(0, 0, finalSize.Width, finalSize.Height);
}
else
{
visibleBounds = ApplicationView.GetForCurrentView().TrueVisibleBounds;
}

var maximumWidth = Math.Min(visibleBounds.Width, finalSize.Width);
var maximumHeight = Math.Min(visibleBounds.Height, finalSize.Height);
Expand Down
4 changes: 2 additions & 2 deletions src/Uno.UI/UI/Xaml/Controls/Popup/Popup.WithPopupRoot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ partial void OnIsOpenChangedPartialNative(bool oldIsOpen, bool newIsOpen)
{
#if !HAS_UNO_WINUI
// In UWP, XamlRoot is set automatically to CoreWindow XamlRoot if not set beforehand.
if (XamlRoot is null)
if (XamlRoot is null && Child.XamlRoot is null)
{
XamlRoot = CoreServices.Instance.ContentRootCoordinator.CoreWindowContentRoot.XamlRoot;
}
Expand All @@ -94,7 +94,7 @@ partial void OnIsOpenChangedPartialNative(bool oldIsOpen, bool newIsOpen)
#if !__SKIA__ // The OpenPopup method should be moved out of Window in general https://github.com/unoplatform/uno/issues/8978
_closePopup.Disposable = Window.Current.OpenPopup(this);
#else
var currentXamlRoot = XamlRoot ?? CoreServices.Instance.ContentRootCoordinator.CoreWindowContentRoot.XamlRoot;
var currentXamlRoot = XamlRoot ?? Child.XamlRoot ?? CoreServices.Instance.ContentRootCoordinator.CoreWindowContentRoot.XamlRoot;
_closePopup.Disposable = currentXamlRoot?.OpenPopup(this);
#endif
PopupPanel.Visibility = Visibility.Visible;
Expand Down

0 comments on commit 693c244

Please sign in to comment.