Skip to content

Commit

Permalink
Exposing the maxContentSizeMultiplier prop for RN.Text and RN.TextInp…
Browse files Browse the repository at this point in the history
…ut. (#78)

* Exposed the maximumFontScale prop and updating docs
  • Loading branch information
rumit91 authored and berickson1 committed May 11, 2017
1 parent 1333bd5 commit 7991b17
Show file tree
Hide file tree
Showing 12 changed files with 93 additions and 4 deletions.
11 changes: 11 additions & 0 deletions docs/docs/apis/userinterface.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,17 @@ measureWindow(): Types.Dimensions;
// can be adjusted by users on some platforms; defaults to 1.0
getContentSizeMultiplier(): SyncTasks.Promise<number>;

// Indicates the default maximum "size multiplier" for text increase.
// Defaults to 0 which indicates there is no max.
// Note: Older versions of React Native don’t support this interface.
getMaxContentSizeMultiplier(): SyncTasks.Promise<number>;

// Sets the default maximum "size multiplier" for text increase.
// Values must be 0 or >=1. The default is 0 which indicates that
// there is no max.
// Note: Older versions of React Native don’t support this interface.
setMaxContentSizeMultiplier(maxContentSizeMultiplier: number): void;

// Dismisses the on-screen keyboard (applies to mobile only)
dismissKeyboard(): void;
```
Expand Down
11 changes: 11 additions & 0 deletions docs/docs/components/link.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,17 @@ This component displays a hyperlink. On the web, it translates to an &lt;a&gt; t

## Props
``` javascript
// Should fonts be scaled according to system setting?
allowFontScaling: boolean = true; // Android and iOS only

// Should the scale multiplier be capped when allowFontScaling is set to true?
// Possible values include the following:
// null/undefined (default) - inheret from parent/global default
// 0 - no max
// >= 1 - sets the maxContentSizeMultiplier of this node to this value
// Note: Older versions of React Native don’t support this interface.
maxContentSizeMultiplier: number = null; // Android and iOS only

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

Expand Down
16 changes: 12 additions & 4 deletions docs/docs/components/text.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Another difference between Text and other components is that Text children are n
``` javascript
// Alternate text to display if the image cannot be loaded
// or by screen readers
accessibilityHidden: boolean = false;
accessibilityLabel: string = undefined;

// Hide the component from screen readers?
accessibilityHidden: boolean = false;
Expand All @@ -29,12 +29,17 @@ accessibilityTraits: AccessibilityTrait | AccessibilityTrait[] = undefined;
// Region for accessibility mechanisms
accessibilityLiveRegion?: AccessibilityLiveRegion = undefined; // Android and web only

// Keyboard tab order
tabIndex: number = undefined;

// Should fonts be scaled according to system setting?
allowFontScaling: boolean = true; // Android and iOS only

// Should the scale multiplier be capped when allowFontScaling is set to true?
// Possible values include the following:
// null/undefined (default) - inheret from parent/global default
// 0 - no max
// >= 1 - sets the maxContentSizeMultiplier of this node to this value
// Note: Older versions of React Native don’t support this interface.
maxContentSizeMultiplier: number = null; // Android and iOS only

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

Expand All @@ -43,6 +48,9 @@ selectable: boolean = false;

// See below for supported styles
style: TextStyleRuleSet | TextStyleRuleSet[] = [];

// Keyboard tab order
tabIndex: number = undefined;
```

## Styles
Expand Down
8 changes: 8 additions & 0 deletions docs/docs/components/textinput.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,14 @@ keyboardAppearance: 'default' | 'light' | 'dark';
// On-screen keyboard type to display
keyboardType: 'default' | 'numeric' | 'email-address' | 'number-pad';

// Should the scale multiplier be capped when allowFontScaling is set to true?
// Possible values include the following:
// null/undefined (default) - inheret from parent/global default
// 0 - no max
// >= 1 - sets the maxContentSizeMultiplier of this node to this value
// Note: Older versions of React Native don’t support this interface.
maxContentSizeMultiplier: number = null; // Android and iOS 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 ? null : this.props.numberOfLines }
allowFontScaling={ this.props.allowFontScaling }
maxContentSizeMultiplier={ this.props.maxContentSizeMultiplier }
ellipsizeMode={ this.props.ellipsizeMode }
onPress={ this.props.onPress }
textBreakStrategy={ this.props.textBreakStrategy }
Expand Down
8 changes: 8 additions & 0 deletions src/common/Types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -487,6 +487,9 @@ export interface TextPropsShared extends CommonProps {
// to true. iOS and Android only.
allowFontScaling?: boolean;

// Specifies the maximum scale factor for text size. iOS and Android only.
maxContentSizeMultiplier?: number;

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

Expand Down Expand Up @@ -741,6 +744,8 @@ export interface LinkProps extends CommonStyledProps<LinkStyleRuleSet> {
children?: ReactNode;
selectable?: boolean;
numberOfLines?: number;
allowFontScaling?: boolean;
maxContentSizeMultiplier?: number;

onPress?: (e: RX.Types.SyntheticEvent, url: string) => void;
onLongPress?: (e: RX.Types.SyntheticEvent, url: string) => void;
Expand Down Expand Up @@ -769,6 +774,9 @@ export interface TextInputPropsShared extends CommonProps, CommonAccessibilityPr
// to true. iOS and Android only.
allowFontScaling?: boolean;

// Specifies the maximum scale factor for text size. iOS and Android only.
maxContentSizeMultiplier?: number;

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

Expand Down
2 changes: 2 additions & 0 deletions src/native-common/Link.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ export class Link extends RX.Link<{}> {
numberOfLines={ this.props.numberOfLines === 0 ? null : this.props.numberOfLines }
onPress={ this._onPress }
onLongPress={ this._onLongPress }
allowFontScaling={ this.props.allowFontScaling }
maxContentSizeMultiplier={ this.props.maxContentSizeMultiplier }
>
{ this.props.children }
</RN.Text>
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 @@ -36,6 +36,7 @@ export class Text extends RX.Text<{}> {
importantForAccessibility={ importantForAccessibility }
numberOfLines={ this.props.numberOfLines }
allowFontScaling={ this.props.allowFontScaling }
maxContentSizeMultiplier={ this.props.maxContentSizeMultiplier }
onPress={ this.props.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 @@ -86,6 +86,7 @@ export class TextInput extends RX.TextInput<TextInputState> {
textBreakStrategy={ 'simple' }
accessibilityLabel={ this.props.accessibilityLabel }
allowFontScaling={ this.props.allowFontScaling }
maxContentSizeMultiplier={ this.props.maxContentSizeMultiplier }
underlineColorAndroid='transparent'
/>
);
Expand Down
22 changes: 22 additions & 0 deletions src/native-common/UserInterface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,28 @@ export class UserInterface extends RX.UserInterface {
return deferred.promise();
}

getMaxContentSizeMultiplier(): SyncTasks.Promise<number> {
let deferred = SyncTasks.Defer<number>();

// TODO: #727532 Remove conditional after implementing UIManager.getContentSizeMultiplier for UWP
if (RN.Platform.OS === 'windows') {
deferred.resolve(1);
} else {
RN.NativeModules.UIManager.getMaxContentSizeMultiplier((value: number) => {
deferred.resolve(value);
});
}

return deferred.promise();
}

setMaxContentSizeMultiplier(maxContentSizeMultiplier: number): void {
// TODO: #727532 Remove conditional after implementing UIManager.getContentSizeMultiplier for UWP
if (RN.Platform.OS !== 'windows') {
RN.NativeModules.UIManager.setMaxContentSizeMultiplier(maxContentSizeMultiplier);
}
}

useCustomScrollbars(enable = true) {
// Nothing to do
}
Expand Down
4 changes: 4 additions & 0 deletions src/typings/react-native.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ declare module 'react-native' {
interface TextProps extends ComponentPropsStyleBase {
importantForAccessibility?: string; // 'auto' | 'yes' | 'no' | 'no-hide-descendants';
allowFontScaling?: boolean;
maxContentSizeMultiplier?: number;
children? : React.ReactNode;
numberOfLines? : number;
ellipsizeMode? : 'head' | 'middle' | 'tail' // There's also 'clip' but it is iOS only
Expand Down Expand Up @@ -343,6 +344,7 @@ declare module 'react-native' {
testID?: string;
textAlign?: string; // enum('auto' | 'left' | 'right' | 'center' | 'justify')
allowFontScaling?: boolean;
maxContentSizeMultiplier?: number;
selection?: { start: number, end: number };

//iOS and android
Expand Down Expand Up @@ -816,6 +818,8 @@ declare module 'react-native' {
dispatchViewManagerCommand: Function;

getContentSizeMultiplier: Function;
getMaxContentSizeMultiplier: Function;
setMaxContentSizeMultiplier: Function;

// ios
takeSnapshot: (view: any, options?: SnapshotOptions) => Promise<string>;
Expand Down
12 changes: 12 additions & 0 deletions src/web/UserInterface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,18 @@ export class UserInterface extends RX.UserInterface {
return SyncTasks.Resolved(1);
}

getMaxContentSizeMultiplier(): SyncTasks.Promise<number> {
// Browsers don't support font-specific scaling. They scale all of their
// UI elements the same.
return SyncTasks.Resolved(0);
}

setMaxContentSizeMultiplier(maxContentSizeMultiplier: number) {
// Browsers don't support font-specific scaling. They scale all of their
// UI elements the same.
// No-op.
}

isHighPixelDensityScreen(): boolean {
return this.getPixelRatio() > 1;
}
Expand Down

0 comments on commit 7991b17

Please sign in to comment.