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

[24321] Large amounts are no longer cut off on smaller widths. #26280

Merged
merged 19 commits into from
Sep 11, 2023
Merged
Show file tree
Hide file tree
Changes from 9 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
15 changes: 14 additions & 1 deletion src/components/ReportActionItem/MoneyRequestPreview.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ import PressableWithFeedback from '../Pressable/PressableWithoutFeedback';
import * as ReceiptUtils from '../../libs/ReceiptUtils';
import ReportActionItemImages from './ReportActionItemImages';
import transactionPropTypes from '../transactionPropTypes';
import variables from '../../styles/variables';
import useWindowDimensions from '../../hooks/useWindowDimensions';

const propTypes = {
/** The active IOUReport, used for Onyx subscription */
Expand Down Expand Up @@ -131,9 +133,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 @@ -253,7 +258,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, requestAmount),
]}
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.js
Original file line number Diff line number Diff line change
Expand Up @@ -1329,6 +1329,35 @@ function getDropDownButtonHeight(buttonSize) {
};
}

/**
* Returns fitting fontSize and lineHeight values in order to prevent large amounts from being cut off on small screen widths.
*
* @param {Number} baseFontSize
* @param {Number} baseLineHeight
* @param {Boolean} isSmallScreenWidth
* @param {Number} windowWidth
* @param {Number} requestAmount
* @returns {Object}
*/
function getAmountFontSizeAndLineHeight(baseFontSize, baseLineHeight, isSmallScreenWidth, windowWidth, requestAmount) {
let toSubtract = 0;

if (isSmallScreenWidth) {
const widthDifference = variables.mobileResponsiveWidthBreakpoint - windowWidth;
if (widthDifference > 350) toSubtract = 2;
if (widthDifference > 400) toSubtract = 6;
if (widthDifference > 450) toSubtract = 9;
pecanoro marked this conversation as resolved.
Show resolved Hide resolved
}

// requestAmount also includes digits after ".", so "1,000,000.00" qualifies.
if (requestAmount >= 100000000) toSubtract += 2;
pecanoro marked this conversation as resolved.
Show resolved Hide resolved

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

export {
getAvatarSize,
getAvatarWidthStyle,
Expand Down Expand Up @@ -1404,4 +1433,5 @@ export {
getDisabledLinkStyles,
getCheckboxContainerStyle,
getDropDownButtonHeight,
getAmountFontSizeAndLineHeight,
};
6 changes: 6 additions & 0 deletions src/styles/styles.js
Original file line number Diff line number Diff line change
Expand Up @@ -2681,6 +2681,12 @@ const styles = {
marginBottom: 0,
},

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

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