Skip to content

Commit

Permalink
The fix for child FlexLayout content appearing no longer works starti…
Browse files Browse the repository at this point in the history
…ng from version 8.0.61 (#26665)

* BindableLayout ItemsSource fix

* Added snapshot for Windows
  • Loading branch information
Tamilarasan-Paranthaman authored Dec 19, 2024
1 parent 9873689 commit 6ea9765
Show file tree
Hide file tree
Showing 8 changed files with 89 additions and 19 deletions.
10 changes: 5 additions & 5 deletions src/Controls/src/Core/Layout/FlexLayout.cs
Original file line number Diff line number Diff line change
Expand Up @@ -495,16 +495,16 @@ void AddFlexItem(int index, IView child)
InitItemProperties(child, item);
if (child is not FlexLayout)
{
item.SelfSizing = (Flex.Item it, ref float w, ref float h) =>
item.SelfSizing = (Flex.Item it, ref float w, ref float h, bool inMeasureMode) =>
{
Size request;

if (InMeasureMode)
if (inMeasureMode)
{
var sizeConstraints = item.GetConstraints();

sizeConstraints.Width = (InMeasureMode && sizeConstraints.Width == 0) ? double.PositiveInfinity : sizeConstraints.Width;
sizeConstraints.Height = (InMeasureMode && sizeConstraints.Height == 0) ? double.PositiveInfinity : sizeConstraints.Height;
sizeConstraints.Width = (inMeasureMode && sizeConstraints.Width == 0) ? double.PositiveInfinity : sizeConstraints.Width;
sizeConstraints.Height = (inMeasureMode && sizeConstraints.Height == 0) ? double.PositiveInfinity : sizeConstraints.Height;

if (child is Image)
{
Expand Down Expand Up @@ -585,7 +585,7 @@ public void Layout(double width, double height)

_root.Width = !double.IsPositiveInfinity((width)) ? (float)width : 0;
_root.Height = !double.IsPositiveInfinity((height)) ? (float)height : 0;
_root.Layout();
_root.Layout(InMeasureMode);

if (useMeasureHack)
{
Expand Down
8 changes: 4 additions & 4 deletions src/Controls/src/Core/LegacyLayouts/FlexLayout.cs
Original file line number Diff line number Diff line change
Expand Up @@ -306,11 +306,11 @@ void AddChild(View view)
InitItemProperties(view, item);
if (!(view is FlexLayout))
{ //inner layouts don't get measured
item.SelfSizing = (Flex.Item it, ref float w, ref float h) =>
item.SelfSizing = (Flex.Item it, ref float w, ref float h, bool inMeasureMode) =>
{
var sizeConstrains = item.GetConstraints();
sizeConstrains.Width = (_measuring && sizeConstrains.Width == 0) ? double.PositiveInfinity : sizeConstrains.Width;
sizeConstrains.Height = (_measuring && sizeConstrains.Height == 0) ? double.PositiveInfinity : sizeConstrains.Height;
sizeConstrains.Width = (inMeasureMode && sizeConstrains.Width == 0) ? double.PositiveInfinity : sizeConstrains.Width;
sizeConstrains.Height = (inMeasureMode && sizeConstrains.Height == 0) ? double.PositiveInfinity : sizeConstrains.Height;
var request = view.Measure(sizeConstrains.Width, sizeConstrains.Height, MeasureFlags.None).Request;
w = (float)request.Width;
h = (float)request.Height;
Expand Down Expand Up @@ -489,7 +489,7 @@ void Layout(double width, double height)
return;
_root.Width = !double.IsPositiveInfinity((width)) ? (float)width : 0;
_root.Height = !double.IsPositiveInfinity((height)) ? (float)height : 0;
_root.Layout();
_root.Layout(_measuring);
}
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
49 changes: 49 additions & 0 deletions src/Controls/tests/TestCases.HostApp/Issues/Issue23491.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
using Microsoft.Maui.Layouts;

namespace Maui.Controls.Sample.Issues
{
[Issue(IssueTracker.Github, 23491, "BindableLayout.ItemsSource no longer works in 8.0.61", PlatformAffected.All)]
public class Issue23491 : ContentPage
{
Label headerLabel;
Label label1;
Label label2;
public Issue23491()
{
headerLabel = new Label { Text = "Below is the Content of the Child FlexLayout",
TextColor=Colors.Red };

headerLabel.AutomationId = "HeaderLabel";

// Child FlexLayout
label1 = new Label
{
Text = "First label inside the child flexlayout",
Padding =new Thickness(5)
};

label2 = new Label
{
Text = "Second label inside the child flexLayout",
Padding =new Thickness(5)
};

var childFlexLayout = new FlexLayout
{
Margin = new Thickness(10),
Wrap = FlexWrap.Wrap,
Children = { label1, label2 }
};

// Main FlexLayout
var mainLayout = new FlexLayout
{
Direction = FlexDirection.Column,
Children = { headerLabel, childFlexLayout }
};

// Set the content of the page
Content = mainLayout;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using NUnit.Framework;
using UITest.Appium;
using UITest.Core;

namespace Microsoft.Maui.TestCases.Tests.Issues
{
public class Issue23491 : _IssuesUITest
{
public Issue23491(TestDevice device) : base(device) { }

public override string Issue => "BindableLayout.ItemsSource no longer works in 8.0.61";

[Test]
[Category(UITestCategories.Label)]
public void ChildFlexLayoutContentShouldAppear()
{
App.WaitForElement("HeaderLabel");
VerifyScreenshot();
}
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
20 changes: 10 additions & 10 deletions src/Core/src/Layouts/Flex.cs
Original file line number Diff line number Diff line change
Expand Up @@ -426,18 +426,18 @@ public Item Root
}
}

public void Layout()
public void Layout(bool inMeasureMode)
{
if (Parent != null)
throw new InvalidOperationException("Layout() must be called on a root item (that hasn't been added to another item)");
if (Double.IsNaN(Width) || Double.IsNaN(Height))
throw new InvalidOperationException("Layout() must be called on an item that has proper values for the Width and Height properties");
if (SelfSizing != null)
throw new InvalidOperationException("Layout() cannot be called on an item that has the SelfSizing property set");
layout_item(this, Width, Height);
layout_item(this, Width, Height, inMeasureMode);
}

public delegate void SelfSizingDelegate(Item item, ref float width, ref float height);
public delegate void SelfSizingDelegate(Item item, ref float width, ref float height, bool inMeasureMode);

public SelfSizingDelegate? SelfSizing { get; set; }

Expand All @@ -449,7 +449,7 @@ void ValidateChild(Item child)
throw new ArgumentException("child already has a parent");
}

static void layout_item(Item item, float width, float height)
static void layout_item(Item item, float width, float height, bool inMeasureMode)
{
if (item == null || item.Count == 0)
return;
Expand All @@ -476,7 +476,7 @@ static void layout_item(Item item, float width, float height)
child.Frame[1] = absolute_pos(child.Top, child.Bottom, child.Frame[3], height);

// Now that the item has a frame, we can layout its children.
layout_item(child, child.Frame[2], child.Frame[3]);
layout_item(child, child.Frame[2], child.Frame[3], inMeasureMode);
continue;
}

Expand Down Expand Up @@ -507,7 +507,7 @@ static void layout_item(Item item, float width, float height)
{
float[] size = { child.Frame[2], child.Frame[3] };

child.SelfSizing(child, ref size[0], ref size[1]);
child.SelfSizing(child, ref size[0], ref size[1], inMeasureMode);

for (int j = 0; j < 2; j++)
{
Expand Down Expand Up @@ -540,7 +540,7 @@ static void layout_item(Item item, float width, float height)
{
// Not enough space for this child on this line, layout the
// remaining items and move it to a new line.
layout_items(item, last_layout_child, i, relative_children_count, ref layout);
layout_items(item, last_layout_child, i, relative_children_count, ref layout, inMeasureMode);

layout.reset();
last_layout_child = i;
Expand Down Expand Up @@ -578,7 +578,7 @@ static void layout_item(Item item, float width, float height)
}

// Layout remaining items in wrap mode, or everything otherwise.
layout_items(item, last_layout_child, item.Count, relative_children_count, ref layout);
layout_items(item, last_layout_child, item.Count, relative_children_count, ref layout, inMeasureMode);

// In wrap mode we may need to tweak the position of each line according to
// the align_content property as well as the cross-axis size of items that
Expand Down Expand Up @@ -729,7 +729,7 @@ static void layout_align(AlignContent align, float flex_dim, uint children_count
}
}

static void layout_items(Item item, int child_begin, int child_end, int children_count, ref flex_layout layout)
static void layout_items(Item item, int child_begin, int child_end, int children_count, ref flex_layout layout, bool inMeasureMode)
{
if (children_count > (child_end - child_begin))
throw new ArgumentException($"The {children_count} must not be smaller than the requested range between {child_begin} and {child_end}", nameof(children_count));
Expand Down Expand Up @@ -850,7 +850,7 @@ static void layout_items(Item item, int child_begin, int child_end, int children
}

// Now that the item has a frame, we can layout its children.
layout_item(child, child.Frame[2], child.Frame[3]);
layout_item(child, child.Frame[2], child.Frame[3], inMeasureMode);
}

if (layout.wrap && !layout.reverse2)
Expand Down

0 comments on commit 6ea9765

Please sign in to comment.