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

Fixed currency pressable ui and padding issues #36497

Merged
merged 4 commits into from
Feb 14, 2024
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
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
Loading