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

Moved GetPlatformSize logic into a new service #4885

Merged
merged 2 commits into from
Feb 24, 2022
Merged

Conversation

mattleibow
Copy link
Member

@mattleibow mattleibow commented Feb 24, 2022

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 Compat Platform.GetNativeSize. When we introduced handlers, we just kept things as they were and added a if 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

  • Removes IPlatformServices.GetPlatformSize
  • Adds:
     public interface IPlatformSizeService
     {
      	SizeRequest GetPlatformSize(VisualElement view, double widthConstraint, double heightConstraint);
     }

PR Checklist

  • Targets the correct branch
  • Tests are passing (or failures are unrelated)
  • Targets a single property for a single control (or intertwined few properties)
  • Adds the property to the appropriate interface
  • Avoids any changes not essential to the handler property
  • Adds the mapping to the PropertyMapper in the handler
  • Adds the mapping method to the WinUI, Android, iOS, and Standard aspects of the handler
  • Implements the actual property updates (usually in extension methods in the Platform section of Core)
  • Tags ported renderer methods with [PortHandler]
  • Adds an example of the property to the sample project (MainPage)
  • Adds the property to the stub class
  • Implements basic property tests in DeviceTests

Does this PR touch anything that might affect accessibility?

  • Does this PR introduce a new control? (If yes, add an example using SemanticProperties to the SemanticsPage)
  • APIs that modify focusability?
  • APIs that modify any text property on a control?
  • Does this PR modify view nesting or view arrangement in anyway?
  • Is there the smallest possibility that your PR will change accessibility?
  • I'm not sure, please help me

If any of the above checkboxes apply to your PR, then the PR will need to provide testing to demonstrate that accessibility still works.

Comment on lines 269 to 275
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);
}
Copy link
Member Author

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.

Comment on lines 136 to +143
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);
}
Copy link
Member Author

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.

Comment on lines -288 to +294
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);
Copy link
Member Author

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.

Comment on lines -913 to +919
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);
Copy link
Member Author

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.

Comment on lines -77 to -87
[SetUp]
public void Setup()
{
Device.PlatformServices = new MockPlatformServices();
}

[TearDown]
public void TearDown()
{
Device.PlatformServices = null;
}
Copy link
Member Author

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.

@Redth Redth merged commit d56f560 into main Feb 24, 2022
@Redth Redth deleted the dev/platform-size branch February 24, 2022 17:26
@samhouts samhouts added the migration-compatibility Xamarin.Forms to .NET MAUI Migration, Upgrade Assistant, Try-Convert label Aug 28, 2023
@github-actions github-actions bot locked and limited conversation to collaborators Dec 23, 2023
@samhouts samhouts added the fixed-in-6.0.200-preview.14.2 Look for this fix in 6.0.200-preview.14.2! label Aug 2, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
fixed-in-6.0.200-preview.14.2 Look for this fix in 6.0.200-preview.14.2! migration-compatibility Xamarin.Forms to .NET MAUI Migration, Upgrade Assistant, Try-Convert
Projects
No open projects
Status: Done
Development

Successfully merging this pull request may close these issues.

GetNativeSize - Gets renderer or handler and calls getdesired size - remove
4 participants