diff options
author | Jason Smith <jason.smith@xamarin.com> | 2016-03-27 15:48:31 -0700 |
---|---|---|
committer | Jason Smith <jason.smith@xamarin.com> | 2016-03-27 15:48:31 -0700 |
commit | 904d06d81269d9b03e148ab1467aeb163c8b736d (patch) | |
tree | 54828569ce77c330a4fdbb8b1467f42a67509f88 | |
parent | 1ee2a1d31138e6da2b048b37a01893146348b6f9 (diff) | |
download | xamarin-forms-904d06d81269d9b03e148ab1467aeb163c8b736d.tar.gz xamarin-forms-904d06d81269d9b03e148ab1467aeb163c8b736d.tar.bz2 xamarin-forms-904d06d81269d9b03e148ab1467aeb163c8b736d.zip |
[C]Remove view from previous parent when added to new parent layout
Technically this could be considered a breaking change if someone was depending on the old behavior, however the old behavior resulted in layouts that were not predictable to the user. So while yes someone could have built something that works, it would have been via trial and error and generally breaking the rule of one parent to each view. Fixes https://bugzilla.xamarin.com/show_bug.cgi?id=39509
-rw-r--r-- | Xamarin.Forms.Core.UnitTests/GroupViewUnitTests.cs | 13 | ||||
-rw-r--r-- | Xamarin.Forms.Core/Layout.cs | 3 |
2 files changed, 16 insertions, 0 deletions
diff --git a/Xamarin.Forms.Core.UnitTests/GroupViewUnitTests.cs b/Xamarin.Forms.Core.UnitTests/GroupViewUnitTests.cs index 61e38cf1..fe823b1a 100644 --- a/Xamarin.Forms.Core.UnitTests/GroupViewUnitTests.cs +++ b/Xamarin.Forms.Core.UnitTests/GroupViewUnitTests.cs @@ -288,5 +288,18 @@ namespace Xamarin.Forms.Core.UnitTests Assert.False (added); Assert.False (removed); } + + [Test] + public void AddToSecondLayoutRemovesFromOriginal() + { + var child = new BoxView(); + var layout1 = new NaiveLayout(); + var layout2 = new NaiveLayout(); + + layout1.Children.Add(child); + layout2.Children.Add(child); + + Assert.False(layout1.Children.Contains(child)); + } } } diff --git a/Xamarin.Forms.Core/Layout.cs b/Xamarin.Forms.Core/Layout.cs index c611777c..a7864070 100644 --- a/Xamarin.Forms.Core/Layout.cs +++ b/Xamarin.Forms.Core/Layout.cs @@ -395,6 +395,9 @@ namespace Xamarin.Forms void OnInternalAdded(View view) { + var parent = view.Parent as Layout; + parent?.InternalChildren.Remove(view); + OnChildAdded(view); if (ShouldInvalidateOnChildAdded(view)) InvalidateLayout(); |