@@ -93,9 +93,12 @@ public static void MapVerticalScrollBarVisibility(IScrollViewHandler handler, IS
93
93
94
94
public static void MapOrientation ( IScrollViewHandler handler , IScrollView scrollView )
95
95
{
96
- if ( GetContentView ( handler . PlatformView ) is ContentView currentContentContainer )
96
+ if ( handler ? . PlatformView is UIScrollView uiScrollView )
97
97
{
98
- currentContentContainer . SetNeedsLayout ( ) ;
98
+ var fullContentSize = scrollView . PresentedContent ? . DesiredSize ?? Size . Zero ;
99
+ var viewportWidth = uiScrollView . Bounds . Width ;
100
+ var viewportHeight = uiScrollView . Bounds . Height ;
101
+ SetContentSizeForOrientation ( uiScrollView , viewportWidth , viewportHeight , scrollView . Orientation , fullContentSize ) ;
99
102
}
100
103
}
101
104
@@ -198,9 +201,12 @@ static Func<Rect, Size> ArrangeScrollViewContent(Func<Rect, Size> internalArrang
198
201
Math . Max ( containerBounds . Height , scrollViewBounds . Height ) ) ;
199
202
container . Center = new CGPoint ( container . Bounds . GetMidX ( ) , container . Bounds . GetMidY ( ) ) ;
200
203
}
204
+
201
205
var contentSize = internalArrange ( rect ) ;
202
- var size = SetContentSizeForOrientation ( platformScrollView , scrollView . Orientation , contentSize ) ;
203
- return size ;
206
+
207
+ SetContentSizeForOrientation ( platformScrollView , platformScrollView . Bounds . Width , platformScrollView . Bounds . Height , scrollView . Orientation , contentSize ) ;
208
+
209
+ return contentSize ;
204
210
} ;
205
211
}
206
212
@@ -258,16 +264,19 @@ public override Size GetDesiredSize(double widthConstraint, double heightConstra
258
264
widthConstraint = AccountForPadding ( widthConstraint , padding . HorizontalThickness ) ;
259
265
heightConstraint = AccountForPadding ( heightConstraint , padding . VerticalThickness ) ;
260
266
261
- var crossPlatformSize = virtualView . CrossPlatformMeasure ( widthConstraint , heightConstraint ) ;
267
+ var crossPlatformContentSize = virtualView . CrossPlatformMeasure ( widthConstraint , heightConstraint ) ;
262
268
263
269
// Add the padding back in for the final size
264
- crossPlatformSize . Width += padding . HorizontalThickness ;
265
- crossPlatformSize . Height += padding . VerticalThickness ;
270
+ crossPlatformContentSize . Width += padding . HorizontalThickness ;
271
+ crossPlatformContentSize . Height += padding . VerticalThickness ;
272
+
273
+ var viewportWidth = Math . Min ( crossPlatformContentSize . Width , widthConstraint ) ;
274
+ var viewportHeight = Math . Min ( crossPlatformContentSize . Height , heightConstraint ) ;
266
275
267
- var size = SetContentSizeForOrientation ( platformView , virtualView . Orientation , crossPlatformSize ) ;
276
+ SetContentSizeForOrientation ( platformView , widthConstraint , heightConstraint , virtualView . Orientation , crossPlatformContentSize ) ;
268
277
269
- var finalWidth = ViewHandlerExtensions . ResolveConstraints ( size . Width , virtualView . Width , virtualView . MinimumWidth , virtualView . MaximumWidth ) ;
270
- var finalHeight = ViewHandlerExtensions . ResolveConstraints ( size . Height , virtualView . Height , virtualView . MinimumHeight , virtualView . MaximumHeight ) ;
278
+ var finalWidth = ViewHandlerExtensions . ResolveConstraints ( viewportWidth , virtualView . Width , virtualView . MinimumWidth , virtualView . MaximumWidth ) ;
279
+ var finalHeight = ViewHandlerExtensions . ResolveConstraints ( viewportHeight , virtualView . Height , virtualView . MinimumHeight , virtualView . MaximumHeight ) ;
271
280
272
281
return new Size ( finalWidth , finalHeight ) ;
273
282
}
@@ -304,27 +313,19 @@ static double AccountForPadding(double constraint, double padding)
304
313
return Math . Max ( 0 , constraint - padding ) ;
305
314
}
306
315
307
- static Size SetContentSizeForOrientation ( UIScrollView platformScrollView , ScrollOrientation orientation , Size crossPlatformSize )
308
- {
309
- CGRect scrollViewBounds = platformScrollView . Bounds ;
310
- var contentSize = AccountForOrientation ( crossPlatformSize , scrollViewBounds . Width , scrollViewBounds . Height , orientation ) ;
311
- platformScrollView . ContentSize = contentSize ;
312
- return contentSize ;
313
- }
314
-
315
- internal static Size AccountForOrientation ( Size size , double widthConstraint , double heightConstraint , ScrollOrientation orientation )
316
+ static void SetContentSizeForOrientation ( UIScrollView uiScrollView , double viewportWidth , double viewportHeight , ScrollOrientation orientation , Size contentSize )
316
317
{
317
318
if ( orientation is ScrollOrientation . Vertical or ScrollOrientation . Neither )
318
319
{
319
- size . Width = widthConstraint ;
320
+ contentSize . Width = Math . Min ( contentSize . Width , viewportWidth ) ;
320
321
}
321
322
322
323
if ( orientation is ScrollOrientation . Horizontal or ScrollOrientation . Neither )
323
324
{
324
- size . Height = heightConstraint ;
325
+ contentSize . Height = Math . Min ( contentSize . Height , viewportHeight ) ;
325
326
}
326
327
327
- return size ;
328
+ uiScrollView . ContentSize = contentSize ;
328
329
}
329
330
}
330
331
}
0 commit comments