[Core] Fix layout padding update issue (#4166)
authorSeungkeun Lee <sngn.lee@samsung.com>
Fri, 26 Oct 2018 06:59:14 +0000 (15:59 +0900)
committerStephane Delcroix <stephane@delcroix.org>
Fri, 26 Oct 2018 07:00:01 +0000 (09:00 +0200)
- Update PaddingPropertyChanged handler
 - Add UnitTest for Padding
 - Update ControlGallery

- fixes #4165

Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Issue2763.cs
Xamarin.Forms.Core.UnitTests/StackLayoutUnitTests.cs
Xamarin.Forms.Core/Layout.cs

index 35a9f9d..d6e21fa 100644 (file)
@@ -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 },
index fb4a8aa..1c91e10 100644 (file)
@@ -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");
+               }
        }
 }
index 4d1c8f7..d88e6cd 100644 (file)
@@ -102,7 +102,7 @@ namespace Xamarin.Forms
 
                void IPaddingElement.OnPaddingPropertyChanged(Thickness oldValue, Thickness newValue)
                {
-                       InvalidateMeasureInternal(InvalidationTrigger.MeasureChanged);
+                       InvalidateLayout();
                }
 
                internal ObservableCollection<Element> InternalChildren { get; } = new ObservableCollection<Element>();