diff --git a/src/Controls/src/Core/Layout/FlexLayout.cs b/src/Controls/src/Core/Layout/FlexLayout.cs index 1e43f5c0ee5a..acebf1f4b6bc 100644 --- a/src/Controls/src/Core/Layout/FlexLayout.cs +++ b/src/Controls/src/Core/Layout/FlexLayout.cs @@ -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) { @@ -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) { diff --git a/src/Controls/src/Core/LegacyLayouts/FlexLayout.cs b/src/Controls/src/Core/LegacyLayouts/FlexLayout.cs index 492669acea70..7bd95120333d 100644 --- a/src/Controls/src/Core/LegacyLayouts/FlexLayout.cs +++ b/src/Controls/src/Core/LegacyLayouts/FlexLayout.cs @@ -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; @@ -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); } } } \ No newline at end of file diff --git a/src/Controls/tests/TestCases.Android.Tests/snapshots/android/ChildFlexLayoutContentShouldAppear.png b/src/Controls/tests/TestCases.Android.Tests/snapshots/android/ChildFlexLayoutContentShouldAppear.png new file mode 100644 index 000000000000..7a16ed1d2891 Binary files /dev/null and b/src/Controls/tests/TestCases.Android.Tests/snapshots/android/ChildFlexLayoutContentShouldAppear.png differ diff --git a/src/Controls/tests/TestCases.HostApp/Issues/Issue23491.cs b/src/Controls/tests/TestCases.HostApp/Issues/Issue23491.cs new file mode 100644 index 000000000000..7772664c0ad1 --- /dev/null +++ b/src/Controls/tests/TestCases.HostApp/Issues/Issue23491.cs @@ -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; + } + } +} \ No newline at end of file diff --git a/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue23491.cs b/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue23491.cs new file mode 100644 index 000000000000..4785757952a2 --- /dev/null +++ b/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue23491.cs @@ -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(); + } + } +} \ No newline at end of file diff --git a/src/Controls/tests/TestCases.WinUI.Tests/snapshots/windows/ChildFlexLayoutContentShouldAppear.png b/src/Controls/tests/TestCases.WinUI.Tests/snapshots/windows/ChildFlexLayoutContentShouldAppear.png new file mode 100644 index 000000000000..dfb1d6852e03 Binary files /dev/null and b/src/Controls/tests/TestCases.WinUI.Tests/snapshots/windows/ChildFlexLayoutContentShouldAppear.png differ diff --git a/src/Controls/tests/TestCases.iOS.Tests/snapshots/ios/ChildFlexLayoutContentShouldAppear.png b/src/Controls/tests/TestCases.iOS.Tests/snapshots/ios/ChildFlexLayoutContentShouldAppear.png new file mode 100644 index 000000000000..ac7eb12b344a Binary files /dev/null and b/src/Controls/tests/TestCases.iOS.Tests/snapshots/ios/ChildFlexLayoutContentShouldAppear.png differ diff --git a/src/Core/src/Layouts/Flex.cs b/src/Core/src/Layouts/Flex.cs index 12272000732e..2ecadeccf1af 100644 --- a/src/Core/src/Layouts/Flex.cs +++ b/src/Core/src/Layouts/Flex.cs @@ -426,7 +426,7 @@ 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)"); @@ -434,10 +434,10 @@ public void Layout() 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; } @@ -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; @@ -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; } @@ -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++) { @@ -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; @@ -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 @@ -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)); @@ -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)