From 3ed804c547ba47344cdfcda49c54b24c9a0c5e0b Mon Sep 17 00:00:00 2001 From: David Oliver Date: Wed, 19 May 2021 10:02:35 -0400 Subject: [PATCH] chore: Fix TransformToVisual from Popup to main tree Use GetVisualTreeParent() to ascend the tree, since GetParent() may refer to the logical rather than visual parent. --- src/Uno.UI/UI/Xaml/UIElement.Android.cs | 10 ++-------- src/Uno.UI/UI/Xaml/UIElement.iOS.cs | 10 ++-------- src/Uno.UI/UI/Xaml/UIElement.macOS.cs | 10 ++-------- 3 files changed, 6 insertions(+), 24 deletions(-) diff --git a/src/Uno.UI/UI/Xaml/UIElement.Android.cs b/src/Uno.UI/UI/Xaml/UIElement.Android.cs index ce2466f2f303..5c7be9aa8cab 100644 --- a/src/Uno.UI/UI/Xaml/UIElement.Android.cs +++ b/src/Uno.UI/UI/Xaml/UIElement.Android.cs @@ -153,7 +153,7 @@ internal static GeneralTransform TransformToVisual(View element, View visual) /// 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 @@ -193,7 +193,7 @@ private bool TryGetParentUIElementForTransformToVisual(out UIElement parentEleme do { - parent = parent.GetParent(); + parent = parent.GetVisualTreeParent(); switch (parent) { @@ -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; } } diff --git a/src/Uno.UI/UI/Xaml/UIElement.iOS.cs b/src/Uno.UI/UI/Xaml/UIElement.iOS.cs index 37fc860413dd..abf53ec7c341 100644 --- a/src/Uno.UI/UI/Xaml/UIElement.iOS.cs +++ b/src/Uno.UI/UI/Xaml/UIElement.iOS.cs @@ -142,7 +142,7 @@ internal Windows.Foundation.Point GetPosition(Point position, global::Windows.UI /// 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 @@ -158,7 +158,7 @@ private bool TryGetParentUIElementForTransformToVisual(out UIElement parentEleme case UIView view: do { - parent = parent.GetParent(); + parent = parent.GetVisualTreeParent(); switch (parent) { @@ -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; } } diff --git a/src/Uno.UI/UI/Xaml/UIElement.macOS.cs b/src/Uno.UI/UI/Xaml/UIElement.macOS.cs index fb0aa7e982d5..5520e92c3db4 100644 --- a/src/Uno.UI/UI/Xaml/UIElement.macOS.cs +++ b/src/Uno.UI/UI/Xaml/UIElement.macOS.cs @@ -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 @@ -139,7 +139,7 @@ private bool TryGetParentUIElementForTransformToVisual(out UIElement parentEleme case NSView view: do { - parent = parent?.GetParent(); + parent = parent?.GetVisualTreeParent(); switch (parent) { @@ -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; } }