From 2eff1bb43d679a9fe21a9019bce2827cc28ebff8 Mon Sep 17 00:00:00 2001 From: Seungkeun Lee Date: Fri, 26 Oct 2018 15:59:14 +0900 Subject: [PATCH] [Core] Fix layout padding update issue (#4166) - Update PaddingPropertyChanged handler - Add UnitTest for Padding - Update ControlGallery - fixes #4165 --- .../Issue2763.cs | 26 +++++++++ .../StackLayoutUnitTests.cs | 68 ++++++++++++++++++++++ Xamarin.Forms.Core/Layout.cs | 2 +- 3 files changed, 95 insertions(+), 1 deletion(-) diff --git a/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Issue2763.cs b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Issue2763.cs index 35a9f9d..d6e21fa 100644 --- a/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Issue2763.cs +++ b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Issue2763.cs @@ -13,9 +13,11 @@ namespace Xamarin.Forms.Controls { protected override void Init() { + Title = "Padding update issue"; StackLayout parentLayout1 = null; StackLayout parentLayout2 = null; StackLayout parentLayout3 = null; + StackLayout parentLayout4 = null; StackLayout stackLayout = new StackLayout { @@ -32,6 +34,22 @@ namespace Xamarin.Forms.Controls } } }; + StackLayout stackLayout2 = new StackLayout + { + HorizontalOptions = LayoutOptions.FillAndExpand, + VerticalOptions = LayoutOptions.FillAndExpand, + BackgroundColor = Color.Blue, + Children = + { + new BoxView + { + HorizontalOptions = LayoutOptions.Start, + Color = Color.Red, + HeightRequest = 100, + WidthRequest = 100, + } + } + }; ContentView contentView = new ContentView { @@ -73,6 +91,7 @@ namespace Xamarin.Forms.Controls stackLayout.SetBinding(Forms.Layout.PaddingProperty, new Binding() { Path = "Value", Source = paddingSlider }); contentView.SetBinding(Forms.Layout.PaddingProperty, new Binding() { Path = "Value", Source = paddingSlider }); flex.SetBinding(Forms.Layout.PaddingProperty, new Binding() { Path = "Value", Source = paddingSlider }); + stackLayout2.SetBinding(Forms.Layout.PaddingProperty, new Binding() { Path = "Value", Source = paddingSlider }); // Build the page. this.Padding = new Thickness(20); @@ -105,6 +124,8 @@ namespace Xamarin.Forms.Controls parentLayout2.Children.Remove(boxview); parentLayout3.Children.Add(boxview); parentLayout3.Children.Remove(boxview); + parentLayout4.Children.Add(boxview); + parentLayout4.Children.Remove(boxview); }) }, new ScrollView @@ -116,6 +137,11 @@ namespace Xamarin.Forms.Controls Spacing = 20, Children = { + (parentLayout4 = new StackLayout + { + HeightRequest = 200, + Children = { new Label { Text = "StackLayout2" }, stackLayout2 }, + }), (parentLayout1 = new StackLayout { Children = { new Label { Text = "StackLayout" }, stackLayout }, diff --git a/Xamarin.Forms.Core.UnitTests/StackLayoutUnitTests.cs b/Xamarin.Forms.Core.UnitTests/StackLayoutUnitTests.cs index fb4a8aa..1c91e10 100644 --- a/Xamarin.Forms.Core.UnitTests/StackLayoutUnitTests.cs +++ b/Xamarin.Forms.Core.UnitTests/StackLayoutUnitTests.cs @@ -615,5 +615,73 @@ namespace Xamarin.Forms.Core.UnitTests stack.Layout (new Rectangle (0, 0, 100, 100)); } + + [Test] + public void PaddingResizeTest() + { + var child = new BoxView + { + IsPlatformEnabled = true, + WidthRequest = 20, + HeightRequest = 20, + }; + + var innerStack = new StackLayout + { + HorizontalOptions = LayoutOptions.Center, + VerticalOptions = LayoutOptions.Center, + IsPlatformEnabled = true, + Children = { child } + }; + + var outterLayout = new StackLayout + { + HorizontalOptions = LayoutOptions.FillAndExpand, + VerticalOptions = LayoutOptions.FillAndExpand, + IsPlatformEnabled = true, + Platform = new UnitPlatform(), + Children = { innerStack } + }; + + outterLayout.Layout(new Rectangle(0, 0, 100, 100)); + var beforeSize = innerStack.Bounds.Size; + innerStack.Padding = new Thickness(30); + var afterSize = innerStack.Bounds.Size; + Assert.AreNotEqual(beforeSize, afterSize, "Padding was grow, so Size should be bigger"); + } + + [Test] + public void PaddingChildRelayoutTest() + { + var child = new BoxView + { + IsPlatformEnabled = true, + WidthRequest = 20, + HeightRequest = 20, + }; + + var innerStack = new StackLayout + { + HorizontalOptions = LayoutOptions.FillAndExpand, + VerticalOptions = LayoutOptions.FillAndExpand, + IsPlatformEnabled = true, + Children = { child } + }; + + var outterLayout = new StackLayout + { + HorizontalOptions = LayoutOptions.FillAndExpand, + VerticalOptions = LayoutOptions.FillAndExpand, + IsPlatformEnabled = true, + Platform = new UnitPlatform(), + Children = { innerStack } + }; + + outterLayout.Layout(new Rectangle(0, 0, 100, 100)); + var before = child.Bounds; + innerStack.Padding = new Thickness(30); + var after = child.Bounds; + Assert.AreNotEqual(before, after, "child should be moved within padding size"); + } } } diff --git a/Xamarin.Forms.Core/Layout.cs b/Xamarin.Forms.Core/Layout.cs index 4d1c8f7..d88e6cd 100644 --- a/Xamarin.Forms.Core/Layout.cs +++ b/Xamarin.Forms.Core/Layout.cs @@ -102,7 +102,7 @@ namespace Xamarin.Forms void IPaddingElement.OnPaddingPropertyChanged(Thickness oldValue, Thickness newValue) { - InvalidateMeasureInternal(InvalidationTrigger.MeasureChanged); + InvalidateLayout(); } internal ObservableCollection InternalChildren { get; } = new ObservableCollection(); -- 2.7.4