@@ -25,12 +25,14 @@ protected override void ConnectHandler(MauiScrollView platformView)
2525 {
2626 base . ConnectHandler ( platformView ) ;
2727 platformView . ScrollChange += ScrollChange ;
28+ platformView . CrossPlatformArrange = VirtualView . CrossPlatformArrange ;
2829 }
2930
3031 protected override void DisconnectHandler ( MauiScrollView platformView )
3132 {
3233 base . DisconnectHandler ( platformView ) ;
3334 platformView . ScrollChange -= ScrollChange ;
35+ platformView . CrossPlatformArrange = null ;
3436 }
3537
3638 public override Size GetDesiredSize ( double widthConstraint , double heightConstraint )
@@ -232,10 +234,7 @@ static void InsertInsetView(IScrollViewHandler handler, IScrollView scrollView,
232234
233235 Size ICrossPlatformLayout . CrossPlatformMeasure ( double widthConstraint , double heightConstraint )
234236 {
235- if ( VirtualView is not { } scrollView )
236- {
237- return Size . Zero ;
238- }
237+ var scrollView = VirtualView ;
239238
240239 var padding = scrollView . Padding ;
241240
@@ -244,25 +243,31 @@ Size ICrossPlatformLayout.CrossPlatformMeasure(double widthConstraint, double he
244243 return new Size ( padding . HorizontalThickness , padding . VerticalThickness ) ;
245244 }
246245
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 ) ) ;
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 ) ;
251254
252255 if ( double . IsInfinity ( widthConstraint ) )
253256 {
254- widthConstraint = contentSize . Width ;
257+ widthConstraint = result . Width ;
255258 }
256259
257260 if ( double . IsInfinity ( heightConstraint ) )
258261 {
259- heightConstraint = contentSize . Height ;
262+ heightConstraint = result . Height ;
260263 }
261264
262- return contentSize . AdjustForFill ( new Rect ( 0 , 0 , widthConstraint , heightConstraint ) , scrollView . PresentedContent ) ;
265+ return fullSize . AdjustForFill ( new Rect ( 0 , 0 , widthConstraint , heightConstraint ) , scrollView . PresentedContent ) ;
263266 }
264267
265- Size ICrossPlatformLayout . CrossPlatformArrange ( Rect bounds ) =>
266- ( VirtualView as ICrossPlatformLayout ) ? . CrossPlatformArrange ( bounds ) ?? Size . Zero ;
268+ Size ICrossPlatformLayout . CrossPlatformArrange ( Rect bounds )
269+ {
270+ return ( VirtualView as ICrossPlatformLayout ) . CrossPlatformArrange ( bounds ) ;
271+ }
267272 }
268273}
0 commit comments