Skip to content

Commit

Permalink
Merge pull request #41717 from Expensify/youssef_fix_focused_option
Browse files Browse the repository at this point in the history
[CP Staging] Uneven splits follow up
  • Loading branch information
marcaaron authored May 7, 2024
2 parents 5554726 + 936bb93 commit dcda83e
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 15 deletions.
6 changes: 5 additions & 1 deletion src/components/AmountTextInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ type AmountTextInputProps = {

/** Style for the TextInput container */
containerStyle?: StyleProp<ViewStyle>;

/** Hide the focus styles on TextInput */
hideFocusedState?: boolean;
} & Pick<BaseTextInputProps, 'autoFocus'>;

function AmountTextInput(
Expand All @@ -50,14 +53,15 @@ function AmountTextInput(
onKeyPress,
containerStyle,
disableKeyboard = true,
hideFocusedState = true,
...rest
}: AmountTextInputProps,
ref: ForwardedRef<BaseTextInputRef>,
) {
return (
<TextInput
autoGrow
hideFocusedState
hideFocusedState={hideFocusedState}
shouldInterceptSwipe
disableKeyboard={disableKeyboard}
inputStyle={style}
Expand Down
6 changes: 6 additions & 0 deletions src/components/MoneyRequestAmountInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,11 @@ type MoneyRequestAmountInputProps = {
/** Whether we want to format the display amount on blur */
formatAmountOnBlur?: boolean;

/** Max length for the amount input */
maxLength?: number;

/** Hide the focus styles on TextInput */
hideFocusedState?: boolean;
};

type Selection = {
Expand Down Expand Up @@ -99,6 +103,7 @@ function MoneyRequestAmountInput(
disableKeyboard = true,
formatAmountOnBlur,
maxLength,
hideFocusedState = true,
...props
}: MoneyRequestAmountInputProps,
forwardedRef: ForwardedRef<BaseTextInputRef>,
Expand Down Expand Up @@ -279,6 +284,7 @@ function MoneyRequestAmountInput(
prefixContainerStyle={props.prefixContainerStyle}
touchableInputWrapperStyle={props.touchableInputWrapperStyle}
maxLength={maxLength}
hideFocusedState={hideFocusedState}
/>
);
}
Expand Down
8 changes: 4 additions & 4 deletions src/components/MoneyRequestConfirmationList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -473,9 +473,8 @@ function MoneyRequestConfirmationList({
let amount: number | undefined = 0;
if (iouAmount > 0) {
amount =
isPolicyExpenseChat || !transaction?.comment?.splits
? IOUUtils.calculateAmount(selectedParticipants.length, iouAmount, iouCurrencyCode ?? '', isPayer)
: transaction.comment.splits.find((split) => split.accountID === participantOption.accountID)?.amount;
transaction?.comment?.splits?.find((split) => split.accountID === participantOption.accountID)?.amount ??
IOUUtils.calculateAmount(selectedParticipants.length, iouAmount, iouCurrencyCode ?? '', isPayer);
}
return {
...participantOption,
Expand All @@ -502,7 +501,7 @@ function MoneyRequestConfirmationList({
onAmountChange: (value: string) => onSplitShareChange(participantOption.accountID ?? 0, Number(value)),
},
}));
}, [transaction, iouCurrencyCode, isPolicyExpenseChat, onSplitShareChange, payeePersonalDetails, selectedParticipants, currencyList, iouAmount, shouldShowReadOnlySplits, StyleUtils]);
}, [transaction, iouCurrencyCode, onSplitShareChange, payeePersonalDetails, selectedParticipants, currencyList, iouAmount, shouldShowReadOnlySplits, StyleUtils]);

const isSplitModified = useMemo(() => {
if (!transaction?.splitShares) {
Expand Down Expand Up @@ -1092,6 +1091,7 @@ function MoneyRequestConfirmationList({
onConfirmSelection={confirm}
selectedOptions={selectedOptions}
disableArrowKeysActions
disableFocusOptions
boldStyle
showTitleTooltip
shouldTextInputAppearBelowOptions
Expand Down
4 changes: 2 additions & 2 deletions src/components/OptionRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -260,16 +260,16 @@ function OptionRow({
prefixCharacter={option.amountInputProps.prefixCharacter}
disableKeyboard={false}
isCurrencyPressable={false}
hideFocusedState={false}
hideCurrencySymbol
formatAmountOnBlur
touchableInputWrapperStyle={[styles.optionRowAmountInputWrapper, option.amountInputProps.containerStyle]}
prefixContainerStyle={[styles.pv0]}
containerStyle={[styles.textInputContainer]}
inputStyle={[
styles.optionRowAmountInput,
StyleUtils.getPaddingLeft(StyleUtils.getCharacterPadding(option.amountInputProps.prefixCharacter ?? '') + styles.pl1.paddingLeft) as TextStyle,
option.amountInputProps.inputStyle,
]}
containerStyle={styles.iouAmountTextInputContainer}
onAmountChange={option.amountInputProps.onAmountChange}
maxLength={option.amountInputProps.maxLength}
/>
Expand Down
4 changes: 4 additions & 0 deletions src/components/TextInputWithCurrencySymbol/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,11 @@ type TextInputWithCurrencySymbolProps = {
/** Customizes the touchable wrapper of the TextInput component */
touchableInputWrapperStyle?: StyleProp<ViewStyle>;

/** Max length for the amount input */
maxLength?: number;

/** Hide the focus styles on TextInput */
hideFocusedState?: boolean;
} & Pick<BaseTextInputProps, 'autoFocus'>;

export default TextInputWithCurrencySymbolProps;
5 changes: 2 additions & 3 deletions src/libs/actions/IOU.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6423,9 +6423,8 @@ function setSplitShares(transaction: OnyxEntry<OnyxTypes.Transaction>, amount: n
}

const isPayer = accountID === userAccountID;

// This function expects the length of participants without current user
const splitAmount = IOUUtils.calculateAmount(accountIDs.length - 1, amount, currency, isPayer);
const participantsLength = newAccountIDs.includes(userAccountID) ? newAccountIDs.length - 1 : newAccountIDs.length;
const splitAmount = IOUUtils.calculateAmount(participantsLength, amount, currency, isPayer);
return {
...result,
[accountID]: {
Expand Down
5 changes: 0 additions & 5 deletions src/styles/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1142,11 +1142,6 @@ const styles = (theme: ThemeColors) =>
borderColor: theme.border,
},

optionRowAmountInputWrapper: {
borderColor: theme.border,
borderBottomWidth: 2,
},

optionRowAmountInput: {
textAlign: 'right',
},
Expand Down

0 comments on commit dcda83e

Please sign in to comment.