11using System ;
2+ using System . Collections . Generic ;
3+ using System . ComponentModel ;
4+ using System . Drawing ;
5+ using System . Text ;
26using CoreGraphics ;
37using Microsoft . Maui . Graphics ;
48using Microsoft . Maui . Layouts ;
9+ using Microsoft . Maui . Platform ;
10+ using ObjCRuntime ;
511using UIKit ;
612using Size = Microsoft . Maui . Graphics . Size ;
713
@@ -97,11 +103,9 @@ public static void MapOrientation(IScrollViewHandler handler, IScrollView scroll
97103 // without having to re-layout the ScrollView
98104
99105 var fullContentSize = scrollView . PresentedContent ? . DesiredSize ?? Size . Zero ;
100-
101- var viewportBounds = GetViewportBounds ( uiScrollView ) ;
106+ var viewportBounds = uiScrollView . Bounds ;
102107 var viewportWidth = viewportBounds . Width ;
103108 var viewportHeight = viewportBounds . Height ;
104-
105109 SetContentSizeForOrientation ( uiScrollView , viewportWidth , viewportHeight , scrollView . Orientation , fullContentSize ) ;
106110 }
107111
@@ -123,7 +127,7 @@ public static void MapRequestScrollTo(IScrollViewHandler handler, IScrollView sc
123127 var availableScrollWidth = uiScrollView . ContentSize . Width - uiScrollView . Frame . Width ;
124128 var minScrollHorizontal = Math . Min ( request . HorizontalOffset , availableScrollWidth ) ;
125129 var minScrollVertical = Math . Min ( request . VerticalOffset , availableScrollHeight ) ;
126- uiScrollView . SetContentOffset ( new CGPoint ( minScrollHorizontal , minScrollVertical ) , ! request . Instant ) ;
130+ uiScrollView . SetContentOffset ( new CoreGraphics . CGPoint ( minScrollHorizontal , minScrollVertical ) , ! request . Instant ) ;
127131
128132 if ( request . Instant )
129133 {
@@ -181,15 +185,16 @@ static void InsertContentView(UIScrollView platformScrollView, IScrollView scrol
181185 return ;
182186 }
183187
184- var contentContainer = new ContentView
188+ var contentContainer = new ContentView ( )
185189 {
186190 View = scrollView . PresentedContent ,
187- Tag = ContentPanelTag ,
188- // This is where we normally would inject the cross-platform ScrollView's layout logic; instead, we're injecting the
189- // methods from this handler so it can make some adjustments for things like Padding before the default logic is invoked
190- CrossPlatformLayout = crossPlatformLayout
191+ Tag = ContentPanelTag
191192 } ;
192193
194+ // This is where we normally would inject the cross-platform ScrollView's layout logic; instead, we're injecting the
195+ // methods from this handler so it can make some adjustments for things like Padding before the default logic is invoked
196+ contentContainer . CrossPlatformLayout = crossPlatformLayout ;
197+
193198 platformScrollView . ClearSubviews ( ) ;
194199 contentContainer . AddSubview ( platformContent ) ;
195200 platformScrollView . AddSubview ( contentContainer ) ;
@@ -284,11 +289,6 @@ static void SetContentSizeForOrientation(UIScrollView uiScrollView, double viewp
284289 uiScrollView . ContentSize = contentSize ;
285290 }
286291
287- static CGRect GetViewportBounds ( UIScrollView platformScrollView )
288- {
289- return platformScrollView . AdjustedContentInset . InsetRect ( platformScrollView . Bounds ) ;
290- }
291-
292292 Size ICrossPlatformLayout . CrossPlatformMeasure ( double widthConstraint , double heightConstraint )
293293 {
294294 var scrollView = VirtualView ;
@@ -301,18 +301,17 @@ Size ICrossPlatformLayout.CrossPlatformMeasure(double widthConstraint, double he
301301 return Size . Zero ;
302302 }
303303
304- var viewPortBounds = GetViewportBounds ( platformScrollView ) ;
305-
304+ var scrollViewBounds = platformScrollView . Bounds ;
306305 var padding = scrollView . Padding ;
307306
308307 if ( widthConstraint == 0 )
309308 {
310- widthConstraint = viewPortBounds . Width ;
309+ widthConstraint = scrollViewBounds . Width ;
311310 }
312311
313312 if ( heightConstraint == 0 )
314313 {
315- heightConstraint = viewPortBounds . Height ;
314+ heightConstraint = scrollViewBounds . Height ;
316315 }
317316
318317 // Account for the ScrollView Padding before measuring the content
@@ -331,28 +330,29 @@ Size ICrossPlatformLayout.CrossPlatformArrange(Rect bounds)
331330 var crossPlatformLayout = scrollView as ICrossPlatformLayout ;
332331 var platformScrollView = PlatformView ;
333332
333+ var contentSize = crossPlatformLayout . CrossPlatformArrange ( bounds ) ;
334+
334335 // The UIScrollView's bounds are available, so we can use them to make sure the ContentSize makes sense
335336 // for the ScrollView orientation
336- var viewportBounds = GetViewportBounds ( platformScrollView ) ;
337-
338- var contentSize = crossPlatformLayout . CrossPlatformArrange ( viewportBounds . ToRectangle ( ) ) ;
339-
337+ var viewportBounds = platformScrollView . Bounds ;
340338 var viewportHeight = viewportBounds . Height ;
341339 var viewportWidth = viewportBounds . Width ;
342340 SetContentSizeForOrientation ( platformScrollView , viewportWidth , viewportHeight , scrollView . Orientation , contentSize ) ;
343341
344342 var container = GetContentView ( platformScrollView ) ;
345343
346- if ( container != null )
344+ if ( container ? . Superview is UIScrollView uiScrollView )
347345 {
348346 // Ensure the container is at least the size of the UIScrollView itself, so that the
349347 // cross-platform layout logic makes sense and the contents don't arrange outside the
350348 // container. (Everything will look correct if they do, but hit testing won't work properly.)
349+
350+ var scrollViewBounds = uiScrollView . Bounds ;
351351 var containerBounds = contentSize ;
352352
353353 container . Bounds = new CGRect ( 0 , 0 ,
354- Math . Max ( containerBounds . Width , viewportBounds . Width ) ,
355- Math . Max ( containerBounds . Height , viewportBounds . Height ) ) ;
354+ Math . Max ( containerBounds . Width , scrollViewBounds . Width ) ,
355+ Math . Max ( containerBounds . Height , scrollViewBounds . Height ) ) ;
356356
357357 container . Center = new CGPoint ( container . Bounds . GetMidX ( ) , container . Bounds . GetMidY ( ) ) ;
358358 }
0 commit comments