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 all 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
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),
]}
Comment on lines +275 to +278
Copy link
Contributor

Choose a reason for hiding this comment

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

This PR caused a regression in #30275. This dynamic style caused an inconsistency of the text style for amount with the money report preview in ReportPreview which has a fixed style for the amount.

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 @@ -1180,6 +1180,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 @@ -1263,5 +1292,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
Loading