summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Controls.Issues
diff options
context:
space:
mode:
authorSamantha Houts <samhouts@users.noreply.github.com>2017-10-18 21:28:18 (GMT)
committerRui Marinho <me@ruimarinho.net>2017-10-18 21:46:09 (GMT)
commit3b9712aaf5d0e8932d1e30facc9ec842a43f6860 (patch)
tree71b91ca39de0c0fc9ad3e5cebe42755c8d3b9e94 /Xamarin.Forms.Controls.Issues
parent0927f1e6889a2f92864c8bfc384cfd4c3fa9c7ed (diff)
downloadxamarin-forms-3b9712aaf5d0e8932d1e30facc9ec842a43f6860.zip
xamarin-forms-3b9712aaf5d0e8932d1e30facc9ec842a43f6860.tar.gz
xamarin-forms-3b9712aaf5d0e8932d1e30facc9ec842a43f6860.tar.bz2
[Android] Prevent ObjectDisposedExceptions in ListViews with Header/FooterTemplates (#1155)
* Update repro to include header/footers with bound props * [Android] Clear renderers of ListView header/footers And don't call `RemoveAllViews`, because that causes the ObjectDisposedExceptions.
Diffstat (limited to 'Xamarin.Forms.Controls.Issues')
-rw-r--r--Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Bugzilla57910.cs110
-rw-r--r--Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/TestPages/QuickCollectNavigationPage.cs15
-rw-r--r--Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Xamarin.Forms.Controls.Issues.Shared.projitems1
3 files changed, 115 insertions, 11 deletions
diff --git a/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Bugzilla57910.cs b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Bugzilla57910.cs
index e76c8e2..ffc9eb9 100644
--- a/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Bugzilla57910.cs
+++ b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Bugzilla57910.cs
@@ -3,6 +3,7 @@ using Xamarin.Forms.Internals;
using System;
using System.Linq;
using System.ComponentModel;
+using System.Collections.ObjectModel;
#if UITEST
using Xamarin.UITest;
@@ -13,7 +14,7 @@ namespace Xamarin.Forms.Controls.Issues
{
[Preserve(AllMembers = true)]
[Issue(IssueTracker.Bugzilla, 57910, "ObjectDisposedException in Xamarin.Forms.Platform.Android.Renderers.ProgressBarRenderer", PlatformAffected.Android)]
- public class Bugzilla57910 : Bugzilla57910QuickCollectNavigationPage
+ public class Bugzilla57910 : QuickCollectNavigationPage
{
const string ButtonId = "btnPush";
const string Button2Id = "btnPop";
@@ -62,6 +63,93 @@ namespace Xamarin.Forms.Controls.Issues
}
[Preserve(AllMembers = true)]
+ class ListHeaderView : ContentView
+ {
+ public ListHeaderView()
+ {
+ Label newLabel = new Label();
+ newLabel.SetBinding(Label.TextProperty, nameof(ListPageViewModel.Header));
+ Content = newLabel;
+ }
+ }
+
+ [Preserve(AllMembers = true)]
+ class ListFooterView : ContentView
+ {
+ public ListFooterView()
+ {
+ Label newLabel = new Label();
+ newLabel.SetBinding(Label.TextProperty, nameof(ListPageViewModel.Footer));
+
+ var stack = new StackLayout { Children = { newLabel } };
+ Content = stack;
+ }
+ }
+
+ [Preserve(AllMembers = true)]
+ class ListPageViewModel : INotifyPropertyChanged
+ {
+ ObservableCollection<ListItemViewModel> _items;
+ string _footer;
+ string _header;
+
+ int _counter;
+ public ListPageViewModel()
+ {
+ _header = "Header!";
+ _footer = "Footer!";
+ _counter = 0;
+ _items = new ObservableCollection<ListItemViewModel>(Enumerable.Range(0, 100).Select(c => new ListItemViewModel()));
+
+ // Need an asynchronous action that happens sometime between creation of the Element and Pop of the containing page
+ Device.StartTimer(TimeSpan.FromMilliseconds((100)), () =>
+ {
+ Header = $"Header! {_counter++}";
+ Footer = $"Footer! {_counter++}";
+
+ return true;
+ });
+ }
+
+ public event PropertyChangedEventHandler PropertyChanged;
+
+ public ObservableCollection<ListItemViewModel> Items
+ {
+ get { return _items; }
+ set
+ {
+ _items = value;
+ OnPropertyChanged(nameof(Items));
+ }
+ }
+
+ public string Header
+ {
+ get { return _header; }
+ set
+ {
+ _header = value;
+ OnPropertyChanged(nameof(Header));
+ }
+ }
+
+ public string Footer
+ {
+ get { return _footer; }
+ set
+ {
+ _footer = value;
+ OnPropertyChanged(nameof(Footer));
+ }
+ }
+
+ protected virtual void OnPropertyChanged(string propertyName)
+ {
+ PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
+ }
+ }
+
+ [Preserve(AllMembers = true)]
class ListItemViewModel : INotifyPropertyChanged
{
double _downloadProgressPercentage;
@@ -128,12 +216,20 @@ namespace Xamarin.Forms.Controls.Issues
ListView listView = new ListView(ListViewCachingStrategy.RecycleElement)
{
RowHeight = 70,
- ItemsSource = Enumerable.Range(0, 100).Select(c => new ListItemViewModel()),
- ItemTemplate = new DataTemplate(typeof(ListItemView))
+ ItemTemplate = new DataTemplate(typeof(ListItemView)),
+ HeaderTemplate = new DataTemplate(typeof(ListHeaderView)),
+ FooterTemplate = new DataTemplate(typeof(ListFooterView)),
};
+
+ listView.SetBinding(ListView.ItemsSourceProperty, nameof(ListPageViewModel.Items));
+ listView.SetBinding(ListView.HeaderProperty, ".");
+ listView.SetBinding(ListView.FooterProperty, ".");
+
Button newButton = new Button { Text = "Pop", AutomationId = Button2Id };
newButton.Clicked += NewButton_Clicked;
Content = new StackLayout { Children = { new Label { Text = Instructions2 }, newButton, listView } };
+
+ BindingContext = new ListPageViewModel();
}
void NewButton_Clicked(object sender, EventArgs e)
@@ -156,12 +252,4 @@ namespace Xamarin.Forms.Controls.Issues
}
#endif
}
-
- [Preserve(AllMembers = true)]
- public class Bugzilla57910QuickCollectNavigationPage : TestNavigationPage
- {
- protected override void Init()
- {
- }
- }
} \ No newline at end of file
diff --git a/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/TestPages/QuickCollectNavigationPage.cs b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/TestPages/QuickCollectNavigationPage.cs
new file mode 100644
index 0000000..b28c9f1
--- /dev/null
+++ b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/TestPages/QuickCollectNavigationPage.cs
@@ -0,0 +1,15 @@
+´╗┐using System;
+using System.Collections.Generic;
+using System.Linq;
+using Xamarin.Forms.Internals;
+
+namespace Xamarin.Forms.Controls
+{
+ [Preserve(AllMembers = true)]
+ public class QuickCollectNavigationPage : TestNavigationPage
+ {
+ protected override void Init()
+ {
+ }
+ }
+}
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 0612d54..7da6778 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
@@ -284,6 +284,7 @@
</Compile>
<Compile Include="$(MSBuildThisFileDirectory)RestartAppTest.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Bugzilla53179_1.cs" />
+ <Compile Include="$(MSBuildThisFileDirectory)TestPages\QuickCollectNavigationPage.cs" />
<Compile Include="$(MSBuildThisFileDirectory)TestPages\ScreenshotConditionalApp.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Bugzilla41842.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Bugzilla42277.cs" />