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

Remove clipped texts throughout the app when device font size is increased #10312

Merged
merged 22 commits into from
Dec 2, 2022
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
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
2 changes: 1 addition & 1 deletion src/components/Button.js
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ class Button extends Component {
{textComponent}
</View>
{this.props.shouldShowRightIcon && (
<View>
<View style={styles.justifyContentCenter}>
<Icon
src={this.props.iconRight}
fill={this.props.iconFill}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ const defaultViewProps = {style: [styles.alignItemsStart, styles.userSelectText]
// costly invalidations and commits.
const BaseHTMLEngineProvider = (props) => {
// We need to memoize this prop to make it referentially stable.
const defaultTextProps = useMemo(() => ({selectable: props.textSelectable}), [props.textSelectable]);
const defaultTextProps = useMemo(() => ({selectable: props.textSelectable, allowFontScaling: false}), [props.textSelectable]);

// We need to pass multiple system-specific fonts for emojis but
// we can't apply multiple fonts at once so we need to pass fallback fonts.
Expand Down
1 change: 1 addition & 0 deletions src/components/Picker/BasePicker/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ class BasePicker extends React.Component {
fixAndroidTouchableBug
onOpen={this.props.onOpen}
onClose={this.props.onClose}
textInputProps={{allowFontScaling: false}}
pickerProps={{
onFocus: this.props.onOpen,
onBlur: this.executeOnCloseAndOnBlur,
Expand Down
1 change: 1 addition & 0 deletions src/components/RNTextInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ const defaultProps = {

const RNTextInput = props => (
<TextInput
allowFontScaling={false}
ref={(ref) => {
if (!_.isFunction(props.forwardedRef)) {
return;
Expand Down
2 changes: 1 addition & 1 deletion src/components/TestToolRow.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const propTypes = {

const TestToolRow = props => (
<View style={[styles.flexRow, styles.mb6, styles.justifyContentBetween, styles.alignItemsCenter]}>
<View style={styles.flex3}>
<View style={styles.flex2}>
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This fixes this bug.

Copy link
Collaborator

Choose a reason for hiding this comment

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

There are multiple issues there but I think you are referring to Preferences Page.

Copy link
Collaborator

Choose a reason for hiding this comment

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

But we updated the Button view style to fix that one, not sure how this fixed it. Can you briefly explain this thanks!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Can you briefly explain this

Ok, this is what you get when using styles.flex3 with a large font size.

Simulator Screen Shot - iPhone 13 - 2022-11-21 at 20 40 04

And this is what you get when using styles.flex2 with a large font size.

Simulator Screen Shot - iPhone 13 - 2022-11-21 at 20 40 13

As you can see, there is a difference between both, by using styles.flex2 you can see the Invalidate word completely.

<Text>
{props.title}
</Text>
Expand Down
2 changes: 1 addition & 1 deletion src/components/Text.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ const Text = React.forwardRef(({

return (
// eslint-disable-next-line react/jsx-props-no-spreading
<RNText ref={ref} style={[componentStyle]} {...props}>{children}</RNText>
<RNText allowFontScaling={false} ref={ref} style={[componentStyle]} {...props}>{children}</RNText>
);
});

Expand Down
1 change: 1 addition & 0 deletions src/components/TextInput/TextInputLabel/index.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class TextInputLabel extends PureComponent {
render() {
return (
<Animated.Text
allowFontScaling={false}
onLayout={({nativeEvent}) => {
this.setState({width: nativeEvent.layout.width});
}}
Expand Down
4 changes: 3 additions & 1 deletion src/components/TextInput/styleConst.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import variables from '../../styles/variables';

const ACTIVE_LABEL_TRANSLATE_Y = 4;
const ACTIVE_LABEL_SCALE = 0.8668;

const INACTIVE_LABEL_TRANSLATE_Y = 16;
const INACTIVE_LABEL_TRANSLATE_Y = variables.INACTIVE_LABEL_TRANSLATE_Y;
const INACTIVE_LABEL_SCALE = 1;

export {
Expand Down
4 changes: 2 additions & 2 deletions src/pages/home/report/FloatingMessageCounter/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const defaultProps = {
onClick: () => {},
};

const MARKER_INACTIVE_TRANSLATE_Y = -30;
const MARKER_INACTIVE_TRANSLATE_Y = -40;
Copy link
Contributor

Choose a reason for hiding this comment

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

Why did we change this value?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

To completely hide the FloatingMessageCounter component when we are using a larger font size.
Simulator Screen Shot - iPhone 13 - 2022-12-01 at 07 46 16

const MARKER_ACTIVE_TRANSLATE_Y = 10;

class FloatingMessageCounter extends PureComponent {
Expand Down Expand Up @@ -75,7 +75,7 @@ class FloatingMessageCounter extends PureComponent {
small
onPress={this.props.onClick}
ContentComponent={() => (
<View style={[styles.flexRow]}>
<View style={[styles.flexRow, styles.alignItemsCenter]}>
<Icon small src={Expensicons.DownArrow} fill={themeColors.textReversed} />
<Text
selectable={false}
Expand Down
53 changes: 28 additions & 25 deletions src/styles/styles.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const picker = {
paddingHorizontal: 11,
paddingBottom: 8,
paddingTop: 23,
height: 52,
height: variables.inputHeight,
borderWidth: 1,
borderStyle: 'solid',
borderColor: themeColors.border,
Expand Down Expand Up @@ -215,25 +215,25 @@ const styles = {

label: {
fontSize: variables.fontSizeLabel,
lineHeight: 18,
lineHeight: variables.lineHeightLarge,
},

textLabel: {
color: themeColors.text,
fontSize: variables.fontSizeLabel,
lineHeight: 18,
lineHeight: variables.lineHeightLarge,
},

mutedTextLabel: {
color: themeColors.textSupporting,
fontSize: variables.fontSizeLabel,
lineHeight: 18,
lineHeight: variables.lineHeightLarge,
},

textMicro: {
fontFamily: fontFamily.GTA,
fontSize: variables.fontSizeSmall,
lineHeight: 14,
lineHeight: variables.lineHeightSmall,
},

textMicroBold: {
Expand All @@ -247,7 +247,7 @@ const styles = {
color: themeColors.textSupporting,
fontFamily: fontFamily.GTA,
fontSize: variables.fontSizeSmall,
lineHeight: 14,
lineHeight: variables.lineHeightSmall,
},

textExtraSmallSupporting: {
Expand Down Expand Up @@ -389,20 +389,23 @@ const styles = {

buttonSmallText: {
fontSize: variables.fontSizeSmall,
lineHeight: variables.lineHeightSmallFont,
fontFamily: fontFamily.GTA_BOLD,
fontWeight: fontWeightBold,
textAlign: 'center',
},

buttonMediumText: {
fontSize: variables.fontSizeLabel,
lineHeight: variables.lineHeightLabelFont,
fontFamily: fontFamily.GTA_BOLD,
fontWeight: fontWeightBold,
textAlign: 'center',
},

buttonLargeText: {
fontSize: variables.fontSizeNormal,
lineHeight: variables.lineHeightNormalFont,
fontFamily: fontFamily.GTA_BOLD,
fontWeight: fontWeightBold,
textAlign: 'center',
Expand Down Expand Up @@ -603,7 +606,7 @@ const styles = {
badgeText: {
color: themeColors.text,
fontSize: variables.fontSizeSmall,
lineHeight: 16,
lineHeight: variables.lineHeightNormal,
...whiteSpace.noWrap,
},

Expand Down Expand Up @@ -650,7 +653,7 @@ const styles = {
color: themeColors.textSupporting,
fontFamily: fontFamily.GTA,
fontSize: variables.fontSizeSmall,
lineHeight: 14,
lineHeight: variables.lineHeightSmall,
},

chatItemComposeSecondaryRowOffset: {
Expand All @@ -673,7 +676,7 @@ const styles = {
},

componentHeightLarge: {
height: variables.componentSizeLarge,
height: variables.inputHeight,
},

textInputContainer: {
Expand Down Expand Up @@ -801,7 +804,7 @@ const styles = {
},
picker: (disabled = false, error = false, focused = false) => ({
iconContainer: {
top: 16,
top: Math.round(variables.inputHeight * 0.5) - 10,
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is weird, care to explain this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

TO vertically center a child in its parent we need padding top = half parent height - half child height, in our case half input height = 26 and half icon height = 10 so we need padding top = 16, but because the input height increases when the device font size increases so instead of using a hard coded value we can make it dynamic.

Copy link
Collaborator

Choose a reason for hiding this comment

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

This calculation, itself seems off can we move the computation variables at least?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Do you mean keeping top: variables.pickerIconTop in styles.js and in variables.js file using this pickerIconTop: (getValueUsingPixelRatio(52, 72) * 0.5) - 10?

right: 11,
zIndex: -1,
},
Expand Down Expand Up @@ -859,21 +862,21 @@ const styles = {
fontWeight: fontWeightBold,
color: themeColors.heading,
fontSize: variables.fontSizeLabel,
lineHeight: 18,
lineHeight: variables.lineHeightLarge,
marginBottom: 8,
},

formHelp: {
color: themeColors.textSupporting,
fontSize: variables.fontSizeLabel,
lineHeight: 18,
lineHeight: variables.lineHeightLarge,
marginBottom: 4,
},

formError: {
color: themeColors.textError,
fontSize: variables.fontSizeLabel,
lineHeight: 18,
lineHeight: variables.formErrorLineHeight,
marginBottom: 4,
},

Expand Down Expand Up @@ -962,7 +965,7 @@ const styles = {
alignItems: 'center',
display: 'flex',
justifyContent: 'center',
paddingVertical: 20,
paddingVertical: variables.lineHeightXLarge,
width: '100%',
},

Expand Down Expand Up @@ -1178,8 +1181,8 @@ const styles = {

optionDisplayName: {
fontFamily: fontFamily.GTA,
height: 20,
lineHeight: 20,
height: variables.alternateTextHeight,
lineHeight: variables.lineHeightXLarge,
...whiteSpace.noWrap,
},

Expand All @@ -1198,8 +1201,8 @@ const styles = {
},

optionAlternateText: {
height: 20,
lineHeight: 20,
height: variables.alternateTextHeight,
lineHeight: variables.lineHeightXLarge,
},

optionAlternateTextCompact: {
Expand Down Expand Up @@ -1305,7 +1308,7 @@ const styles = {
fontFamily: fontFamily.GTA_BOLD,
fontSize: variables.fontSizeNormal,
fontWeight: fontWeightBold,
lineHeight: 20,
lineHeight: variables.lineHeightXLarge,
paddingRight: 5,
paddingBottom: 4,
...wordBreak.breakWord,
Expand All @@ -1316,14 +1319,14 @@ const styles = {
color: themeColors.textSupporting,
fontSize: variables.fontSizeSmall,
height: 24,
lineHeight: 20,
lineHeight: variables.lineHeightXLarge,
},

chatItemMessage: {
color: themeColors.text,
fontSize: variables.fontSizeNormal,
fontFamily: fontFamily.GTA,
lineHeight: 20,
lineHeight: variables.lineHeightXLarge,
marginTop: -2,
marginBottom: -2,
maxWidth: '100%',
Expand All @@ -1339,7 +1342,7 @@ const styles = {
color: colors.blue,
fontSize: variables.fontSizeNormal,
fontFamily: fontFamily.GTA,
lineHeight: 20,
lineHeight: variables.lineHeightXLarge,
},

chatItemComposeWithFirstRow: {
Expand Down Expand Up @@ -1394,7 +1397,7 @@ const styles = {
borderWidth: 0,
borderRadius: 0,
height: 'auto',
lineHeight: 20,
lineHeight: variables.lineHeightXLarge,
...overflowXHidden,

// On Android, multiline TextInput with height: 'auto' will show extra padding unless they are configured with
Expand Down Expand Up @@ -2369,7 +2372,7 @@ const styles = {
peopleBadgeText: {
color: themeColors.textReversed,
fontSize: variables.fontSizeSmall,
lineHeight: 16,
lineHeight: variables.lineHeightNormal,
...whiteSpace.noWrap,
},

Expand Down Expand Up @@ -2466,7 +2469,7 @@ const styles = {
},

communicationsLinkHeight: {
height: 20,
height: variables.communicationsLinkHeight,
},

floatingMessageCounterWrapper: {
Expand Down
49 changes: 40 additions & 9 deletions src/styles/variables.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,23 @@
import {PixelRatio} from 'react-native';

/**
* Calculate the fontSize, lineHeight and padding when the device font size is changed, In most cases users do not change their device font size so PixelRatio.getFontScale() = 1 and this
* method always return defaultValue (first param). when device font size increases/decrease, PixelRatio.getFontScale() value increases/decrease as well. this means if you hava a text
* and the 'fontSize' of it is 19, then the device font size changed to the 5th level on ios slider now the actual fontSize = 19 * PixelRatio.getFontScale() = 19 * 1.11 = 21.09 since we are
* disallowing font scaling we need to calculate it manually, so we are using this equation : PixelRatio.getFontScale() * defaultValue > maxValue ? maxValue : defaultValue * PixelRatio.
* getFontScale() this equation means increases/decreases the fontSize when the device font size increases/decreases but do not increase it if the fontSize value exceed maxValue (second
* param).
* @param {Number} defaultValue
* @param {Number} maxValue
* @returns {Number}
*/
function getValueUsingPixelRatio(defaultValue, maxValue) {
return PixelRatio.getFontScale() * defaultValue > maxValue ? maxValue : defaultValue * PixelRatio.getFontScale();
}

export default {
contentHeaderHeight: 65,
componentSizeSmall: 28,
contentHeaderHeight: getValueUsingPixelRatio(65, 100),
componentSizeSmall: getValueUsingPixelRatio(28, 32),
componentSizeNormal: 40,
inputComponentSizeNormal: 42,
componentSizeLarge: 52,
Expand All @@ -15,17 +32,22 @@ export default {
avatarSizeSmallSubscript: 14,
fontSizeOnlyEmojis: 30,
fontSizeOnlyEmojisHeight: 35,
fontSizeSmall: 11,
fontSizeSmall: getValueUsingPixelRatio(11, 17),
fontSizeExtraSmall: 9,
fontSizeLabel: 13,
fontSizeNormal: 15,
fontSizeMedium: 16,
fontSizeLarge: 17,
fontSizeLabel: getValueUsingPixelRatio(13, 19),
fontSizeNormal: getValueUsingPixelRatio(15, 21),
fontSizeMedium: getValueUsingPixelRatio(16, 22),
fontSizeLarge: getValueUsingPixelRatio(17, 19),
lineHeightSmallFont: getValueUsingPixelRatio(11, 17),
lineHeightLabelFont: getValueUsingPixelRatio(13, 19),
lineHeightNormalFont: getValueUsingPixelRatio(15, 21),
lineHeightMediumFont: getValueUsingPixelRatio(16, 22),
lineHeightLargeFont: getValueUsingPixelRatio(17, 19),
fontSizeHero: 36,
fontSizeh1: 19,
fontSizeXXLarge: 28,
fontSizeXXXLarge: 32,
fontSizeNormalHeight: 20,
fontSizeNormalHeight: getValueUsingPixelRatio(20, 28),
lineHeightHero: 40,
iconSizeXXXSmall: 4,
iconSizeXXSmall: 8,
Expand All @@ -49,7 +71,16 @@ export default {
minHeightToShowGraphics: 854, // Login form layout breaks below this height due to insufficient space to show the form and graphics
optionRowHeight: 64,
optionRowHeightCompact: 52,
optionsListSectionHeaderHeight: 54,
optionsListSectionHeaderHeight: getValueUsingPixelRatio(54, 60),
lineHeightSmall: getValueUsingPixelRatio(14, 16),
lineHeightNormal: getValueUsingPixelRatio(16, 21),
lineHeightLarge: getValueUsingPixelRatio(18, 24),
lineHeightXLarge: getValueUsingPixelRatio(20, 24),
inputHeight: getValueUsingPixelRatio(52, 72),
formErrorLineHeight: getValueUsingPixelRatio(18, 23),
communicationsLinkHeight: getValueUsingPixelRatio(20, 30),
alternateTextHeight: getValueUsingPixelRatio(20, 24),
INACTIVE_LABEL_TRANSLATE_Y: getValueUsingPixelRatio(16, 21),
sliderBarHeight: 8,
sliderKnobSize: 26,
};