1
1
using System ;
2
- using System . Collections . Generic ;
3
- using System . ComponentModel ;
4
- using System . Drawing ;
5
- using System . Text ;
6
2
using CoreGraphics ;
7
3
using Microsoft . Maui . Graphics ;
8
4
using Microsoft . Maui . Layouts ;
9
- using Microsoft . Maui . Platform ;
10
- using ObjCRuntime ;
11
5
using UIKit ;
12
6
using Size = Microsoft . Maui . Graphics . Size ;
13
7
@@ -103,9 +97,11 @@ public static void MapOrientation(IScrollViewHandler handler, IScrollView scroll
103
97
// without having to re-layout the ScrollView
104
98
105
99
var fullContentSize = scrollView . PresentedContent ? . DesiredSize ?? Size . Zero ;
106
- var viewportBounds = uiScrollView . Bounds ;
100
+
101
+ var viewportBounds = GetViewportBounds ( uiScrollView ) ;
107
102
var viewportWidth = viewportBounds . Width ;
108
103
var viewportHeight = viewportBounds . Height ;
104
+
109
105
SetContentSizeForOrientation ( uiScrollView , viewportWidth , viewportHeight , scrollView . Orientation , fullContentSize ) ;
110
106
}
111
107
@@ -127,7 +123,7 @@ public static void MapRequestScrollTo(IScrollViewHandler handler, IScrollView sc
127
123
var availableScrollWidth = uiScrollView . ContentSize . Width - uiScrollView . Frame . Width ;
128
124
var minScrollHorizontal = Math . Min ( request . HorizontalOffset , availableScrollWidth ) ;
129
125
var minScrollVertical = Math . Min ( request . VerticalOffset , availableScrollHeight ) ;
130
- uiScrollView . SetContentOffset ( new CoreGraphics . CGPoint ( minScrollHorizontal , minScrollVertical ) , ! request . Instant ) ;
126
+ uiScrollView . SetContentOffset ( new CGPoint ( minScrollHorizontal , minScrollVertical ) , ! request . Instant ) ;
131
127
132
128
if ( request . Instant )
133
129
{
@@ -185,16 +181,15 @@ static void InsertContentView(UIScrollView platformScrollView, IScrollView scrol
185
181
return ;
186
182
}
187
183
188
- var contentContainer = new ContentView ( )
184
+ var contentContainer = new ContentView
189
185
{
190
186
View = scrollView . PresentedContent ,
191
- Tag = ContentPanelTag
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
192
191
} ;
193
192
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
-
198
193
platformScrollView . ClearSubviews ( ) ;
199
194
contentContainer . AddSubview ( platformContent ) ;
200
195
platformScrollView . AddSubview ( contentContainer ) ;
@@ -289,6 +284,11 @@ static void SetContentSizeForOrientation(UIScrollView uiScrollView, double viewp
289
284
uiScrollView . ContentSize = contentSize ;
290
285
}
291
286
287
+ static CGRect GetViewportBounds ( UIScrollView platformScrollView )
288
+ {
289
+ return platformScrollView . AdjustedContentInset . InsetRect ( platformScrollView . Bounds ) ;
290
+ }
291
+
292
292
Size ICrossPlatformLayout . CrossPlatformMeasure ( double widthConstraint , double heightConstraint )
293
293
{
294
294
var scrollView = VirtualView ;
@@ -301,17 +301,18 @@ Size ICrossPlatformLayout.CrossPlatformMeasure(double widthConstraint, double he
301
301
return Size . Zero ;
302
302
}
303
303
304
- var scrollViewBounds = platformScrollView . Bounds ;
304
+ var viewPortBounds = GetViewportBounds ( platformScrollView ) ;
305
+
305
306
var padding = scrollView . Padding ;
306
307
307
308
if ( widthConstraint == 0 )
308
309
{
309
- widthConstraint = scrollViewBounds . Width ;
310
+ widthConstraint = viewPortBounds . Width ;
310
311
}
311
312
312
313
if ( heightConstraint == 0 )
313
314
{
314
- heightConstraint = scrollViewBounds . Height ;
315
+ heightConstraint = viewPortBounds . Height ;
315
316
}
316
317
317
318
// Account for the ScrollView Padding before measuring the content
@@ -330,29 +331,28 @@ Size ICrossPlatformLayout.CrossPlatformArrange(Rect bounds)
330
331
var crossPlatformLayout = scrollView as ICrossPlatformLayout ;
331
332
var platformScrollView = PlatformView ;
332
333
333
- var contentSize = crossPlatformLayout . CrossPlatformArrange ( bounds ) ;
334
-
335
334
// The UIScrollView's bounds are available, so we can use them to make sure the ContentSize makes sense
336
335
// for the ScrollView orientation
337
- var viewportBounds = platformScrollView . Bounds ;
336
+ var viewportBounds = GetViewportBounds ( platformScrollView ) ;
337
+
338
+ var contentSize = crossPlatformLayout . CrossPlatformArrange ( viewportBounds . ToRectangle ( ) ) ;
339
+
338
340
var viewportHeight = viewportBounds . Height ;
339
341
var viewportWidth = viewportBounds . Width ;
340
342
SetContentSizeForOrientation ( platformScrollView , viewportWidth , viewportHeight , scrollView . Orientation , contentSize ) ;
341
343
342
344
var container = GetContentView ( platformScrollView ) ;
343
345
344
- if ( container ? . Superview is UIScrollView uiScrollView )
346
+ if ( container != null )
345
347
{
346
348
// Ensure the container is at least the size of the UIScrollView itself, so that the
347
349
// cross-platform layout logic makes sense and the contents don't arrange outside the
348
350
// container. (Everything will look correct if they do, but hit testing won't work properly.)
349
-
350
- var scrollViewBounds = uiScrollView . Bounds ;
351
351
var containerBounds = contentSize ;
352
352
353
353
container . Bounds = new CGRect ( 0 , 0 ,
354
- Math . Max ( containerBounds . Width , scrollViewBounds . Width ) ,
355
- Math . Max ( containerBounds . Height , scrollViewBounds . Height ) ) ;
354
+ Math . Max ( containerBounds . Width , viewportBounds . Width ) ,
355
+ Math . Max ( containerBounds . Height , viewportBounds . Height ) ) ;
356
356
357
357
container . Center = new CGPoint ( container . Bounds . GetMidX ( ) , container . Bounds . GetMidY ( ) ) ;
358
358
}
0 commit comments