1
+ using System ;
2
+ using System . Collections . Generic ;
3
+ using System . Threading . Tasks ;
4
+ using Xamarin . Forms . CustomAttributes ;
5
+ using Xamarin . Forms . Internals ;
6
+
7
+ #if UITEST
8
+ using Xamarin . Forms . Core . UITests ;
9
+ using Xamarin . UITest ;
10
+ using NUnit . Framework ;
11
+ #endif
12
+
13
+ namespace Xamarin . Forms . Controls . Issues
14
+ {
15
+ #if UITEST
16
+ [ Category ( UITestCategories . ManualReview ) ]
17
+ #endif
18
+ [ Preserve ( AllMembers = true ) ]
19
+ [ Issue ( IssueTracker . Github , 10222 , "[CollectionView] ObjectDisposedException if the page is closed during scrolling" , PlatformAffected . iOS ) ]
20
+ public class Issue10222 : TestNavigationPage // or TestMasterDetailPage, etc ...
21
+ {
22
+ protected override void Init ( )
23
+ {
24
+ // Initialize ui here instead of ctor
25
+ Navigation . PushAsync ( new ContentPage
26
+ {
27
+ Content = new Button
28
+ {
29
+ AutomationId = "goTo" ,
30
+ Text = "Go" ,
31
+ Command = new Command ( async ( ) => await Navigation . PushAsync ( new CarouselViewTestPage ( ) ) )
32
+ }
33
+ } ) ;
34
+ }
35
+
36
+ class CarouselViewTestPage : ContentPage
37
+ {
38
+ CollectionView cv ;
39
+ public CarouselViewTestPage ( )
40
+ {
41
+ cv = new CollectionView
42
+ {
43
+ AutomationId = "collectionView" ,
44
+ Margin = new Thickness ( 0 , 40 ) ,
45
+ ItemTemplate = new DataTemplate ( ( ) =>
46
+ {
47
+ var label = new Label
48
+ {
49
+ HorizontalTextAlignment = TextAlignment . Center ,
50
+ Margin = new Thickness ( 0 , 100 )
51
+ } ;
52
+ label . SetBinding ( Label . TextProperty , new Binding ( "." ) ) ;
53
+ return label ;
54
+ } )
55
+ } ;
56
+ Content = cv ;
57
+ InitCV ( ) ;
58
+ }
59
+
60
+ async void InitCV ( )
61
+ {
62
+ var items = new List < string > ( ) ;
63
+ for ( int i = 0 ; i < 10 ; i ++ )
64
+ {
65
+ items . Add ( $ "items{ i } ") ;
66
+ }
67
+
68
+ cv . ItemsSource = items ;
69
+
70
+ //give the cv time to draw the items
71
+ await Task . Delay ( 1000 ) ;
72
+
73
+ cv . ScrollTo ( items . Count - 1 ) ;
74
+
75
+ //give the cv time to scroll
76
+ var rand = new Random ( ) ;
77
+ await Task . Delay ( rand . Next ( 10 , 200 ) ) ;
78
+
79
+ await Navigation . PopAsync ( false ) ;
80
+
81
+ }
82
+ }
83
+
84
+ #if UITEST
85
+ [ Test ]
86
+ public void Issue10222Test ( )
87
+ {
88
+ RunningApp . WaitForElement ( q => q . Marked ( "goTo" ) ) ;
89
+ RunningApp . Tap ( "goTo" ) ;
90
+ RunningApp . WaitForElement ( q => q . Marked ( "collectionView" ) ) ;
91
+ RunningApp . WaitForElement ( q => q . Marked ( "goTo" ) ) ;
92
+ }
93
+ #endif
94
+ }
95
+ }
0 commit comments