Skip to content

Commit 8cb0539

Browse files
committed
- update API docs and API features
1 parent 95aa37d commit 8cb0539

File tree

10 files changed

+70
-18
lines changed

10 files changed

+70
-18
lines changed

src/Controls/tests/DeviceTests/Elements/VisualElementTreeTests.cs

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,8 @@ public async Task FindPlatformViewInsideLayout()
111111

112112
await CreateHandlerAndAddToWindow(views, () =>
113113
{
114-
object platformView = button.ToPlatform();
115-
object foundTreeElement = button.ToPlatform().GetVisualTreeElement();
114+
var platformView = button.ToPlatform();
115+
var foundTreeElement = button.ToPlatform().GetVisualTreeElement();
116116

117117
Assert.Equal(button, foundTreeElement);
118118
});
@@ -130,8 +130,8 @@ public async Task FindPlatformViewInsideScrollView()
130130

131131
await CreateHandlerAndAddToWindow(view, () =>
132132
{
133-
object platformView = button.ToPlatform();
134-
object foundTreeElement = button.ToPlatform().GetVisualTreeElement();
133+
var platformView = button.ToPlatform();
134+
var foundTreeElement = button.ToPlatform().GetVisualTreeElement();
135135

136136
Assert.Equal(button, foundTreeElement);
137137
});
@@ -147,8 +147,8 @@ public async Task FindPlatformViewViaDefaultContainer()
147147

148148
await CreateHandlerAndAddToWindow(view, () =>
149149
{
150-
object platformView = button.ToPlatform();
151-
object foundTreeElement = button.ToPlatform().GetVisualTreeElement();
150+
var platformView = button.ToPlatform();
151+
var foundTreeElement = button.ToPlatform().GetVisualTreeElement();
152152

153153
Assert.Equal(button, foundTreeElement);
154154
});
@@ -170,15 +170,17 @@ await CreateHandlerAndAddToWindow<NestingViewHandler>(view, (handler) =>
170170
.AddChild()
171171
.AddChild(button, view);
172172

173-
object platformView = button.ToPlatform();
174-
object foundTreeElement = button.ToPlatform().GetVisualTreeElement();
173+
var platformView = button.ToPlatform();
174+
var foundTreeElement = button.ToPlatform().GetVisualTreeElement();
175175

176176
Assert.Equal(button, foundTreeElement);
177177
});
178178
}
179179

180-
[Fact]
181-
public async Task FindFirstMauiParentElement()
180+
[Theory]
181+
[InlineData(false)]
182+
[InlineData(true)]
183+
public async Task FindFirstMauiParentElement(bool searchAncestors)
182184
{
183185
SetupBuilder();
184186
var viewToLocate = new NestingView();
@@ -193,8 +195,12 @@ await CreateHandlerAndAddToWindow<NestingViewHandler>(view, (handler) =>
193195
.AddChild()
194196
.AddChild();
195197

196-
object foundTreeElement = nestedChild.GetVisualTreeElement();
197-
Assert.Equal(viewToLocate, foundTreeElement);
198+
var foundTreeElement = nestedChild.GetVisualTreeElement(searchAncestors);
199+
200+
if (searchAncestors)
201+
Assert.Equal(viewToLocate, foundTreeElement);
202+
else
203+
Assert.Null(foundTreeElement);
198204
});
199205
}
200206
}

src/Core/src/Core/Extensions/VisualTreeElementExtensions.cs

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -157,10 +157,29 @@ static List<IVisualTreeElement> GetVisualTreeElementsWindowsInternal(IVisualTree
157157
}
158158
#endif
159159

160-
#pragma warning disable RS0016 // Add public types and members to the declared API
160+
/// <summary>
161+
/// Locates the Visual Tree Element that's a best for the given platform view.
162+
/// If an exact Visual Tree Element counterpart isn't found, then
163+
/// we will return the first Visual Tree Element we can find by searching through the
164+
/// ancestors of the given platform view.
165+
/// </summary>
166+
/// <param name="platformView">The platform view</param>
167+
/// <returns><see cref="IVisualTreeElement"/></returns>
168+
public static IVisualTreeElement? GetVisualTreeElement(
169+
this PlatformView platformView) =>
170+
platformView.GetVisualTreeElement(true);
171+
172+
/// <summary>
173+
/// Locates the Visual Tree Element that's a best for the given platform view.
174+
/// If searchAncestors is set to true we will return the first Visual Tree Element
175+
/// we can find by searching through the ancestors of the given platform view, otherwise
176+
/// we will just return null.
177+
/// </summary>
178+
/// <param name="platformView">The platform view</param>
179+
/// <param name="searchAncestors"></param>
180+
/// <returns><see cref="IVisualTreeElement"/></returns>
161181
public static IVisualTreeElement? GetVisualTreeElement(
162-
this PlatformView platformView)
163-
#pragma warning restore RS0016 // Add public types and members to the declared API
182+
this PlatformView platformView, bool searchAncestors)
164183
{
165184
var platformParentPath = new List<PlatformView>();
166185
IVisualTreeElement? foundParent = null;
@@ -194,7 +213,18 @@ static List<IVisualTreeElement> GetVisualTreeElementsWindowsInternal(IVisualTree
194213
// Let's search back down the xplat tree to figure out what IElement to return
195214
// This searches down the xplat tree to figure out what path going down the xplat tree
196215
// matches up against the path we took to go up the platform tree
197-
return FindNextChild(foundParent, platformView, platformParentPath);
216+
var returnValue = FindNextChild(foundParent, platformView, platformParentPath);
217+
218+
// If we aren't searching ancestors, then we only want to return
219+
// IVTE if it matches the found platformView
220+
if (!searchAncestors &&
221+
returnValue != null &&
222+
!returnValue.IsThisMyPlatformView(platformView))
223+
{
224+
return null;
225+
}
226+
227+
return returnValue;
198228

199229
static IVisualTreeElement? FindNextChild(
200230
IVisualTreeElement parent,

src/Core/src/PublicAPI/net-android/PublicAPI.Unshipped.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,8 @@ static Microsoft.Maui.SizeRequest.operator ==(Microsoft.Maui.SizeRequest left, M
106106
*REMOVED*override Microsoft.Maui.Handlers.ViewHandler.SetVirtualView(Microsoft.Maui.IElement! element) -> void
107107
override Microsoft.Maui.Platform.WrapperView.Visibility.get -> Android.Views.ViewStates
108108
override Microsoft.Maui.Platform.WrapperView.Visibility.set -> void
109+
static Microsoft.Maui.VisualTreeElementExtensions.GetVisualTreeElement(this Android.Views.View! platformView) -> Microsoft.Maui.IVisualTreeElement?
110+
static Microsoft.Maui.VisualTreeElementExtensions.GetVisualTreeElement(this Android.Views.View! platformView, bool searchAncestors) -> Microsoft.Maui.IVisualTreeElement?
109111
~override Microsoft.Maui.Platform.WrapperView.DrawShadow(Android.Graphics.Canvas canvas, int viewWidth, int viewHeight) -> void
110112
~override Microsoft.Maui.Platform.WrapperView.GetClipPath(int width, int height) -> Android.Graphics.Path
111113
*REMOVED*Microsoft.Maui.IContentView.CrossPlatformArrange(Microsoft.Maui.Graphics.Rect bounds) -> Microsoft.Maui.Graphics.Size

src/Core/src/PublicAPI/net-ios/PublicAPI.Unshipped.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,8 @@ static Microsoft.Maui.PropertyMapperExtensions.PrependToMapping<TVirtualView, TV
9797
static Microsoft.Maui.PropertyMapperExtensions.ReplaceMapping<TVirtualView, TViewHandler>(this Microsoft.Maui.IPropertyMapper<Microsoft.Maui.IElement!, Microsoft.Maui.IElementHandler!>! propertyMapper, string! key, System.Action<TViewHandler, TVirtualView>! method) -> void
9898
static Microsoft.Maui.SizeRequest.operator !=(Microsoft.Maui.SizeRequest left, Microsoft.Maui.SizeRequest right) -> bool
9999
static Microsoft.Maui.SizeRequest.operator ==(Microsoft.Maui.SizeRequest left, Microsoft.Maui.SizeRequest right) -> bool
100+
static Microsoft.Maui.VisualTreeElementExtensions.GetVisualTreeElement(this UIKit.UIView! platformView) -> Microsoft.Maui.IVisualTreeElement?
101+
static Microsoft.Maui.VisualTreeElementExtensions.GetVisualTreeElement(this UIKit.UIView! platformView, bool searchAncestors) -> Microsoft.Maui.IVisualTreeElement?
100102
virtual Microsoft.Maui.MauiUIApplicationDelegate.PerformFetch(UIKit.UIApplication! application, System.Action<UIKit.UIBackgroundFetchResult>! completionHandler) -> void
101103
Microsoft.Maui.Platform.MauiView.CacheMeasureConstraints(double widthConstraint, double heightConstraint) -> void
102104
Microsoft.Maui.Platform.MauiView.InvalidateConstraintsCache() -> void

src/Core/src/PublicAPI/net-maccatalyst/PublicAPI.Unshipped.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,8 @@ static Microsoft.Maui.PropertyMapperExtensions.ReplaceMapping<TVirtualView, TVie
100100
static Microsoft.Maui.SizeRequest.operator !=(Microsoft.Maui.SizeRequest left, Microsoft.Maui.SizeRequest right) -> bool
101101
static Microsoft.Maui.SizeRequest.operator ==(Microsoft.Maui.SizeRequest left, Microsoft.Maui.SizeRequest right) -> bool
102102
Microsoft.Maui.LifecycleEvents.iOSLifecycle.PerformFetch
103+
static Microsoft.Maui.VisualTreeElementExtensions.GetVisualTreeElement(this UIKit.UIView! platformView) -> Microsoft.Maui.IVisualTreeElement?
104+
static Microsoft.Maui.VisualTreeElementExtensions.GetVisualTreeElement(this UIKit.UIView! platformView, bool searchAncestors) -> Microsoft.Maui.IVisualTreeElement?
103105
virtual Microsoft.Maui.MauiUIApplicationDelegate.PerformFetch(UIKit.UIApplication! application, System.Action<UIKit.UIBackgroundFetchResult>! completionHandler) -> void
104106
*REMOVED*Microsoft.Maui.IContentView.CrossPlatformArrange(Microsoft.Maui.Graphics.Rect bounds) -> Microsoft.Maui.Graphics.Size
105107
*REMOVED*Microsoft.Maui.IContentView.CrossPlatformMeasure(double widthConstraint, double heightConstraint) -> Microsoft.Maui.Graphics.Size

src/Core/src/PublicAPI/net-tizen/PublicAPI.Unshipped.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,3 +60,5 @@ Microsoft.Maui.IMenuElement.Accelerators.get -> System.Collections.Generic.IRead
6060
*REMOVED*Microsoft.Maui.IContentView.CrossPlatformMeasure(double widthConstraint, double heightConstraint) -> Microsoft.Maui.Graphics.Size
6161
*REMOVED*Microsoft.Maui.ILayout.CrossPlatformArrange(Microsoft.Maui.Graphics.Rect bounds) -> Microsoft.Maui.Graphics.Size
6262
*REMOVED*Microsoft.Maui.ILayout.CrossPlatformMeasure(double widthConstraint, double heightConstraint) -> Microsoft.Maui.Graphics.Size
63+
static Microsoft.Maui.VisualTreeElementExtensions.GetVisualTreeElement(this object! platformView) -> Microsoft.Maui.IVisualTreeElement?
64+
static Microsoft.Maui.VisualTreeElementExtensions.GetVisualTreeElement(this object! platformView, bool searchAncestors) -> Microsoft.Maui.IVisualTreeElement?

src/Core/src/PublicAPI/net-windows/PublicAPI.Unshipped.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,3 +88,5 @@ static Microsoft.Maui.Handlers.MenuFlyoutSubItemHandler.MapAccelerator(Microsoft
8888
*REMOVED*override Microsoft.Maui.Platform.ContentPanel.MeasureOverride(Windows.Foundation.Size availableSize) -> Windows.Foundation.Size
8989
*REMOVED*override Microsoft.Maui.Platform.LayoutPanel.MeasureOverride(Windows.Foundation.Size availableSize) -> Windows.Foundation.Size
9090
static Microsoft.Maui.Handlers.DatePickerHandler.MapBackground(Microsoft.Maui.Handlers.IDatePickerHandler! handler, Microsoft.Maui.IDatePicker! datePicker) -> void
91+
static Microsoft.Maui.VisualTreeElementExtensions.GetVisualTreeElement(this Microsoft.UI.Xaml.FrameworkElement! platformView) -> Microsoft.Maui.IVisualTreeElement?
92+
static Microsoft.Maui.VisualTreeElementExtensions.GetVisualTreeElement(this Microsoft.UI.Xaml.FrameworkElement! platformView, bool searchAncestors) -> Microsoft.Maui.IVisualTreeElement?

src/Core/src/PublicAPI/net/PublicAPI.Unshipped.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,4 +59,6 @@ static Microsoft.Maui.SizeRequest.operator ==(Microsoft.Maui.SizeRequest left, M
5959
*REMOVED*Microsoft.Maui.IContentView.CrossPlatformArrange(Microsoft.Maui.Graphics.Rect bounds) -> Microsoft.Maui.Graphics.Size
6060
*REMOVED*Microsoft.Maui.IContentView.CrossPlatformMeasure(double widthConstraint, double heightConstraint) -> Microsoft.Maui.Graphics.Size
6161
*REMOVED*Microsoft.Maui.ILayout.CrossPlatformArrange(Microsoft.Maui.Graphics.Rect bounds) -> Microsoft.Maui.Graphics.Size
62-
*REMOVED*Microsoft.Maui.ILayout.CrossPlatformMeasure(double widthConstraint, double heightConstraint) -> Microsoft.Maui.Graphics.Size
62+
*REMOVED*Microsoft.Maui.ILayout.CrossPlatformMeasure(double widthConstraint, double heightConstraint) -> Microsoft.Maui.Graphics.Size
63+
static Microsoft.Maui.VisualTreeElementExtensions.GetVisualTreeElement(this object! platformView) -> Microsoft.Maui.IVisualTreeElement?
64+
static Microsoft.Maui.VisualTreeElementExtensions.GetVisualTreeElement(this object! platformView, bool searchAncestors) -> Microsoft.Maui.IVisualTreeElement?

src/Core/src/PublicAPI/netstandard/PublicAPI.Unshipped.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,3 +60,5 @@ Microsoft.Maui.IAccelerator.Modifiers.get -> System.Collections.Generic.IReadOnl
6060
*REMOVED*Microsoft.Maui.IContentView.CrossPlatformMeasure(double widthConstraint, double heightConstraint) -> Microsoft.Maui.Graphics.Size
6161
*REMOVED*Microsoft.Maui.ILayout.CrossPlatformArrange(Microsoft.Maui.Graphics.Rect bounds) -> Microsoft.Maui.Graphics.Size
6262
*REMOVED*Microsoft.Maui.ILayout.CrossPlatformMeasure(double widthConstraint, double heightConstraint) -> Microsoft.Maui.Graphics.Size
63+
static Microsoft.Maui.VisualTreeElementExtensions.GetVisualTreeElement(this object! platformView) -> Microsoft.Maui.IVisualTreeElement?
64+
static Microsoft.Maui.VisualTreeElementExtensions.GetVisualTreeElement(this object! platformView, bool searchAncestors) -> Microsoft.Maui.IVisualTreeElement?

src/Core/src/PublicAPI/netstandard2.0/PublicAPI.Unshipped.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,4 +59,6 @@ static Microsoft.Maui.SizeRequest.operator ==(Microsoft.Maui.SizeRequest left, M
5959
*REMOVED*Microsoft.Maui.IContentView.CrossPlatformArrange(Microsoft.Maui.Graphics.Rect bounds) -> Microsoft.Maui.Graphics.Size
6060
*REMOVED*Microsoft.Maui.IContentView.CrossPlatformMeasure(double widthConstraint, double heightConstraint) -> Microsoft.Maui.Graphics.Size
6161
*REMOVED*Microsoft.Maui.ILayout.CrossPlatformArrange(Microsoft.Maui.Graphics.Rect bounds) -> Microsoft.Maui.Graphics.Size
62-
*REMOVED*Microsoft.Maui.ILayout.CrossPlatformMeasure(double widthConstraint, double heightConstraint) -> Microsoft.Maui.Graphics.Size
62+
*REMOVED*Microsoft.Maui.ILayout.CrossPlatformMeasure(double widthConstraint, double heightConstraint) -> Microsoft.Maui.Graphics.Size
63+
static Microsoft.Maui.VisualTreeElementExtensions.GetVisualTreeElement(this object! platformView) -> Microsoft.Maui.IVisualTreeElement?
64+
static Microsoft.Maui.VisualTreeElementExtensions.GetVisualTreeElement(this object! platformView, bool searchAncestors) -> Microsoft.Maui.IVisualTreeElement?

0 commit comments

Comments
 (0)