Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Comments/refactoring for clarification (#14176) #14217

Merged
merged 2 commits into from
Mar 27, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 20 additions & 6 deletions src/Core/src/Handlers/ScrollView/ScrollViewHandler.iOS.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,20 @@ public static void MapVerticalScrollBarVisibility(IScrollViewHandler handler, IS

public static void MapOrientation(IScrollViewHandler handler, IScrollView scrollView)
{
if (handler?.PlatformView is UIScrollView uiScrollView)
if (handler?.PlatformView is not UIScrollView uiScrollView)
{
var fullContentSize = scrollView.PresentedContent?.DesiredSize ?? Size.Zero;
var viewportWidth = uiScrollView.Bounds.Width;
var viewportHeight = uiScrollView.Bounds.Height;
SetContentSizeForOrientation(uiScrollView, viewportWidth, viewportHeight, scrollView.Orientation, fullContentSize);
return;
}

// If the UIScrollView hasn't been laid out yet, this will basically do nothing.
// If it has been, we can just update the ContentSize here and get the new orientation working
// without having to re-layout the ScrollView

var fullContentSize = scrollView.PresentedContent?.DesiredSize ?? Size.Zero;
var viewportBounds = uiScrollView.Bounds;
var viewportWidth = viewportBounds.Width;
var viewportHeight = viewportBounds.Height;
SetContentSizeForOrientation(uiScrollView, viewportWidth, viewportHeight, scrollView.Orientation, fullContentSize);
}

public static void MapRequestScrollTo(IScrollViewHandler handler, IScrollView scrollView, object? args)
Expand Down Expand Up @@ -204,7 +211,12 @@ static Func<Rect, Size> ArrangeScrollViewContent(Func<Rect, Size> internalArrang

var contentSize = internalArrange(rect);

SetContentSizeForOrientation(platformScrollView, platformScrollView.Bounds.Width, platformScrollView.Bounds.Height, scrollView.Orientation, contentSize);
// The UIScrollView's bounds are available, so we can use them to make sure the ContentSize makes sense
// for the ScrollView orientation
var viewportBounds = platformScrollView.Bounds;
var viewportHeight = viewportBounds.Height;
var viewportWidth = viewportBounds.Width;
SetContentSizeForOrientation(platformScrollView, viewportWidth, viewportHeight, scrollView.Orientation, contentSize);

return contentSize;
};
Expand Down Expand Up @@ -273,6 +285,8 @@ public override Size GetDesiredSize(double widthConstraint, double heightConstra
var viewportWidth = Math.Min(crossPlatformContentSize.Width, widthConstraint);
var viewportHeight = Math.Min(crossPlatformContentSize.Height, heightConstraint);

// Since the UIScrollView might not be laid out yet, we can't rely on its Bounds for the viewport height/width
// So we'll use the constraints instead.
SetContentSizeForOrientation(platformView, widthConstraint, heightConstraint, virtualView.Orientation, crossPlatformContentSize);

var finalWidth = ViewHandlerExtensions.ResolveConstraints(viewportWidth, virtualView.Width, virtualView.MinimumWidth, virtualView.MaximumWidth);
Expand Down