Skip to content

Commit bdaf59b

Browse files
committed
Removed vestigial UpdateContentLayout() method left over from Forms
The Forms version of ItemContentView called the UpdateContentLayout method when laying out each RecyclerView item to ensure that all cross-platform layout updates were applied. When the CollectionView was ported to MAUI, that method didn't appropriately handle the changes to margins in the layout, so a call to LayoutVirtualView was added to deal with that. Both methods effectively do the same job, so UpdateContentLayout is now redundant. This change removes UpdateContentLayout so we don't lay out (and in some cases re-measure) the content unnecessarily.
1 parent fabfc55 commit bdaf59b

File tree

1 file changed

+16
-47
lines changed

1 file changed

+16
-47
lines changed

src/Controls/src/Core/Handlers/Items/Android/ItemContentView.cs

Lines changed: 16 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
using System;
33
using Android.Content;
44
using Android.Views;
5-
using AndroidX.CoordinatorLayout.Widget;
6-
using AndroidX.Fragment.App;
75
using Microsoft.Maui.Graphics;
86
using AView = Android.Views.View;
97

@@ -23,26 +21,31 @@ public ItemContentView(Context context) : base(context)
2321

2422
internal void ClickOn() => CallOnClick();
2523

24+
AView PlatformView => Content?.ContainerView ?? Content?.PlatformView;
25+
2626
internal void RealizeContent(View view, ItemsView itemsView)
2727
{
2828
Content = CreateHandler(view, itemsView);
29-
var platformView = Content.ContainerView ?? Content.PlatformView;
29+
var platformView = PlatformView;
30+
3031
//make sure we don't belong to a previous Holder
3132
platformView.RemoveFromParent();
3233
AddView(platformView);
3334

34-
//TODO: RUI IS THIS THE BEST WAY TO CAST?
35-
(View as VisualElement).MeasureInvalidated += ElementMeasureInvalidated;
35+
if (View is VisualElement visualElement)
36+
{
37+
visualElement.MeasureInvalidated += ElementMeasureInvalidated;
38+
}
3639
}
3740

3841
internal void Recycle()
3942
{
40-
if (View != null)
43+
if (View is VisualElement visualElement)
4144
{
42-
(View as VisualElement).MeasureInvalidated -= ElementMeasureInvalidated;
45+
visualElement.MeasureInvalidated -= ElementMeasureInvalidated;
4346
}
4447

45-
var platformView = Content?.ContainerView ?? Content?.PlatformView;
48+
var platformView = PlatformView;
4649

4750
if (platformView != null)
4851
{
@@ -66,18 +69,10 @@ protected override void OnLayout(bool changed, int l, int t, int r, int b)
6669
return;
6770
}
6871

69-
var size = this.FromPixels(r - l, b - t);
70-
71-
//TODO: RUI Is this the best way?
72-
//View.Arrange(new Rectangle(Point.Zero, size));
73-
//Arrange doesn't seem to work as expected
74-
75-
if (View?.Handler is not IPlatformViewHandler handler)
76-
return;
77-
78-
handler.LayoutVirtualView(l, t, r, b);
79-
80-
UpdateContentLayout();
72+
if (View?.Handler is IPlatformViewHandler handler)
73+
{
74+
handler.LayoutVirtualView(l, t, r, b);
75+
}
8176
}
8277

8378
protected override void OnMeasure(int widthMeasureSpec, int heightMeasureSpec)
@@ -125,7 +120,7 @@ protected override void OnMeasure(int widthMeasureSpec, int heightMeasureSpec)
125120
SetMeasuredDimension(pixelWidth, pixelHeight);
126121
}
127122

128-
void ElementMeasureInvalidated(object sender, System.EventArgs e)
123+
void ElementMeasureInvalidated(object sender, EventArgs e)
129124
{
130125
if (this.IsAlive())
131126
{
@@ -137,32 +132,6 @@ void ElementMeasureInvalidated(object sender, System.EventArgs e)
137132
}
138133
}
139134

140-
void UpdateContentLayout()
141-
{
142-
VisualElement mauiControlsView = View as VisualElement;
143-
AView aview = Content.ToPlatform();
144-
145-
if (mauiControlsView == null || aview == null)
146-
return;
147-
148-
var x = (int)this.ToPixels(mauiControlsView.X);
149-
var y = (int)this.ToPixels(mauiControlsView.Y);
150-
var width = Math.Max(0, (int)this.ToPixels(mauiControlsView.Width));
151-
var height = Math.Max(0, (int)this.ToPixels(mauiControlsView.Height));
152-
153-
aview.Layout(x, y, width, height);
154-
155-
if ((aview is LayoutViewGroup || aview is ContentViewGroup || aview is CoordinatorLayout || aview is FragmentContainerView) && width == 0 && height == 0)
156-
{
157-
// Nothing to do here; just chill.
158-
}
159-
else
160-
{
161-
aview.Measure(MeasureSpecMode.Exactly.MakeMeasureSpec(width), MeasureSpecMode.Exactly.MakeMeasureSpec(height));
162-
aview.Layout(x, y, x + width, y + height);
163-
}
164-
}
165-
166135
static IPlatformViewHandler CreateHandler(View view, ItemsView itemsView) =>
167136
TemplateHelpers.GetHandler(view, itemsView.FindMauiContext());
168137
}

0 commit comments

Comments
 (0)