forked from xamarin/Xamarin.Forms
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[All] Crash fixes for ListViews (xamarin#243)
* [Controls] Add repro for 42277 * [Android] No crash if GroupHeaderTemplate=null * [Android] Fix DataTemplateSelector crash * [Core] Expose ListProxy on TIL * [iOS] Fix DataTemplateSelector crash * [Win] Fix DataTemplateSelector crash * [Docs] Update docs * [Core] Implement ListProxy explicitly Allows ListProxy property to stay internal. * [Controls] Revert unnecessary change to shproj
- Loading branch information
Showing
8 changed files
with
154 additions
and
9 deletions.
There are no files selected for viewing
121 changes: 121 additions & 0 deletions
121
Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Bugzilla42277.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
using System; | ||
using System.Linq; | ||
using Xamarin.Forms.CustomAttributes; | ||
using Xamarin.Forms.Internals; | ||
using System.Collections.Generic; | ||
|
||
#if UITEST | ||
using Xamarin.UITest; | ||
using NUnit.Framework; | ||
#endif | ||
|
||
namespace Xamarin.Forms.Controls | ||
{ | ||
[Preserve(AllMembers = true)] | ||
[Issue(IssueTracker.Bugzilla, 42277, "DataTemplate System.InvalidCastException crash in 2.3.1-pre1")] | ||
public class Bugzilla42277 : TestContentPage | ||
{ | ||
const string Success1 = "Success1"; | ||
const string Success2 = "Success2"; | ||
const string Success3 = "GroupedSuccess3"; | ||
const string Success4 = "GroupedSuccess4"; | ||
const string Success5 = "GroupedSuccess5"; | ||
const string Success6 = "GroupedSuccess6"; | ||
|
||
class MyDataTemplateSelector : DataTemplateSelector | ||
{ | ||
DataTemplate _1Template; | ||
DataTemplate _2Template; | ||
|
||
DataTemplate _3Template; | ||
DataTemplate _4Template; | ||
DataTemplate _5Template; | ||
DataTemplate _6Template; | ||
|
||
public MyDataTemplateSelector() | ||
{ | ||
_1Template = new DataTemplate(() => | ||
{ | ||
return new TextCell { Text = Success1 }; | ||
}); | ||
|
||
_2Template = new DataTemplate(() => | ||
{ | ||
return new TextCell { Text = Success2 }; | ||
}); | ||
|
||
_3Template = new DataTemplate(() => | ||
{ | ||
return new TextCell { Text = Success3 }; | ||
}); | ||
|
||
_4Template = new DataTemplate(() => | ||
{ | ||
return new TextCell { Text = Success4 }; | ||
}); | ||
|
||
_5Template = new DataTemplate(() => | ||
{ | ||
return new TextCell { Text = Success5 }; | ||
}); | ||
|
||
_6Template = new DataTemplate(() => | ||
{ | ||
return new TextCell { Text = Success6 }; | ||
}); | ||
} | ||
|
||
protected override DataTemplate OnSelectTemplate(object item, BindableObject container) | ||
{ | ||
int number = (int)item; | ||
switch (number) | ||
{ | ||
default: | ||
case 0: return _1Template; | ||
case 1: return _2Template; | ||
case 2: return _3Template; | ||
case 3: return _4Template; | ||
case 4: return _5Template; | ||
case 5: return _6Template; | ||
} | ||
} | ||
} | ||
|
||
protected override void Init() | ||
{ | ||
//test non-grouped DTS | ||
ListView listView = new ListView(ListViewCachingStrategy.RecycleElement) | ||
{ | ||
ItemsSource = Enumerable.Range(0, 2), | ||
ItemTemplate = new MyDataTemplateSelector() | ||
}; | ||
|
||
//test grouped DTS | ||
ListView groupedListView = new ListView(ListViewCachingStrategy.RecycleElement) | ||
{ | ||
ItemsSource = new List<List<int>> { Enumerable.Range(2, 2).ToList(), Enumerable.Range(4, 2).ToList() }, | ||
IsGroupingEnabled = true, | ||
ItemTemplate = new MyDataTemplateSelector() | ||
}; | ||
|
||
Content = new StackLayout { Children = { listView, groupedListView } }; | ||
|
||
//test collection changed | ||
listView.ItemsSource = Enumerable.Range(0, 2); | ||
groupedListView.ItemsSource = new List<List<int>> { Enumerable.Range(2, 2).ToList(), Enumerable.Range(4, 2).ToList() }; | ||
} | ||
|
||
#if UITEST | ||
[Test] | ||
public void Bugzilla42277Test() | ||
{ | ||
RunningApp.WaitForElement(q => q.Marked(Success1)); | ||
RunningApp.WaitForElement(q => q.Marked(Success2)); | ||
RunningApp.WaitForElement(q => q.Marked(Success3)); | ||
RunningApp.WaitForElement(q => q.Marked(Success4)); | ||
RunningApp.WaitForElement(q => q.Marked(Success5)); | ||
RunningApp.WaitForElement(q => q.Marked(Success6)); | ||
} | ||
#endif | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters