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

Snackbar and Toast messages are omitted when length is equal to display width on iOS #1281

Merged
merged 6 commits into from
Jul 6, 2023

Conversation

cat0363
Copy link
Contributor

@cat0363 cat0363 commented Jul 4, 2023

If the Snackbar message length is the same as the display width, the end of the message is omitted.
This PR fixes the problem that the end of the message is omitted when the length of the Snackbar or Toast message is close to the display width.

Description of Change

Auto width adjustment of UILabel now works when Snackbar or Toast message length is close to display width.

[CommunityToolkit.Maui.Core.Views.PlatformToast.macios.cs]

public PlatformToast(
    string message,
    UIColor backgroundColor,
    CGRect cornerRadius,
    UIColor textColor,
    UIFont font,
    double characterSpacing,
    NFloat padding)
{
    padding += DefaultPadding;

    messageLabel = new PaddedLabel(padding, padding, padding, padding)
    {
        Lines = new IntPtr(0),
        AdjustsFontSizeToFitWidth = true
    };

    Message = message;
    TextColor = textColor;
    Font = font;
    CharacterSpacing = characterSpacing;
    AlertView.VisualOptions.BackgroundColor = backgroundColor;
    AlertView.VisualOptions.CornerRadius = cornerRadius;
    AlertView.AddChild(messageLabel);
}

I was set the value of the messageLabel's AdjustsFontSizeToFitWidth property to true.

As a result, if the length of the message is close to the display width, the width of the UILabel will be automatically adjusted and the font size may be slightly reduced, but the end of the message will not be displayed omitted.

Linked Issues

PR Checklist

Additional information

Below is the execution result.

[Snackbar]
Message : 1234567890ABCDEFGHIJKLMNOPQRSTUVW
2023-07-04_03-32-45-午後

Message : 1234567890ABCDEFGHIJKLMNOPQRSTUVWXY
2023-07-04_03-33-21-午後

Message : 1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ
2023-07-04_03-33-29-午後

[Toast]

Message : 1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ
2023-07-04_03-37-32-午後

Message : 1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ123
2023-07-04_03-38-08-午後

Message : 1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ1234
2023-07-04_03-38-15-午後

If the length of the message is close to the display width, the UILabel's automatic width adjustment will work and the font size will be slightly smaller, but you can see from the execution result that the end of the message is displayed without omitting it.

The following is the verification result when the Font Size is set to 30.

[Snackbar]

Message : 1234567890ABCDEF
2023-07-04_03-47-24-午後

Message : 1234567890ABCDEFG
2023-07-04_03-47-30-午後

Message : 1234567890ABCDEFGH
2023-07-04_03-47-36-午後

[Toast]

Message : 1234567890ABCDEFGH
2023-07-04_03-50-36-午後

Message : 1234567890ABCDEFGHI
2023-07-04_03-48-03-午後

Message : 1234567890ABCDEFGHJ
2023-07-04_03-48-09-午後

@VladislavAntonyuk VladislavAntonyuk added the needs discussion Discuss it on the next Monthly standup label Jul 4, 2023
@brminnick brminnick changed the title Fix Issue #1280 Snackbar and Toast messages are omitted when length is equal to display width on iOS Jul 6, 2023
@VladislavAntonyuk VladislavAntonyuk enabled auto-merge (squash) July 6, 2023 20:24
@VladislavAntonyuk VladislavAntonyuk merged commit ba6d2c8 into CommunityToolkit:main Jul 6, 2023
7 checks passed
@brminnick brminnick removed the needs discussion Discuss it on the next Monthly standup label May 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[BUG] Snackbar and Toast messages are omitted when length is equal to display width on iOS
3 participants