Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The fix for child FlexLayout content appearing no longer works starting from version 8.0.61 #26665

Merged
merged 2 commits into from
Dec 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
Copy link
Preview

Copilot AI Dec 17, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The change in the delegate signature is potentially a breaking change. Please ensure that this change is documented and communicated appropriately.

This comment was generated based on a coding guideline created by a repository admin.

Copilot is powered by AI, so mistakes are possible. Review output carefully before use.

Positive Feedback
Negative Feedback

Provide additional feedback

Please help us improve GitHub Copilot by sharing more details about this comment.

Please select one or more of the options

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
Loading