-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
Moved GetPlatformSize
logic into a new service
#4885
Conversation
else if ((visualElementRenderer == null || visualElementRenderer is HandlerToRendererShim) && view is IView iView) | ||
{ | ||
Application.Current?.FindMauiContext()?.CreateLogger<Platform>()?.LogWarning( | ||
"Someone called Platform.GetNativeSize instead of going through the Handler."); | ||
|
||
returnValue = iView.Handler.GetDesiredSize(widthConstraint, heightConstraint); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Keeping this chunk of code here for "just in case", but this code path should never be hit because this service is obsolete and could co away at any time. All callers need to check the handler before using ths service so a removal of renderers/compat is a seamless operation.
if (IndicatorTemplate == null) | ||
return Device.PlatformServices.GetPlatformSize(this, widthConstraint, heightConstraint); | ||
{ | ||
if (Handler != null) | ||
return new SizeRequest(Handler.GetDesiredSize(widthConstraint, heightConstraint)); | ||
|
||
_platformSizeService ??= DependencyService.Get<IPlatformSizeService>(); | ||
return _platformSizeService.GetPlatformSize(this, widthConstraint, heightConstraint); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the example of first checking the handler before using the compat service. Using this, the renderer checks should never even be fetched.
return Device.PlatformServices.GetPlatformSize(this, widthConstraint, heightConstraint); | ||
if (Handler != null) | ||
return new SizeRequest(Handler.GetDesiredSize(widthConstraint, heightConstraint)); | ||
|
||
_platformSizeService ??= DependencyService.Get<IPlatformSizeService>(); | ||
return _platformSizeService.GetPlatformSize(this, widthConstraint, heightConstraint); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Another case of checking the handler before renderers.
return Device.PlatformServices.GetPlatformSize(this, widthConstraint, heightConstraint); | ||
if (Handler != null) | ||
return new SizeRequest(Handler.GetDesiredSize(widthConstraint, heightConstraint)); | ||
|
||
_platformSizeService ??= DependencyService.Get<IPlatformSizeService>(); | ||
return _platformSizeService.GetPlatformSize(this, widthConstraint, heightConstraint); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Last and base occurence of the Handler first before Renderer touches.
[SetUp] | ||
public void Setup() | ||
{ | ||
Device.PlatformServices = new MockPlatformServices(); | ||
} | ||
|
||
[TearDown] | ||
public void TearDown() | ||
{ | ||
Device.PlatformServices = null; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed the rendant logic as BaseTestFixture
does all this.
Description of Change
This PR is basically removing the
IPlatformServices.GetPlatformSize
member and moving it into a new, separate service.However, this one also makes a change to further split the renderers out of the common path. Previously,
IPlatformServices.GetPlatformSize
was basically a "proxy" for calling the CompatPlatform.GetNativeSize
. When we introduced handlers, we just kept things as they were and added aif handler, then measure with handler
chunk of code.This is "fine", but basically makes a hard dependency of all code on compatibility and first assumes renderer logic and then works with handlers. This PR includes a small change to first check the handlers from Controls, and then tries to use the service and Compat.
Part of #1965
Fixes #3949
Additions made
IPlatformServices.GetPlatformSize
PR Checklist
Does this PR touch anything that might affect accessibility?
If any of the above checkboxes apply to your PR, then the PR will need to provide testing to demonstrate that accessibility still works.