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

[iOS] Button CharacterSpacing Fix #20537

Open
wants to merge 11 commits into
base: main
Choose a base branch
from

Conversation

kubaflo
Copy link
Contributor

@kubaflo kubaflo commented Feb 13, 2024

Description of Change

The AttributedTitle property of the iOS's native button hasn't been always updated when needed.

Issues Fixed

Fixes #18832
Fixes #21722

Before After
Before.mov
Fixed.mov

@kubaflo kubaflo requested a review from a team as a code owner February 13, 2024 01:15
@ghost ghost added the community ✨ Community Contribution label Feb 13, 2024
@ghost
Copy link

ghost commented Feb 13, 2024

Hey there @kubaflo! Thank you so much for your PR! Someone from the team will get assigned to your PR shortly and we'll get it reviewed.

@ghost ghost added the legacy-area-controls Label, Button, CheckBox, Slider, Stepper, Switch, Picker, Entry, Editor label Feb 13, 2024
@@ -33,6 +33,10 @@ private static void MapPadding(IButtonHandler handler, Button button)
public static void MapText(IButtonHandler handler, Button button)
{
handler.PlatformView?.UpdateText(button);

// Update all of the attributed text formatting properties
Copy link
Contributor

Choose a reason for hiding this comment

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

Firsr of all, thanks for the contributions.
In Controls and in Core, we are mapping the Text to a extension method. In Core, invoke the MapFormatting method that update the AttributedTitle taking into account the character spacing and the text color. Instead create a new method with a similar logic, everything should be in the same existing method in Core ButtonExtensions, here:

platformButton?.SetAttributedTitle(attributedText, UIControlState.Normal);

This also will avoid the publicAPI small breaking changes.

I think, just need to set the font family and size there. The rest of changes, the test etc are fine.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you for this advice! I've refactored the code and hope it is what you want

@@ -151,6 +157,27 @@ static void SetControlPropertiesFromProxy(UIButton platformView)
}
}

internal static void UpdateAttributedTitle(IButtonHandler handler, ITextStyle textStyle)
Copy link
Contributor

Choose a reason for hiding this comment

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

Could we move this as an extension method in ButtonExtensions?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure, I just did it. I have one question though. This method needs fontManager which currently is getting resolved by IButtonHandler. Should I keep this line of code: var fontManager = handler.GetRequiredService<IFontManager>(); inside this new extension method or pass IFontManager as a parameter to the UpdateAttributedTitle method and call handler.GetRequiredService<IFontManager>(); before calling UpdateAttributedTitle?

Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changed in the last commit

@jsuarezruiz
Copy link
Contributor

/azp run MAUI-UITests-public

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

Copy link
Member

@PureWeen PureWeen left a comment

Choose a reason for hiding this comment

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

Let's wait until this PR is merged
#20953

@jsuarezruiz
Copy link
Contributor

Added pending test snapshot.

@PureWeen
Copy link
Member

/rebase

@github-actions github-actions bot force-pushed the ios-button-character-spacing branch from 71c0f08 to 4aad58f Compare April 29, 2024 21:07
@@ -83,5 +84,24 @@ public static void UpdatePadding(this UIButton platformButton, Thickness padding
#pragma warning restore CA1422 // Validate platform compatibility
#pragma warning restore CA1416
}

public static void UpdateAttributedTitle(this UIButton platformButton, IFontManager fontManager, ITextStyle textStyle)
Copy link
Member

Choose a reason for hiding this comment

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

Can you change this to internal?

@kubaflo kubaflo force-pushed the ios-button-character-spacing branch from 4aad58f to 1952c68 Compare May 6, 2024 14:22
Copy link
Contributor

@tj-devel709 tj-devel709 left a comment

Choose a reason for hiding this comment

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

image
(with gisted code here: https://gist.github.com/tj-devel709/34d29859c873925ac84e7f4556bff305)

This is looking great to me! I was wondering if we can add a font to the UITest as well? Just to catch if we mess up something in the future :)

@tj-devel709
Copy link
Contributor

I added a fontfamily and textcolor to your test but let me know if that is not wanted!

@tj-devel709
Copy link
Contributor

/azp run

Copy link

Azure Pipelines successfully started running 3 pipeline(s).

@kubaflo
Copy link
Contributor Author

kubaflo commented May 9, 2024

I added a fontfamily and textcolor to your test but let me know if that is not wanted!

That's awesome! Thank you

@tj-devel709
Copy link
Contributor

/azp run

Copy link

Azure Pipelines successfully started running 3 pipeline(s).

@Eilon Eilon removed the legacy-area-controls Label, Button, CheckBox, Slider, Stepper, Switch, Picker, Entry, Editor label May 10, 2024
@jsuarezruiz
Copy link
Contributor

/azp run

Copy link

Azure Pipelines successfully started running 3 pipeline(s).

@jsuarezruiz
Copy link
Contributor

Based on the changes, there are several golden tests (comparing an snapshot) with small differences. Waiting the build to complete and review all of them.

@tj-devel709 tj-devel709 force-pushed the ios-button-character-spacing branch from 5cb04ca to c5a6de1 Compare May 22, 2024 19:38
@tj-devel709
Copy link
Contributor

Rebased to main with the new UITest structure!

@tj-devel709
Copy link
Contributor

/azp run

Copy link

Azure Pipelines successfully started running 3 pipeline(s).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-controls-button Button, ImageButton community ✨ Community Contribution platform/iOS 🍎
Projects
None yet
5 participants