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

Handlers should not implement IImageSourcePartSetter directly #16901

Merged
merged 6 commits into from
Aug 23, 2023
Merged

Conversation

mattleibow
Copy link
Member

Description of Change

Handlers should not implement the IImageSourcePartSetter interface directly because this prevents any customization as well as does not support handlers with multiple image sources.

As of today, there is no handler yet with multiple image sources and technically we can implement the interface directly on the handler, but it is not best practice. A hander should be re-usable and connecting a specific implementation to a handler is not recommended.

This PR does a few things:

  • Removes the IImageSourcePartSetter interface from the handlers (button, image, image button and swipe items)
  • Adds the source loader ImageSourcePartLoader SourceLoader { get; } to the ISwipeItemMenuItemHandler handler interface
  • Documents the IImageSourcePartSetter type

@mattleibow mattleibow requested a review from a team as a code owner August 21, 2023 20:15
@mattleibow mattleibow changed the title Handlers mustn't implement IImageSourcePartSetter Handlers should not implement IImageSourcePartSetter directly Aug 21, 2023
Comment on lines -15 to +16
public partial class ButtonHandler : IButtonHandler, IImageSourcePartSetter
public partial class ButtonHandler : IButtonHandler
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 interface from the handler here.

Comment on lines +20 to +21
public virtual ImageSourcePartLoader ImageSourceLoader =>
_imageSourcePartLoader ??= new ImageSourcePartLoader(new ButtonImageSourcePartSetter(this));
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Made this virtual so derived types can actually do something different.

static Microsoft.Maui.Handlers.SwipeItemMenuItemHandler.MapSource(Microsoft.Maui.Handlers.ISwipeItemMenuItemHandler! handler, Microsoft.Maui.ISwipeItemMenuItem! view) -> void
static Microsoft.Maui.Handlers.SwipeItemMenuItemHandler.MapSource(Microsoft.Maui.Handlers.ISwipeItemMenuItemHandler! handler, Microsoft.Maui.ISwipeItemMenuItem! image) -> void
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Vote on this. The param name changed so I am letting it slide, but technically breaking if the dev used named params, but that is a bit hard to do in this case.

The alternative is to duplicate the code in windows with a new param name...

@PureWeen PureWeen removed the request for review from StephaneDelcroix August 21, 2023 20:43
@samhouts samhouts added this to the .NET 8 GA milestone Aug 22, 2023
hartez
hartez previously approved these changes Aug 22, 2023
PureWeen
PureWeen previously approved these changes Aug 22, 2023
@PureWeen PureWeen enabled auto-merge (squash) August 22, 2023 18:49
@PureWeen
Copy link
Member

/rebase

@dotnet dotnet deleted a comment from azure-pipelines bot Aug 23, 2023
@PureWeen PureWeen dismissed stale reviews from hartez and themself via 262a112 August 23, 2023 19:54
Copy link
Member

@rachelkang rachelkang left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approving on behalf of Shane ✅

@PureWeen PureWeen merged commit 69a166b into main Aug 23, 2023
34 checks passed
@PureWeen PureWeen deleted the dev/setter branch August 23, 2023 21:58
@github-actions github-actions bot locked and limited conversation to collaborators Dec 5, 2023
@samhouts samhouts added the fixed-in-8.0.0-rc.1.9171 Look for this fix in 8.0.0-rc.1.9171 label Aug 2, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
fixed-in-8.0.0-rc.1.9171 Look for this fix in 8.0.0-rc.1.9171
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants