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

Add Dynamic Type support #1445

Merged
merged 8 commits into from
Oct 6, 2022
Merged

Conversation

amgleitman
Copy link
Member

@amgleitman amgleitman commented Oct 3, 2022

Please select one of the following

  • I am removing an existing difference between facebook/react-native and microsoft/react-native-macos 👍
  • I am cherry-picking a change from Facebook's react-native into microsoft/react-native-macos 👍
  • I am making a fix / change for the macOS implementation of react-native
  • I am making a change required for Microsoft usage of react-native

Summary

This introduces Dynamic Type support for iOS as discussed here.

This allows Text elements to resize similarly (see note below) to native semantic text elements in iOS when we change the text size in the OS's Accessibility settings. Thanks to a new prop called fontScaleRamp dynamicTypeRamp, we can specify what kind of scaling a particular text element should use.

This prop is only used on iOS. Android appears to use a common linear scale factor for its "large text" accessibility feature, and macOS doesn't support Dynamic Type.

This is a React Native equivalent of this fluentui-apple PR. We're requiring developers to specify which font ramp to use instead of trying to intelligently map them because React Native by default has no innate sense of semantic text styles. This also gives developers the freedom to develop and conform to their own typography standards if they wish.

It's worth noting that while this code yields the same font sizes as FUA does, they're not quite the same as what we would get from -[UIFont preferredFontForTextStyle:] in UIKit or View.font(_:) in SwiftUI. This is because UIFontMetrics appears to develop its scaling ratios based on leading between lines rather than the font size itself, although these still appear to yield "good enough" results.

Changelog

[iOS] [Added] - Dynamic Type support

Screenshots

The following are screenshots from the newly added section to the Text test page (albeit with the outdated fontScaleRamp name).

Normal size:
Screen Shot 2022-09-30 at 3 18 23 PM

AX5:
Screen Shot 2022-09-30 at 3 20 34 PM
Screen Shot 2022-09-30 at 3 20 40 PM

Libraries/Text/BaseText/RCTBaseTextViewManager.m Outdated Show resolved Hide resolved
Libraries/Text/Text/RCTFontScaleRamp.h Outdated Show resolved Hide resolved
Libraries/Text/Text/RCTFontScaleRamp.h Outdated Show resolved Hide resolved
Libraries/Text/RCTTextAttributes.h Outdated Show resolved Hide resolved
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.

2 participants