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

*Proposal:* consider remove paragraph styles from single-line label and buttons #22

Open
mpospese opened this issue Sep 16, 2022 · 0 comments
Labels
enhancement New feature or request

Comments

@mpospese
Copy link
Contributor

TypographyTextField does not utilize paragraph styles to achieve its line height. This is because applying a paragraph style to UITextField can result in weird bugs (such as text wrapping to multiple lines) and also because text fields are by intention single line text views and so do not need paragraph styles. Because they are always single line, we can utilize intrinsicContentSize to achieve the correct lineHeight. (Multi-line text requires paragraph styles to achieve lineHeight.)

Single line labels and buttons (label.numberOfLines = 1) could be handled similarly. They might not need paragraph styles applied (or indeed any attributes at all, depending upon the typography) and line height could be achieved using intrinsicContentSize.

Pros

Using intrinsicContentSize to set height for single line text is more reliable and elegant, and probably less prone to odd rendering bugs. Completely avoiding attributed strings for simple typographies (no kerning, no text decorations) would be a win.

Cons

This would add some complexity because both labels and buttons can dynamically adjust numberOfLines and so a single component would need to be able to operate in both modes: using intrinsicContentSize to set height only when numberOfLines == 1 and relying on paragraph styles only when numberOfLines != 1.

The issue is even more complicated for buttons because the change happens on the titleLabel: UILabel? (which we do not subclass, replace, or override), and it would be more challenging to track changes made directly to button.titleLabel?.numberOfLines.

@mpospese mpospese added the enhancement New feature or request label Sep 16, 2022
@mpospese mpospese changed the title **Proposal:** consider remove paragraph styles from single-line label and buttons *Proposal:* consider remove paragraph styles from single-line label and buttons Sep 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Development

No branches or pull requests

1 participant