@@ -78,6 +78,55 @@ public async Task ContentViewWidthAvailableToChildrenDuringLayout()
7878 Assert . Equal ( 200 , result . ContentViewWidth , 0 ) ;
7979 Assert . Equal ( 200 , result . ChildRecordedWidth , 0 ) ;
8080 }
81+
82+ [ Fact ]
83+ public async Task ContentViewWidthAvailableToChildrenDuringScrolling ( )
84+ {
85+ var contentView = new ContentViewStub ( ) ;
86+ var childView = new TestChildView ( ) ;
87+
88+ contentView . Content = childView ;
89+ contentView . WidthRequest = 200 ;
90+ contentView . HeightRequest = 100 ;
91+
92+ var contentViewHandler = await CreateHandlerAsync ( contentView ) ;
93+
94+ // Simulate multiple layout passes that occur during scrolling in CollectionView
95+ var result = await InvokeOnMainThreadAsync ( ( ) =>
96+ {
97+ // Initial layout
98+ contentView . Measure ( 200 , 100 ) ;
99+ contentView . Arrange ( new Graphics . Rect ( 0 , 0 , 200 , 100 ) ) ;
100+
101+ // Simulate scrolling - multiple measure/arrange cycles with different positions
102+ // This simulates what happens when CollectionView recycles and repositions items during scrolling
103+ for ( int i = 0 ; i < 3 ; i ++ )
104+ {
105+ // Reset the child's recorded width to test each cycle
106+ childView . RecordedParentWidth = - 1 ;
107+
108+ // Simulate different positions during scrolling
109+ var yOffset = i * 10 ;
110+ contentView . Measure ( 200 , 100 ) ;
111+ contentView . Arrange ( new Graphics . Rect ( 0 , yOffset , 200 , 100 + yOffset ) ) ;
112+
113+ // Child should have access to parent width even during position changes
114+ if ( childView . RecordedParentWidth <= 0 )
115+ {
116+ return new { Success = false , ContentViewWidth = contentView . Width , ChildRecordedWidth = childView . RecordedParentWidth , FailedAtIteration = i } ;
117+ }
118+ }
119+
120+ return new { Success = true , ContentViewWidth = contentView . Width , ChildRecordedWidth = childView . RecordedParentWidth , FailedAtIteration = - 1 } ;
121+ } ) ;
122+
123+ // The child should have access to the parent's width during all scrolling scenarios
124+ Assert . True ( result . Success , $ "Child failed to access parent width during scrolling at iteration { result . FailedAtIteration } ") ;
125+ Assert . True ( result . ContentViewWidth > 0 , "ContentView Width should be greater than 0" ) ;
126+ Assert . True ( result . ChildRecordedWidth > 0 , "Child should have recorded a positive parent width during scrolling" ) ;
127+ Assert . Equal ( 200 , result . ContentViewWidth , 0 ) ;
128+ Assert . Equal ( 200 , result . ChildRecordedWidth , 0 ) ;
129+ }
81130 }
82131
83132 public class TestChildView : IView
0 commit comments