Skip to content

Add support for React Native's maxFontSizeMultiplier Text prop #1200

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions docs/docs/components/link.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ allowFontScaling: boolean = true; // Android and iOS only
// property.
autoFocus: boolean = false;

// Specifies largest possible scale a font can reach when allowFontScaling is enabled. Possible values:
// - null / undefined (default): inherit from the parent node or the global default (0)
// - 0: no max, ignore parent / global default
// - >= 1: sets the maxFontSizeMultiplier of this node to this value
maxFontSizeMultiplier: number = undefined; // iOS and Android only.

// For non-zero values, truncates with ellipsis if necessary
numberOfLines: number = 0;

Expand Down
6 changes: 6 additions & 0 deletions docs/docs/components/text.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,12 @@ accessibilityId: string = undefined;
// callback.
autoFocus: boolean = false;

// Specifies largest possible scale a font can reach when allowFontScaling is enabled. Possible values:
// - null / undefined (default): inherit from the parent node or the global default (0)
// - 0: no max, ignore parent / global default
// - >= 1: sets the maxFontSizeMultiplier of this node to this value
maxFontSizeMultiplier: number = undefined; // iOS and Android only.

// For non-zero values, truncates with ellipsis if necessary. Web platform
// doesn't support values greater than 1. Web platform may also not truncate
// properly if text contains line breaks, so it may be necessary to replace
Expand Down
6 changes: 6 additions & 0 deletions docs/docs/components/textinput.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,12 @@ keyboardAppearance: 'default' | 'light' | 'dark';
// On-screen keyboard type to display
keyboardType: 'default' | 'numeric' | 'email-address' | 'number-pad';

// Specifies largest possible scale a font can reach when allowFontScaling is enabled. Possible values:
// - null / undefined (default): inherit from the parent node or the global default (0)
// - 0: no max, ignore parent / global default
// - >= 1: sets the maxFontSizeMultiplier of this node to this value
maxFontSizeMultiplier: number = undefined; // iOS and Android only.

// Maximum character count
maxLength: number = undefined;

Expand Down
1 change: 1 addition & 0 deletions src/android/Text.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ export class Text extends CommonText {
importantForAccessibility={ importantForAccessibility }
numberOfLines={ this.props.numberOfLines === 0 ? undefined : this.props.numberOfLines }
allowFontScaling={ this.props.allowFontScaling }
maxFontSizeMultiplier={ this.props.maxFontSizeMultiplier }
ellipsizeMode={ this.props.ellipsizeMode }
onPress={ this.props.onPress }
textBreakStrategy={ this.props.textBreakStrategy }
Expand Down
15 changes: 15 additions & 0 deletions src/common/Types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -572,6 +572,13 @@ export interface TextPropsShared<C = React.Component> extends CommonProps<C> {
// to true. iOS and Android only.
allowFontScaling?: boolean;

// Specifies largest possible scale a font can reach when allowFontScaling is enabled. Possible values:
// - null / undefined (default): inherit from the parent node or the global default (0)
// - 0: no max, ignore parent / global default
// - >= 1: sets the maxFontSizeMultiplier of this node to this value
// iOS and Android only.
maxFontSizeMultiplier?: number | null;

// iOS and Android only
ellipsizeMode?: 'head' | 'middle' | 'tail';

Expand Down Expand Up @@ -882,6 +889,7 @@ export interface LinkProps extends CommonStyledProps<LinkStyleRuleSet, RX.Link>
selectable?: boolean;
numberOfLines?: number;
allowFontScaling?: boolean;
maxFontSizeMultiplier?: number | null;
tabIndex?: number;
accessibilityId?: string;
autoFocus?: boolean; // The component is a candidate for being autofocused.
Expand Down Expand Up @@ -914,6 +922,13 @@ export interface TextInputPropsShared<C = React.Component> extends CommonProps<C
// to true. iOS and Android only.
allowFontScaling?: boolean;

// Specifies largest possible scale a font can reach when allowFontScaling is enabled. Possible values:
// - null / undefined (default): inherit from the parent node or the global default (0)
// - 0: no max, ignore parent / global default
// - >= 1: sets the maxFontSizeMultiplier of this node to this value
// iOS and Android only.
maxFontSizeMultiplier?: number | null;

// iOS-only prop for controlling the keyboard appearance
keyboardAppearance?: 'default' | 'light' | 'dark';

Expand Down
1 change: 1 addition & 0 deletions src/native-common/Link.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ export class LinkBase<S> extends React.Component<RX.Types.LinkProps, S> {
onPress: this._onPress,
onLongPress: this._onLongPress,
allowFontScaling: this.props.allowFontScaling,
maxFontSizeMultiplier: this.props.maxFontSizeMultiplier,
children: this.props.children,
tooltip: this.props.title,
testID: this.props.testId,
Expand Down
1 change: 1 addition & 0 deletions src/native-common/Text.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ export class Text extends React.Component<Types.TextProps, Types.Stateless> impl
importantForAccessibility={ importantForAccessibility }
numberOfLines={ this.props.numberOfLines }
allowFontScaling={ this.props.allowFontScaling }
maxFontSizeMultiplier={ this.props.maxFontSizeMultiplier }
onPress={ onPress }
selectable={ this.props.selectable }
textBreakStrategy={ 'simple' }
Expand Down
1 change: 1 addition & 0 deletions src/native-common/TextInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ export class TextInput extends React.Component<Types.TextInputProps, TextInputSt
textBreakStrategy: 'simple',
accessibilityLabel: this.props.accessibilityLabel,
allowFontScaling: this.props.allowFontScaling,
maxFontSizeMultiplier: this.props.maxFontSizeMultiplier,
underlineColorAndroid: 'transparent',
clearButtonMode: this.props.clearButtonMode,
testID: this.props.testId,
Expand Down