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

Exposing the maxContentSizeMultiplier prop for RN.Text and RN.TextInput. #78

Merged
merged 23 commits into from
May 11, 2017
Merged

Exposing the maxContentSizeMultiplier prop for RN.Text and RN.TextInput. #78

merged 23 commits into from
May 11, 2017

Conversation

rumit91
Copy link
Contributor

@rumit91 rumit91 commented May 1, 2017

Whenever a user changes the system font size to its maximum allowable setting most React Native apps that allow font scaling become unusable. Ideally React Native apps would mimic the behavior of the iMessage (iOS) app where the font size used for non-body text (header, navigational elements, etc) is capped while the body text (text in the message bubbles) is allowed to grow. In this PR I expose the maxContentSizeMultiplier prop on <Text>, <TextInput>, and <Link>. Developers can overwrite the default maxContentSizeMultiplier by calling the static method UserInterface. setMaxContentSizeMultiplier() or they can just choose to set the maxContentSizeMultiplier on the desired elements.

@msftclas
Copy link

msftclas commented May 1, 2017

@rumit91,
Thanks for your contribution as a Microsoft full-time employee or intern. You do not need to sign a CLA.
Thanks,
Microsoft Pull Request Bot

package.json Outdated
@@ -20,7 +20,7 @@
"react-addons-perf": "^15.4.1",
"react-addons-test-utils": "^15.4.1",
"react-dom": "^15.4.1",
"react-native": "^0.42.0",
"react-native": "git+https://skype.visualstudio.com/DefaultCollection/TPS/_git/react-native#timale/fontScalingLimit",
Copy link
Contributor

Choose a reason for hiding this comment

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

You can't change the public reactxp to point to a private, internal react-native version. Just leave the version as-is. Internally, the Skype repo can refer to the private react-native branch.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yep will remove for sure. Was just using this for testing.

@@ -40,6 +40,7 @@ export class Text extends CommonText {
importantForAccessibility={ importantForAccessibility }
numberOfLines={ this.props.numberOfLines === 0 ? null : this.props.numberOfLines }
allowFontScaling={ this.props.allowFontScaling }
maxFontSizeMultiplier={ this.props.maxFontSizeMultiplier }
Copy link
Contributor

Choose a reason for hiding this comment

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

Why wouldn't we also expose a minFontSizeMultiplier?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I didn't add a min, because the user changing the system font to the minimum didn't seem to cause any issues in RN apps, but do you think it would still be valuable for me to add?

@@ -52,6 +53,10 @@ export class Text extends CommonText {
focus() {
AccessibilityUtil.setAccessibilityFocus(this);
}

static setDefaultMaxFontSizeMultiplier(maxFontSizeMultiplier: number): void {
Copy link
Contributor

Choose a reason for hiding this comment

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

This shouldn't be exposed as a static method on Text. It should be a method on the UserInterface namespace.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Moved to UserInterface.

@@ -40,6 +40,7 @@ export class Text extends CommonText {
importantForAccessibility={ importantForAccessibility }
numberOfLines={ this.props.numberOfLines === 0 ? null : this.props.numberOfLines }
allowFontScaling={ this.props.allowFontScaling }
maxFontSizeMultiplier={ this.props.maxFontSizeMultiplier }
Copy link
Contributor

Choose a reason for hiding this comment

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

For consistency with UserInterface (and react native) terminology, this should be called maxContentSizeMultiplier, not minFontSizeMultiplier.

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 the var name.

@@ -40,6 +40,7 @@ export class Text extends CommonText {
importantForAccessibility={ importantForAccessibility }
numberOfLines={ this.props.numberOfLines === 0 ? null : this.props.numberOfLines }
allowFontScaling={ this.props.allowFontScaling }
maxFontSizeMultiplier={ this.props.maxFontSizeMultiplier }
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we really need to expose an override of the default max on a per-Text basis? This seems like it might be overkill.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think we need this to be able to override the default in specific instances. For example, we may want the maxContentSizeMultiplier to be much higher for text inside message bubbles vs the text in the navigational elements.

@@ -220,6 +221,10 @@ export class TextInput extends RX.TextInput<TextInputState> {
setValue(value: string): void {
this._onChangeText(value);
}

static setDefaultMaxFontSizeMultiplier(maxFontSizeMultiplier: number): void {
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think we need a different default for Text and TextInput. As mentioned above, this should be collapsed to a single API - UserInterface.setDefaultMaxContentSizeMultiplier.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agreed. Moved to UserInterface.

@@ -40,6 +40,7 @@ export class Text extends CommonText {
importantForAccessibility={ importantForAccessibility }
numberOfLines={ this.props.numberOfLines === 0 ? null : this.props.numberOfLines }
allowFontScaling={ this.props.allowFontScaling }
maxFontSizeMultiplier={ this.props.maxFontSizeMultiplier }
Copy link
Contributor

Choose a reason for hiding this comment

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

The documentation for Text, TextInput and UserInterface need to be updated as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for reminding me. I added the docs.

@rumit91 rumit91 changed the title Exposing the maxFontSizeMultiplier prop for RN.Text and RN.TextInput. Exposing the maxContentSizeMultiplier prop for RN.Text and RN.TextInput. May 6, 2017

// Triggered when the max content size multiplier changes while
// the app is running.
maxContentSizeMultiplierChangedEvent: SubscribableEvent<
Copy link
Contributor

Choose a reason for hiding this comment

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

We don't need this event. The max content size multiplier is under the control of the app, so it can track this change itself. The reason I added an event for contentSizeMultiplierChanged is that it's under control of the OS (and ultimately the user), so the app needs to be informed when it changes.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed from the code and the docs.

// Should the scale multiplier be capped when allowFontScaling is set to true?
// The default of 0 indicates that the compoent should obey the global setting
// in UserInterface which by default is uncapped.
// Note: Most versions of React Native don’t support this interface.
Copy link
Contributor

Choose a reason for hiding this comment

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

See above.

// Should the scale multiplier be capped when allowFontScaling is set to true?
// The default of 0 indicates that the compoent should obey the global setting
// in UserInterface which by default is uncapped.
// Note: Most versions of React Native don’t support this interface.
Copy link
Contributor

Choose a reason for hiding this comment

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

See above.

// Should the scale multiplier be capped when allowFontScaling is set to true?
// The default of 0 indicates that the compoent should obey the global setting
// in UserInterface which by default is uncapped.
// Note: Most versions of React Native don’t support this interface.
Copy link
Contributor

Choose a reason for hiding this comment

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

Rather than saying "Most versions of React Native", please change to "Older versions...".

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

@@ -48,10 +49,6 @@ export class Text extends CommonText {
</RN.Text>
);
}

Copy link
Contributor

Choose a reason for hiding this comment

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

Did you intend to delete this, or was it a merge error? Amay recently added this code.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I deleted it because it caused merge conflicts. I believe Amay removed it from master recently with this commit: cff4b51

Copy link
Contributor

@erictraut erictraut left a comment

Choose a reason for hiding this comment

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

When you're ready to merge this, let DDR or Brent know, and they can merge and republish.

@berickson1 berickson1 merged commit 7991b17 into microsoft:master May 11, 2017
berickson1 pushed a commit to berickson1/reactxp that referenced this pull request Oct 22, 2018
…ut. (microsoft#78)

* Exposed the maximumFontScale prop and updating docs
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.

4 participants