Skip to content

Commit

Permalink
Merge pull request #26280 from DanutGavrus/fix/24321-large-amounts-cu…
Browse files Browse the repository at this point in the history
…t-off

[24321] Large amounts are no longer cut off on smaller widths.
  • Loading branch information
Julesssss authored Sep 11, 2023
2 parents 62f9a49 + bc0527f commit a4225a7
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/components/ReportActionItem/MoneyRequestPreview.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,10 @@ import PressableWithFeedback from '../Pressable/PressableWithoutFeedback';
import * as ReceiptUtils from '../../libs/ReceiptUtils';
import ReportActionItemImages from './ReportActionItemImages';
import transactionPropTypes from '../transactionPropTypes';
import * as StyleUtils from '../../styles/StyleUtils';
import colors from '../../styles/colors';
import variables from '../../styles/variables';
import useWindowDimensions from '../../hooks/useWindowDimensions';
import MoneyRequestSkeletonView from '../MoneyRequestSkeletonView';

const propTypes = {
Expand Down Expand Up @@ -135,9 +138,12 @@ const defaultProps = {
};

function MoneyRequestPreview(props) {
const {isSmallScreenWidth, windowWidth} = useWindowDimensions();

if (_.isEmpty(props.iouReport) && !props.isBillSplit) {
return null;
}

const sessionAccountID = lodashGet(props.session, 'accountID', null);
const managerID = props.iouReport.managerID || '';
const ownerAccountID = props.iouReport.ownerAccountID || '';
Expand Down Expand Up @@ -265,7 +271,15 @@ function MoneyRequestPreview(props) {
</View>
<View style={[styles.flexRow]}>
<View style={[styles.flex1, styles.flexRow, styles.alignItemsCenter]}>
<Text style={styles.textHeadline}>{getDisplayAmountText()}</Text>
<Text
style={[
styles.moneyRequestPreviewAmount,
StyleUtils.getAmountFontSizeAndLineHeight(variables.fontSizeXLarge, variables.lineHeightXXLarge, isSmallScreenWidth, windowWidth),
]}
numberOfLines={1}
>
{getDisplayAmountText()}
</Text>
{ReportUtils.isSettled(props.iouReport.reportID) && !props.isBillSplit && (
<View style={styles.defaultCheckmarkWrapper}>
<Icon
Expand Down
30 changes: 30 additions & 0 deletions src/styles/StyleUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1187,6 +1187,35 @@ function getDropDownButtonHeight(buttonSize: ButtonSizeValue): ViewStyle | CSSPr
};
}

/**
* Returns fitting fontSize and lineHeight values in order to prevent large amounts from being cut off on small screen widths.
*/
function getAmountFontSizeAndLineHeight(baseFontSize: number, baseLineHeight: number, isSmallScreenWidth: boolean, windowWidth: number): ViewStyle | CSSProperties {
let toSubtract = 0;

if (isSmallScreenWidth) {
const widthDifference = variables.mobileResponsiveWidthBreakpoint - windowWidth;
switch (true) {
case widthDifference > 450:
toSubtract = 11;
break;
case widthDifference > 400:
toSubtract = 8;
break;
case widthDifference > 350:
toSubtract = 4;
break;
default:
break;
}
}

return {
fontSize: baseFontSize - toSubtract,
lineHeight: baseLineHeight - toSubtract,
};
}

/**
* Get transparent color by setting alpha value 0 of the passed hex(#xxxxxx) color code
*/
Expand Down Expand Up @@ -1270,5 +1299,6 @@ export {
getDisabledLinkStyles,
getCheckboxContainerStyle,
getDropDownButtonHeight,
getAmountFontSizeAndLineHeight,
getTransparentColor,
};
6 changes: 6 additions & 0 deletions src/styles/styles.js
Original file line number Diff line number Diff line change
Expand Up @@ -2700,6 +2700,12 @@ const styles = {
marginBottom: 0,
},

moneyRequestPreviewAmount: {
...headlineFont,
...whiteSpace.preWrap,
color: themeColors.heading,
},

defaultCheckmarkWrapper: {
marginLeft: 8,
alignSelf: 'center',
Expand Down

0 comments on commit a4225a7

Please sign in to comment.