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 2 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.

@kubaflo kubaflo force-pushed the ios-button-character-spacing branch from 95005d7 to 789a8fd Compare February 13, 2024 01:21
@ghost ghost added the legacy-area-controls Label, Button, CheckBox, Slider, Stepper, Switch, Picker, Entry, Editor label Feb 13, 2024
@kubaflo kubaflo requested a review from jsuarezruiz February 13, 2024 18:44
@@ -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

@kubaflo kubaflo force-pushed the ios-button-character-spacing branch from d627114 to bcf199e Compare February 14, 2024 19:13
@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
Member

@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
Member

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

@tj-devel709
Copy link
Member

/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
Member

/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
Member

Rebased to main with the new UITest structure!

@tj-devel709
Copy link
Member

/azp run

Copy link

Azure Pipelines successfully started running 3 pipeline(s).

{
// Any text update requires that we update any attributed string formatting
var uiFontAttribute = fontManager.GetFont(textStyle.Font, UIFont.ButtonFontSize);
var attributedString = new NSMutableAttributedString(new NSAttributedString(platformButton.CurrentTitle!));
Copy link
Member

Choose a reason for hiding this comment

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

Looks like there may some situations where this platformButton.CurrentTitle! is null and crashes. Perhaps a null check and bailing could be useful here if the title is not populated yet?

https://gist.github.com/tj-devel709/10346a24bbb84b04a1f8dc4e15777410

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You're right! I've added a null check

@tj-devel709
Copy link
Member

/azp run

Copy link

Azure Pipelines successfully started running 3 pipeline(s).

@tj-devel709 tj-devel709 force-pushed the ios-button-character-spacing branch from 9366d37 to 23fe76a Compare May 30, 2024 14:10
@tj-devel709
Copy link
Member

/azp run

Copy link

Azure Pipelines successfully started running 3 pipeline(s).

@dotnet dotnet deleted a comment from azure-pipelines bot Jun 11, 2024
@dotnet dotnet deleted a comment from azure-pipelines bot Jun 13, 2024
@jsuarezruiz
Copy link
Contributor

/azp run

Copy link

Azure Pipelines successfully started running 3 pipeline(s).

@PureWeen
Copy link
Member

PureWeen commented Oct 1, 2024

/rebase

1 similar comment
@jsuarezruiz
Copy link
Contributor

/rebase

@kubaflo kubaflo force-pushed the ios-button-character-spacing branch from 51c87b8 to b3e03d9 Compare November 15, 2024 09:29
Co-Authored-By: TJ Lambert <50846373+tj-devel709@users.noreply.github.com>
@kubaflo kubaflo force-pushed the ios-button-character-spacing branch from b3e03d9 to e040d14 Compare November 15, 2024 09:36
@jsuarezruiz
Copy link
Contributor

/azp run

Copy link

Azure Pipelines successfully started running 3 pipeline(s).

@jsuarezruiz
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
Projects
None yet
5 participants