summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Controls.Issues
diff options
context:
space:
mode:
authorSamantha Houts <samhouts@users.noreply.github.com>2017-08-15 15:50:59 (GMT)
committerRui Marinho <me@ruimarinho.net>2017-08-15 15:50:59 (GMT)
commit6b9730ee2b09c429c4b7dbc1b2c450938992268c (patch)
tree7c015de0e67977402b84deac23ef9dccf4941c54 /Xamarin.Forms.Controls.Issues
parent565973a42fc2b6a86dd50fbf2bf6d843b3c6f5e9 (diff)
downloadxamarin-forms-6b9730ee2b09c429c4b7dbc1b2c450938992268c.zip
xamarin-forms-6b9730ee2b09c429c4b7dbc1b2c450938992268c.tar.gz
xamarin-forms-6b9730ee2b09c429c4b7dbc1b2c450938992268c.tar.bz2
[iOS] Prevent ListView HasUnevenRows crash when template w/container Element is swapped (#1095)
* Add repro for 58645 * [iOS] Check for null before clearing element renderer * [iOS] Remove unnecessary code renderer.SetElement(null); == descendant.ClearValue(Platform.RendererProperty); * [iOS] Clarify comment, use preferred method of clearing renderer from Element * How about we make the test work? Sounds like a good idea to me.
Diffstat (limited to 'Xamarin.Forms.Controls.Issues')
-rw-r--r--Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Bugzilla58645.cs140
-rw-r--r--Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Xamarin.Forms.Controls.Issues.Shared.projitems1
2 files changed, 141 insertions, 0 deletions
diff --git a/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Bugzilla58645.cs b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Bugzilla58645.cs
new file mode 100644
index 0000000..87f7d1b
--- /dev/null
+++ b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Bugzilla58645.cs
@@ -0,0 +1,140 @@
+´╗┐using Xamarin.Forms.CustomAttributes;
+using Xamarin.Forms.Internals;
+using System.Collections.ObjectModel;
+
+#if UITEST
+using Xamarin.UITest;
+using NUnit.Framework;
+#endif
+
+namespace Xamarin.Forms.Controls.Issues
+{
+ [Preserve(AllMembers = true)]
+ [Issue(IssueTracker.Bugzilla, 58645, "[iOS] NRE Thrown When ListView Items Are Replaced By Items With a Different Template", PlatformAffected.iOS)]
+ public class Bugzilla58645 : TestContentPage
+ {
+ const string ButtonId = "button";
+ ObservableCollection<string> Items { get; set; }
+
+ protected override void Init()
+ {
+ Items = new ObservableCollection<string> { "Item 1A", "Item 2A", "Item 3A" };
+
+ var myListView = new ListView
+ {
+ HasUnevenRows = true,
+ ItemsSource = Items,
+ ItemTemplate = new LayoutTemplateSelector
+ {
+ LayoutA = new DataTemplate(typeof(LayoutA)),
+ LayoutB = new DataTemplate(typeof(LayoutB))
+ }
+ };
+
+ var switchBtn = new Button
+ {
+ Text = "Switch Items",
+ AutomationId = ButtonId,
+ Command = new Command(() =>
+ {
+ Items.Clear();
+ Items.Add("Item 1B");
+ })
+ };
+
+ Content = new StackLayout
+ {
+ Children =
+ {
+ new Label { Text = "Tap the 'Switch Items' button. If the app does not crash, this test has passed." },
+ switchBtn,
+ myListView
+ }
+ };
+ }
+
+ public class LayoutA : ViewCell
+ {
+ public LayoutA()
+ {
+ var layout = new Grid
+ {
+ Padding = new Thickness(14),
+ ColumnDefinitions =
+ {
+ new ColumnDefinition { Width = GridLength.Auto },
+ new ColumnDefinition { Width = new GridLength(1, GridUnitType.Star) }
+ },
+ RowDefinitions =
+ {
+ new RowDefinition { Height = GridLength.Auto }
+ }
+ };
+
+ var mainLabel = new Label();
+ mainLabel.SetBinding(Label.TextProperty, ".");
+
+ var sw = new Switch();
+ layout.Children.Add(mainLabel, 0, 0);
+ layout.Children.Add(sw, 2, 0);
+ View = layout;
+ }
+ }
+
+ public class LayoutB : ViewCell
+ {
+ public LayoutB()
+ {
+ var layout = new Grid
+ {
+ Padding = new Thickness(14),
+ ColumnDefinitions =
+ {
+ new ColumnDefinition { Width = GridLength.Auto },
+ new ColumnDefinition { Width = new GridLength(1, GridUnitType.Star) }
+ },
+ RowDefinitions =
+ {
+ new RowDefinition { Height = GridLength.Auto }
+ }
+ };
+
+ var mainLabel = new Label();
+ mainLabel.SetBinding(Label.TextProperty, ".");
+
+ var secondLabel = new Label
+ {
+ Text = "B"
+ };
+
+ layout.Children.Add(mainLabel, 0, 0);
+ layout.Children.Add(secondLabel, 2, 0);
+ View = layout;
+ }
+ }
+
+ public class LayoutTemplateSelector : DataTemplateSelector
+ {
+ public DataTemplate LayoutA { get; set; }
+ public DataTemplate LayoutB { get; set; }
+
+ protected override DataTemplate OnSelectTemplate(object item, BindableObject container)
+ {
+ if (item == null)
+ return LayoutA;
+
+ var text = (string)item;
+ return text.Contains("A") ? LayoutA : LayoutB;
+ }
+ }
+
+#if UITEST
+ [Test]
+ public void Bugzilla58645Test()
+ {
+ RunningApp.WaitForElement(q => q.Marked(ButtonId));
+ RunningApp.Tap(q => q.Marked(ButtonId));
+ }
+#endif
+ }
+} \ No newline at end of file
diff --git a/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Xamarin.Forms.Controls.Issues.Shared.projitems b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Xamarin.Forms.Controls.Issues.Shared.projitems
index fe99642..484fea9 100644
--- a/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Xamarin.Forms.Controls.Issues.Shared.projitems
+++ b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Xamarin.Forms.Controls.Issues.Shared.projitems
@@ -315,6 +315,7 @@
<Compile Include="$(MSBuildThisFileDirectory)Bugzilla40161.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Bugzila57749.cs" />
<Compile Include="$(MSBuildThisFileDirectory)ScrollViewObjectDisposed.cs" />
+ <Compile Include="$(MSBuildThisFileDirectory)Bugzilla58645.cs" />
<Compile Include="$(MSBuildThisFileDirectory)_Template.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Bugzilla42620.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Issue1028.cs" />