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 2 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
31 changes: 30 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 * 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 @@ -134,6 +136,9 @@
if (_.isEmpty(props.iouReport) && !props.isBillSplit) {
return null;
}

const {isSmallScreenWidth, windowWidth} = useWindowDimensions();

Check failure on line 140 in src/components/ReportActionItem/MoneyRequestPreview.js

View workflow job for this annotation

GitHub Actions / lint

React Hook "useWindowDimensions" is called conditionally. React Hooks must be called in the exact same order in every component render

const sessionAccountID = lodashGet(props.session, 'accountID', null);
const managerID = props.iouReport.managerID || '';
const ownerAccountID = props.iouReport.ownerAccountID || '';
Expand All @@ -159,6 +164,22 @@
description = props.transaction.merchant;
}

// Prevents large amounts from being cropped on small screens
const getFontSizeToSubstract = () => {
let toSubstract = 0;
if (isSmallScreenWidth) {
const widthDifference = variables.mobileResponsiveWidthBreakpoint - windowWidth;
if (widthDifference > 450) toSubstract = 9;
else if (widthDifference > 400) toSubstract = 6;
else if (widthDifference > 350) toSubstract = 2;
}

// requestAmount also includes digits after ".", so "1,000,000.00" qualifies.
if (requestAmount >= 100000000) toSubstract += 2;

return toSubstract;
};

const getSettledMessage = () => {
switch (lodashGet(props.action, 'originalMessage.paymentType', '')) {
case CONST.IOU.PAYMENT_TYPE.PAYPAL_ME:
Expand Down Expand Up @@ -253,7 +274,15 @@
</View>
<View style={[styles.flexRow]}>
<View style={[styles.flex1, styles.flexRow, styles.alignItemsCenter]}>
<Text style={styles.textHeadline}>{getDisplayAmountText()}</Text>
<Text
style={[
styles.moneyRequestPreviewAmount,
StyleUtils.getFontSizeStyle(variables.fontSizeXLarge - getFontSizeToSubstract()),
]}
maxNumberOfLines={3}
Julesssss marked this conversation as resolved.
Show resolved Hide resolved
>
{getDisplayAmountText()}
</Text>
{ReportUtils.isSettled(props.iouReport.reportID) && !props.isBillSplit && (
<View style={styles.defaultCheckmarkWrapper}>
<Icon
Expand Down
7 changes: 7 additions & 0 deletions src/styles/styles.js
Original file line number Diff line number Diff line change
Expand Up @@ -2681,6 +2681,13 @@ const styles = {
marginBottom: 0,
},

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

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