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

Fix inconsistency font size of amount text between report preview and split bill #30960

Merged
merged 8 commits into from
Nov 13, 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
9 changes: 5 additions & 4 deletions src/components/ReportActionItem/MoneyRequestPreview.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ import reportActionPropTypes from '@pages/home/report/reportActionPropTypes';
import styles from '@styles/styles';
import * as StyleUtils from '@styles/StyleUtils';
import themeColors from '@styles/themes/default';
import variables from '@styles/variables';
import * as PaymentMethods from '@userActions/PaymentMethods';
import * as Report from '@userActions/Report';
import CONST from '@src/CONST';
Expand Down Expand Up @@ -245,6 +244,8 @@ function MoneyRequestPreview(props) {
return CurrencyUtils.convertToDisplayString(amount, currency);
};

const displayAmount = isDeleted ? getDisplayDeleteAmountText() : getDisplayAmountText();

const childContainer = (
<View>
<OfflineWithFeedback
Expand Down Expand Up @@ -290,13 +291,13 @@ function MoneyRequestPreview(props) {
<View style={[styles.flex1, styles.flexRow, styles.alignItemsCenter]}>
<Text
style={[
styles.moneyRequestPreviewAmount,
StyleUtils.getAmountFontSizeAndLineHeight(variables.fontSizeXLarge, variables.lineHeightXXLarge, isSmallScreenWidth, windowWidth),
styles.textHeadline,
props.isBillSplit && StyleUtils.getAmountFontSizeAndLineHeight(isSmallScreenWidth, windowWidth, displayAmount.length, participantAvatars.length),
isDeleted && styles.lineThrough,
]}
numberOfLines={1}
>
{isDeleted ? getDisplayDeleteAmountText() : getDisplayAmountText()}
{displayAmount}
</Text>
{ReportUtils.isSettled(props.iouReport.reportID) && !props.isBillSplit && (
<View style={styles.defaultCheckmarkWrapper}>
Expand Down
47 changes: 39 additions & 8 deletions src/styles/StyleUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1257,22 +1257,53 @@ function getDropDownButtonHeight(buttonSize: ButtonSizeValue): ViewStyle {
/**
* 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): TextStyle {
function getAmountFontSizeAndLineHeight(isSmallScreenWidth: boolean, windowWidth: number, displayAmountLength: number, numberOfParticipant: number): TextStyle {
let toSubtract = 0;
const baseFontSize = variables.fontSizeXLarge;
const baseLineHeight = variables.lineHeightXXLarge;

if (isSmallScreenWidth) {
const widthDifference = variables.mobileResponsiveWidthBreakpoint - windowWidth;
const numberOfAvatar = numberOfParticipant < 4 ? numberOfParticipant : 4;
const differentWithMaxLength = 17 - displayAmountLength;

// with a window width is more than 420px the maximum amount will not be cut off with the maximum avatar displays
if (isSmallScreenWidth && windowWidth < 420) {
// Based on width Difference we can see the max length of amount can be displayed with the number of avatars.
// From there we can calculate subtract in accordance with the number of avatar and the length of amount text
const widthDifference = 420 - windowWidth;
switch (true) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we add a comment here explaining how the calculation is done ?

case widthDifference > 450:
// It is very rare for native devices to have a width smaller than 350px so add a constant subtract here
case widthDifference > 70:
toSubtract = 11;
break;
case widthDifference > 400:
toSubtract = 8;
case widthDifference > 60:
if (18 - numberOfAvatar * 2 < displayAmountLength) {
toSubtract = numberOfAvatar * 2 - differentWithMaxLength;
}
break;
case widthDifference > 50:
if (19 - numberOfAvatar * 2 < displayAmountLength) {
toSubtract = (numberOfAvatar - 1) * 2 + 1 - differentWithMaxLength;
}
break;
case widthDifference > 40:
if (20 - numberOfAvatar * 2 < displayAmountLength) {
toSubtract = (numberOfAvatar - 1) * 2 - differentWithMaxLength;
}
break;
case widthDifference > 30:
if (21 - numberOfAvatar * 2 < displayAmountLength) {
toSubtract = (numberOfAvatar - 1) * 2 - 1 - differentWithMaxLength;
}
break;
case widthDifference > 350:
toSubtract = 4;
case widthDifference > 20:
if (22 - numberOfAvatar * 2 < displayAmountLength) {
toSubtract = (numberOfAvatar - 2) * 2 - differentWithMaxLength;
}
break;
default:
if (displayAmountLength + numberOfAvatar === 21) {
toSubtract = 3;
}
break;
}
}
Expand Down
Loading