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

[HOLD] Implement Uneven Splits #40386

Merged
merged 118 commits into from
May 7, 2024
Merged
Show file tree
Hide file tree
Changes from 86 commits
Commits
Show all changes
118 commits
Select commit Hold shift + click to select a range
d99170a
Add TS definitions
youssef-lr Apr 15, 2024
99efbb6
Set split shares when first creating the split
youssef-lr Apr 15, 2024
cf65044
Add IOU functions to set split shares and adjust them
youssef-lr Apr 16, 2024
97ac991
Allow configuring split amounts
youssef-lr Apr 17, 2024
4bc7142
Use temporary amount input
youssef-lr Apr 17, 2024
e9cc173
Pass custom styles
youssef-lr Apr 17, 2024
b24ff87
Temporary updates to the amount input
youssef-lr Apr 18, 2024
6afe0e5
Merge branch 'main' into youssef_uneven_splits_2
youssef-lr Apr 18, 2024
9e53204
Allow setting individual shares
youssef-lr Apr 18, 2024
00db6ff
Show a form error if sum of shares don't match total
youssef-lr Apr 18, 2024
23d8693
Prevent submitting form if total doesn't match
youssef-lr Apr 18, 2024
cc3de14
Adjust shares automatically
youssef-lr Apr 18, 2024
d98103f
Revert changes
youssef-lr Apr 18, 2024
14c9ead
Use temporary input
youssef-lr Apr 18, 2024
f032df0
Show even splits for workspace chat splits
youssef-lr Apr 18, 2024
3d2e12e
Send uneven splits to backend
youssef-lr Apr 18, 2024
eb5c8f1
Save splits array in the transaction optimistically
youssef-lr Apr 18, 2024
39fa362
Merge branch 'main' into youssef_uneven_splits_2
youssef-lr Apr 19, 2024
2001821
Copy changes to MoneyRequestConfirmationList
youssef-lr Apr 19, 2024
f8116b3
Allow excluding group chat users from splits by setting amount to 0
youssef-lr Apr 19, 2024
756d11a
Reset split shares when amount changes
youssef-lr Apr 20, 2024
1cd5bd1
Display read only shares in splti details page
youssef-lr Apr 20, 2024
2cb1d95
Show split share in split preview card
youssef-lr Apr 20, 2024
959d6d0
Allow easy tab navigation for inputs
youssef-lr Apr 20, 2024
e75e56f
Refactoring and TS fixes
youssef-lr Apr 20, 2024
7baa777
wip: Reset button
youssef-lr Apr 20, 2024
6712733
Allow resetting the amounts
youssef-lr Apr 20, 2024
327624e
Bug fix
youssef-lr Apr 21, 2024
e915d7c
Debounce form error in splits page
youssef-lr Apr 22, 2024
845d1a6
Bug fix
youssef-lr Apr 22, 2024
6d5762f
Lint
youssef-lr Apr 22, 2024
5c1758e
Hide inputs for Smartscan splits
youssef-lr Apr 22, 2024
1579091
Fix currency not shown in split amounts in details page
youssef-lr Apr 23, 2024
bca161b
Bug fix
youssef-lr Apr 23, 2024
f5b0c10
Filter out participants with shares equal to 0
youssef-lr Apr 23, 2024
db455e5
Prevent creating a split containing a single participant
youssef-lr Apr 23, 2024
cbe5d36
Prevent submitting form if there's an error
youssef-lr Apr 23, 2024
5dd0aed
Merge branch 'main' into youssef_uneven_splits_2
youssef-lr Apr 23, 2024
66c367d
Lint
youssef-lr Apr 23, 2024
dc7f13d
Merge branch 'main' into youssef_uneven_splits_2
youssef-lr Apr 23, 2024
a22f42d
Add margin next to participant emails
youssef-lr Apr 23, 2024
57610d7
Merge branch 'main' into youssef_uneven_splits_2
youssef-lr Apr 25, 2024
ec56107
Always show confirmation for uneven splits
youssef-lr Apr 25, 2024
6cd30c2
Fix input style
youssef-lr Apr 25, 2024
4e71237
Clean up code for section button
youssef-lr Apr 25, 2024
076d99a
Merge branch 'main' into youssef_uneven_splits_2
youssef-lr Apr 25, 2024
e064698
TS lint
youssef-lr Apr 25, 2024
e7ff3dc
More lint
youssef-lr Apr 25, 2024
8f33768
Skip confirmation screen for smartscanned splits
youssef-lr Apr 25, 2024
d5da181
Remove workaround for removing participants
youssef-lr Apr 25, 2024
7eba6d0
Bring back effect
youssef-lr Apr 25, 2024
23e41fe
Lint
youssef-lr Apr 25, 2024
061fcf1
Don't run unneeded logic unless we have modified shares
youssef-lr Apr 25, 2024
946d75f
Translation
youssef-lr Apr 25, 2024
6590eb4
TS
youssef-lr Apr 25, 2024
ed6f2e3
More TS
youssef-lr Apr 25, 2024
624bad4
Merge branch 'main' into youssef_uneven_splits_2
youssef-lr Apr 25, 2024
af91070
TS and comment imporvement
youssef-lr Apr 25, 2024
2d0d0ba
Remove unintended changes
youssef-lr Apr 25, 2024
17c172b
One last TS fix
youssef-lr Apr 25, 2024
64a8525
Remove unintended change
youssef-lr Apr 26, 2024
58da039
Merge branch 'main' into youssef_uneven_splits_2
youssef-lr Apr 26, 2024
d49ab6d
Cleanup
youssef-lr Apr 26, 2024
d0ce531
Cleanup
youssef-lr Apr 26, 2024
4df0953
Header new copy
youssef-lr Apr 26, 2024
dd6005f
Add comment
youssef-lr Apr 26, 2024
e46a6ce
Show current user's share in the split preview
youssef-lr Apr 26, 2024
1599a86
Merge branch 'main' into youssef_uneven_splits_2
youssef-lr Apr 26, 2024
0daec60
Fix form error disappearing
youssef-lr Apr 26, 2024
9a74508
Fix merchant error missing when completing a split bill
youssef-lr Apr 26, 2024
9dee700
Cleanup
youssef-lr Apr 26, 2024
742e4e3
Rename variable
youssef-lr Apr 26, 2024
44ad9e1
Clean up code
youssef-lr Apr 26, 2024
f3db250
Fix selection always moving to the end
youssef-lr Apr 26, 2024
f2b7bf6
Proper fix for selection moving when amount changes
youssef-lr Apr 28, 2024
7afaca5
Add comment
youssef-lr Apr 28, 2024
5c594aa
Clarify comment
youssef-lr Apr 28, 2024
fbad80a
Copy update
youssef-lr Apr 28, 2024
4deb9ec
Clean up code
youssef-lr Apr 28, 2024
14d5775
Format amounts
youssef-lr Apr 28, 2024
09cde3c
Cleanup
youssef-lr Apr 28, 2024
51041d8
Fix keyboard disabled on native
youssef-lr Apr 29, 2024
d00fb89
Update MoneyRequestAmountInput.tsx
youssef-lr Apr 29, 2024
cea2cf8
Rename callback
youssef-lr Apr 29, 2024
4431b47
Merge branch 'main' into youssef_uneven_splits_2
youssef-lr Apr 29, 2024
dc97bfd
Bug fix
youssef-lr Apr 29, 2024
4b64601
Merge branch 'main' into youssef_uneven_splits_2
youssef-lr Apr 30, 2024
3ac8cb3
TS fix
youssef-lr Apr 30, 2024
9641c4d
Fix input flickering
youssef-lr May 1, 2024
dbe50b9
Bug fixes and add logic to native
youssef-lr May 1, 2024
ce825c9
Style
youssef-lr May 1, 2024
b3c6539
Add autoGrowDirection
youssef-lr May 1, 2024
eb81dff
Cleanup
youssef-lr May 1, 2024
36c5e35
Add a missing change to native
youssef-lr May 1, 2024
fc3768b
Cleanup
youssef-lr May 1, 2024
c2303f0
TS
youssef-lr May 1, 2024
516f2de
Bug fix
youssef-lr May 1, 2024
9657b24
Show dot in numeric keyboard
youssef-lr May 1, 2024
1061dfd
Merge branch 'main' into youssef_uneven_splits_2
youssef-lr May 1, 2024
0397b60
Merge branch 'main' into youssef_uneven_splits_2
youssef-lr May 2, 2024
37deba6
Add accessibility hit slope
youssef-lr May 3, 2024
626ecda
Revert implementation of autgrow with direction to the left
youssef-lr May 3, 2024
7305b68
Revert unintended changes
youssef-lr May 3, 2024
f745d48
Don't format amount when text input is focused
youssef-lr May 3, 2024
c4bc1fd
Don't break other existing amount inputs
youssef-lr May 3, 2024
188e7a2
Remove unneeded prop
youssef-lr May 3, 2024
1332a1c
Remove unused param
youssef-lr May 3, 2024
0d04ae4
Update styles and right-align input
youssef-lr May 3, 2024
ceb81ed
Adjust padding based on prefix length relating to uppercase letters
youssef-lr May 3, 2024
ca87ee5
Replace comma input with period for native keyboards that show a comma
youssef-lr May 3, 2024
c397762
Calculate exact width of the input based on total amount length
youssef-lr May 6, 2024
8af33a4
Add callback removed by mistake
youssef-lr May 6, 2024
672e3ec
Allow editing formatted amount
youssef-lr May 6, 2024
2b296bb
Use fixed width for inputs and max length
youssef-lr May 6, 2024
2056fb0
Don't format amount on blur if it exceeds max length
youssef-lr May 6, 2024
d5ce4cf
Reset selection on blur on mobile
youssef-lr May 6, 2024
209cac2
Merge branch 'main' into youssef_uneven_splits_2
youssef-lr May 6, 2024
c9021df
Fix paidBy section being sticky
youssef-lr May 7, 2024
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
19 changes: 17 additions & 2 deletions src/components/AmountTextInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ type AmountTextInputProps = {
/** Style for the container */
touchableInputWrapperStyle?: StyleProp<ViewStyle>;

/** Whether to disable keyboard */
disableKeyboard?: boolean;

/** Function to call to handle key presses in the text input */
onKeyPress?: (event: NativeSyntheticEvent<KeyboardEvent>) => void;

Expand All @@ -36,15 +39,27 @@ type AmountTextInputProps = {
} & Pick<BaseTextInputProps, 'autoFocus'>;

function AmountTextInput(
{formattedAmount, onChangeAmount, placeholder, selection, onSelectionChange, style, touchableInputWrapperStyle, onKeyPress, containerStyle, ...rest}: AmountTextInputProps,
{
formattedAmount,
onChangeAmount,
placeholder,
selection,
onSelectionChange,
style,
touchableInputWrapperStyle,
onKeyPress,
containerStyle,
disableKeyboard = true,
...rest
}: AmountTextInputProps,
ref: ForwardedRef<BaseTextInputRef>,
) {
return (
<TextInput
disableKeyboard
autoGrow
hideFocusedState
shouldInterceptSwipe
disableKeyboard={disableKeyboard}
inputStyle={style}
textInputContainerStyles={containerStyle}
onChangeText={onChangeAmount}
Expand Down
44 changes: 38 additions & 6 deletions src/components/MoneyRequestAmountInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ type MoneyRequestAmountInputProps = {
/** Whether to hide the currency symbol */
hideCurrencySymbol?: boolean;

/** Whether to disable native keyboard on mobile */
disableKeyboard?: boolean;

/** Style for the prefix */
prefixStyle?: StyleProp<TextStyle>;

Expand All @@ -62,6 +65,12 @@ type MoneyRequestAmountInputProps = {

/** Style for the touchable input wrapper */
touchableInputWrapperStyle?: StyleProp<ViewStyle>;

/** Whether we want to format the display amount on blur */
formatAmountOnBlur?: boolean;

/** Whether to format display amount when the `amount` prop changes from the outside */
formatAmountOnChange?: boolean;
};

type Selection = {
Expand All @@ -88,6 +97,9 @@ function MoneyRequestAmountInput(
hideCurrencySymbol = false,
shouldUpdateSelection = true,
moneyRequestAmountInputRef,
disableKeyboard = true,
formatAmountOnBlur,
formatAmountOnChange,
...props
}: MoneyRequestAmountInputProps,
forwardedRef: ForwardedRef<BaseTextInputRef>,
Expand All @@ -114,6 +126,11 @@ function MoneyRequestAmountInput(
*/
const setNewAmount = useCallback(
(newAmount: string) => {
if (!newAmount) {
setCurrentAmount('');
return;
}

// Remove spaces from the newAmount value because Safari on iOS adds spaces when pasting a copied value
// More info: https://github.com/Expensify/App/issues/16974
const newAmountWithoutSpaces = MoneyRequestUtils.stripSpacesFromAmount(newAmount);
Expand Down Expand Up @@ -163,12 +180,18 @@ function MoneyRequestAmountInput(
if (!currency || typeof amount !== 'number') {
return;
}
const frontendAmount = amount ? CurrencyUtils.convertToFrontendAmount(amount).toString() : '';
const frontendAmount = formatAmountOnChange ? CurrencyUtils.convertToDisplayStringWithoutCurrency(amount, currency) : CurrencyUtils.convertToFrontendAmount(amount).toString();
setCurrentAmount(frontendAmount);
setSelection({
start: frontendAmount.length,
end: frontendAmount.length,
});

// Only update selection if the amount prop was changed from the outside and is not the same as the current amount we just computed
// In the line below the currentAmount is not immediately updated, it should still hold the previous value.
if (frontendAmount !== currentAmount) {
setSelection({
start: frontendAmount.length,
end: frontendAmount.length,
});
}

// we want to re-initialize the state only when the amount changes
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [amount]);
Expand Down Expand Up @@ -204,13 +227,22 @@ function MoneyRequestAmountInput(
forwardDeletePressedRef.current = key === 'delete' || ((operatingSystem === CONST.OS.MAC_OS || operatingSystem === CONST.OS.IOS) && nativeEvent?.ctrlKey && key === 'd');
};

const formatAmount = useCallback(() => {
if (!formatAmountOnBlur) {
return;
}
setCurrentAmount(CurrencyUtils.convertToDisplayStringWithoutCurrency(amount, currency));
}, [amount, currency, formatAmountOnBlur]);

const formattedAmount = MoneyRequestUtils.replaceAllDigits(currentAmount, toLocaleDigit);

return (
<TextInputWithCurrencySymbol
disableKeyboard={disableKeyboard}
formattedAmount={formattedAmount}
onChangeAmount={setNewAmount}
onCurrencyButtonPress={onCurrencyButtonPress}
onBlur={formatAmount}
placeholder={numberFormat(0)}
ref={(ref) => {
if (typeof forwardedRef === 'function') {
Expand Down Expand Up @@ -248,4 +280,4 @@ function MoneyRequestAmountInput(
MoneyRequestAmountInput.displayName = 'MoneyRequestAmountInput';

export default React.forwardRef(MoneyRequestAmountInput);
export type {CurrentMoney, MoneyRequestAmountInputRef};
export type {CurrentMoney, MoneyRequestAmountInputProps, MoneyRequestAmountInputRef};
Loading
Loading