Skip to content

Commit

Permalink
Merge pull request #36497 from shubham1206agra/fix-currency-ui
Browse files Browse the repository at this point in the history
Fixed currency pressable ui and padding issues
  • Loading branch information
aldo-expensify authored Feb 14, 2024
2 parents 7d2eb99 + 605985d commit af1026e
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 4 deletions.
8 changes: 6 additions & 2 deletions src/components/AmountForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ type AmountFormProps = {

/** Fired when back button pressed, navigates to currency selection page */
onCurrencyButtonPress?: () => void;

/** Whether the currency symbol is pressable */
isCurrencyPressable?: boolean;
};

/**
Expand All @@ -48,7 +51,7 @@ const NUM_PAD_CONTAINER_VIEW_ID = 'numPadContainerView';
const NUM_PAD_VIEW_ID = 'numPadView';

function AmountForm(
{value: amount, currency = CONST.CURRENCY.USD, extraDecimals = 0, errorText, onInputChange, onCurrencyButtonPress}: AmountFormProps,
{value: amount, currency = CONST.CURRENCY.USD, extraDecimals = 0, errorText, onInputChange, onCurrencyButtonPress, isCurrencyPressable = true}: AmountFormProps,
forwardedRef: ForwardedRef<BaseTextInputRef>,
) {
const styles = useThemeStyles();
Expand Down Expand Up @@ -210,10 +213,11 @@ function AmountForm(
setSelection(e.nativeEvent.selection);
}}
onKeyPress={textInputKeyPress}
isCurrencyPressable={isCurrencyPressable}
/>
{!!errorText && (
<FormHelpMessage
style={[styles.pAbsolute, styles.b0, styles.mb0, styles.w100]}
style={[styles.pAbsolute, styles.b0, canUseTouchScreen ? styles.mb0 : styles.mb3, styles.ph5, styles.w100]}
isError
message={errorText}
/>
Expand Down
12 changes: 10 additions & 2 deletions src/components/CurrencySymbolButton.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React from 'react';
import {View} from 'react-native';
import useLocalize from '@hooks/useLocalize';
import useTheme from '@hooks/useTheme';
import useThemeStyles from '@hooks/useThemeStyles';
Expand All @@ -15,13 +16,16 @@ type CurrencySymbolButtonProps = {

/** Function to call when currency button is pressed */
onCurrencyButtonPress: () => void;

/** Whether the currency button is pressable or not */
isCurrencyPressable?: boolean;
};

function CurrencySymbolButton({onCurrencyButtonPress, currencySymbol}: CurrencySymbolButtonProps) {
function CurrencySymbolButton({onCurrencyButtonPress, currencySymbol, isCurrencyPressable = true}: CurrencySymbolButtonProps) {
const {translate} = useLocalize();
const styles = useThemeStyles();
const theme = useTheme();
return (
return isCurrencyPressable ? (
<Tooltip text={translate('common.selectCurrency')}>
<PressableWithoutFeedback
onPress={onCurrencyButtonPress}
Expand All @@ -37,6 +41,10 @@ function CurrencySymbolButton({onCurrencyButtonPress, currencySymbol}: CurrencyS
<Text style={styles.iouAmountText}>{currencySymbol}</Text>
</PressableWithoutFeedback>
</Tooltip>
) : (
<View style={[styles.flexRow, styles.alignItemsCenter, styles.gap1]}>
<Text style={styles.iouAmountText}>{currencySymbol}</Text>
</View>
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ function BaseTextInputWithCurrencySymbol(
selection,
onSelectionChange = () => {},
onKeyPress = () => {},
isCurrencyPressable = true,
}: TextInputWithCurrencySymbolProps,
ref: React.ForwardedRef<BaseTextInputRef>,
) {
Expand All @@ -31,6 +32,7 @@ function BaseTextInputWithCurrencySymbol(
<CurrencySymbolButton
currencySymbol={currencySymbol ?? ''}
onCurrencyButtonPress={onCurrencyButtonPress}
isCurrencyPressable={isCurrencyPressable}
/>
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ const propTypes = {

/** Function to call to handle key presses in the text input */
onKeyPress: PropTypes.func,

/** Whether the currency symbol is pressable */
isCurrencyPressable: PropTypes.bool,
};

const defaultProps = {
Expand All @@ -40,6 +43,7 @@ const defaultProps = {
selection: undefined,
onSelectionChange: () => {},
onKeyPress: () => {},
isCurrencyPressable: true,
};

export {propTypes, defaultProps};
3 changes: 3 additions & 0 deletions src/components/TextInputWithCurrencySymbol/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ type TextInputWithCurrencySymbolProps = {

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

/** Whether the currency symbol is pressable */
isCurrencyPressable: boolean;
};

export default TextInputWithCurrencySymbolProps;
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ function WorkspaceRatePage(props: WorkspaceRatePageProps) {
defaultValue={(
(typeof props.workspaceRateAndUnit?.rate === 'string' ? parseFloat(props.workspaceRateAndUnit.rate) : defaultValue) / CONST.POLICY.CUSTOM_UNIT_RATE_BASE_OFFSET
).toFixed(3)}
isCurrencyPressable={false}
/>
</FormProvider>
)}
Expand Down

0 comments on commit af1026e

Please sign in to comment.