Skip to content

Commit

Permalink
chore: Fix TransformToVisual from Popup to main tree
Browse files Browse the repository at this point in the history
Use GetVisualTreeParent() to ascend the tree, since GetParent() may refer to the logical rather than visual parent.
  • Loading branch information
davidjohnoliver committed May 19, 2021
1 parent 4b545f6 commit 3ed804c
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 24 deletions.
10 changes: 2 additions & 8 deletions src/Uno.UI/UI/Xaml/UIElement.Android.cs
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ internal static GeneralTransform TransformToVisual(View element, View visual)
/// </summary>
private bool TryGetParentUIElementForTransformToVisual(out UIElement parentElement, ref double offsetX, ref double offsetY)
{
var parent = this.GetParent();
var parent = this.GetVisualTreeParent();
switch (parent)
{
// First we try the direct parent, if it's from the known type we won't even have to adjust offsets
Expand Down Expand Up @@ -193,7 +193,7 @@ private bool TryGetParentUIElementForTransformToVisual(out UIElement parentEleme

do
{
parent = parent.GetParent();
parent = parent.GetVisualTreeParent();

switch (parent)
{
Expand All @@ -219,12 +219,6 @@ private bool TryGetParentUIElementForTransformToVisual(out UIElement parentEleme
return false;
}
} while (true);

default:
Application.Current.RaiseRecoverableUnhandledException(new InvalidOperationException("Found a parent which is NOT a View."));

parentElement = null;
return false;
}
}

Expand Down
10 changes: 2 additions & 8 deletions src/Uno.UI/UI/Xaml/UIElement.iOS.cs
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ internal Windows.Foundation.Point GetPosition(Point position, global::Windows.UI
/// </summary>
private bool TryGetParentUIElementForTransformToVisual(out UIElement parentElement, ref double offsetX, ref double offsetY)
{
var parent = this.GetParent();
var parent = this.GetVisualTreeParent();
switch (parent)
{
// First we try the direct parent, if it's from the known type we won't even have to adjust offsets
Expand All @@ -158,7 +158,7 @@ private bool TryGetParentUIElementForTransformToVisual(out UIElement parentEleme
case UIView view:
do
{
parent = parent.GetParent();
parent = parent.GetVisualTreeParent();

switch (parent)
{
Expand Down Expand Up @@ -196,12 +196,6 @@ private bool TryGetParentUIElementForTransformToVisual(out UIElement parentEleme
return false;
}
} while (true);

default:
Application.Current.RaiseRecoverableUnhandledException(new InvalidOperationException("Found a parent which is NOT a UIView."));

parentElement = null;
return false;
}
}

Expand Down
10 changes: 2 additions & 8 deletions src/Uno.UI/UI/Xaml/UIElement.macOS.cs
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ private protected override void OnNativeKeyDown(NSEvent evt)

private bool TryGetParentUIElementForTransformToVisual(out UIElement parentElement, ref double offsetX, ref double offsetY)
{
var parent = this.GetParent();
var parent = this.GetVisualTreeParent();
switch (parent)
{
// First we try the direct parent, if it's from the known type we won't even have to adjust offsets
Expand All @@ -139,7 +139,7 @@ private bool TryGetParentUIElementForTransformToVisual(out UIElement parentEleme
case NSView view:
do
{
parent = parent?.GetParent();
parent = parent?.GetVisualTreeParent();

switch (parent)
{
Expand All @@ -166,12 +166,6 @@ private bool TryGetParentUIElementForTransformToVisual(out UIElement parentEleme
return false;
}
} while (true);

default:
Application.Current.RaiseRecoverableUnhandledException(new InvalidOperationException("Found a parent which is NOT a NSView."));

parentElement = null;
return false;
}
}

Expand Down

0 comments on commit 3ed804c

Please sign in to comment.