@@ -25,14 +25,12 @@ protected override void ConnectHandler(MauiScrollView platformView)
2525 {
2626 base . ConnectHandler ( platformView ) ;
2727 platformView . ScrollChange += ScrollChange ;
28- platformView . CrossPlatformArrange = VirtualView . CrossPlatformArrange ;
2928 }
3029
3130 protected override void DisconnectHandler ( MauiScrollView platformView )
3231 {
3332 base . DisconnectHandler ( platformView ) ;
3433 platformView . ScrollChange -= ScrollChange ;
35- platformView . CrossPlatformArrange = null ;
3634 }
3735
3836 public override Size GetDesiredSize ( double widthConstraint , double heightConstraint )
@@ -234,7 +232,10 @@ static void InsertInsetView(IScrollViewHandler handler, IScrollView scrollView,
234232
235233 Size ICrossPlatformLayout . CrossPlatformMeasure ( double widthConstraint , double heightConstraint )
236234 {
237- var scrollView = VirtualView ;
235+ if ( VirtualView is not { } scrollView )
236+ {
237+ return Size . Zero ;
238+ }
238239
239240 var padding = scrollView . Padding ;
240241
@@ -243,31 +244,25 @@ Size ICrossPlatformLayout.CrossPlatformMeasure(double widthConstraint, double he
243244 return new Size ( padding . HorizontalThickness , padding . VerticalThickness ) ;
244245 }
245246
246- // Exclude the padding while measuring the internal content ...
247- var measurementWidth = widthConstraint - padding . HorizontalThickness ;
248- var measurementHeight = heightConstraint - padding . VerticalThickness ;
249-
250- var result = ( scrollView as ICrossPlatformLayout ) . CrossPlatformMeasure ( measurementWidth , measurementHeight ) ;
251-
252- // ... and add the padding back in to the final result
253- var fullSize = new Size ( result . Width + padding . HorizontalThickness , result . Height + padding . VerticalThickness ) ;
247+ var scrollOrientation = scrollView . Orientation ;
248+ var contentWidthConstraint = scrollOrientation is ScrollOrientation . Horizontal or ScrollOrientation . Both ? double . PositiveInfinity : widthConstraint ;
249+ var contentHeightConstraint = scrollOrientation is ScrollOrientation . Vertical or ScrollOrientation . Both ? double . PositiveInfinity : heightConstraint ;
250+ var contentSize = scrollView . MeasureContent ( scrollView . Padding , contentWidthConstraint , contentHeightConstraint , ! double . IsInfinity ( contentWidthConstraint ) , ! double . IsInfinity ( contentHeightConstraint ) ) ;
254251
255252 if ( double . IsInfinity ( widthConstraint ) )
256253 {
257- widthConstraint = result . Width ;
254+ widthConstraint = contentSize . Width ;
258255 }
259256
260257 if ( double . IsInfinity ( heightConstraint ) )
261258 {
262- heightConstraint = result . Height ;
259+ heightConstraint = contentSize . Height ;
263260 }
264261
265- return fullSize . AdjustForFill ( new Rect ( 0 , 0 , widthConstraint , heightConstraint ) , scrollView . PresentedContent ) ;
262+ return contentSize . AdjustForFill ( new Rect ( 0 , 0 , widthConstraint , heightConstraint ) , scrollView . PresentedContent ) ;
266263 }
267264
268- Size ICrossPlatformLayout . CrossPlatformArrange ( Rect bounds )
269- {
270- return ( VirtualView as ICrossPlatformLayout ) . CrossPlatformArrange ( bounds ) ;
271- }
265+ Size ICrossPlatformLayout . CrossPlatformArrange ( Rect bounds ) =>
266+ ( VirtualView as ICrossPlatformLayout ) ? . CrossPlatformArrange ( bounds ) ?? Size . Zero ;
272267 }
273268}
0 commit comments