-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
🍒 Cherry pick PR #36497 to staging 🍒 #36549
Closed
Closed
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
83 changes: 83 additions & 0 deletions
83
src/components/TextInputWithCurrencySymbol/BaseTextInputWithCurrencySymbol.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
import React from 'react'; | ||
import type {NativeSyntheticEvent, TextInputSelectionChangeEventData} from 'react-native'; | ||
import AmountTextInput from '@components/AmountTextInput'; | ||
import CurrencySymbolButton from '@components/CurrencySymbolButton'; | ||
import useLocalize from '@hooks/useLocalize'; | ||
import useThemeStyles from '@hooks/useThemeStyles'; | ||
import * as CurrencyUtils from '@libs/CurrencyUtils'; | ||
import * as MoneyRequestUtils from '@libs/MoneyRequestUtils'; | ||
import type {BaseTextInputRef} from '@src/components/TextInput/BaseTextInput/types'; | ||
import type TextInputWithCurrencySymbolProps from './types'; | ||
|
||
function BaseTextInputWithCurrencySymbol( | ||
{ | ||
selectedCurrencyCode, | ||
onCurrencyButtonPress = () => {}, | ||
onChangeAmount = () => {}, | ||
formattedAmount, | ||
placeholder, | ||
selection, | ||
onSelectionChange = () => {}, | ||
onKeyPress = () => {}, | ||
isCurrencyPressable = true, | ||
}: TextInputWithCurrencySymbolProps, | ||
ref: React.ForwardedRef<BaseTextInputRef>, | ||
) { | ||
const {fromLocaleDigit} = useLocalize(); | ||
const currencySymbol = CurrencyUtils.getLocalizedCurrencySymbol(selectedCurrencyCode); | ||
const isCurrencySymbolLTR = CurrencyUtils.isCurrencySymbolLTR(selectedCurrencyCode); | ||
const styles = useThemeStyles(); | ||
|
||
const currencySymbolButton = ( | ||
<CurrencySymbolButton | ||
currencySymbol={currencySymbol ?? ''} | ||
onCurrencyButtonPress={onCurrencyButtonPress} | ||
isCurrencyPressable={isCurrencyPressable} | ||
/> | ||
); | ||
|
||
/** | ||
* Set a new amount value properly formatted | ||
* | ||
* @param text - Changed text from user input | ||
*/ | ||
const setFormattedAmount = (text: string) => { | ||
const newAmount = MoneyRequestUtils.addLeadingZero(MoneyRequestUtils.replaceAllDigits(text, fromLocaleDigit)); | ||
onChangeAmount(newAmount); | ||
}; | ||
|
||
const amountTextInput = ( | ||
<AmountTextInput | ||
formattedAmount={formattedAmount} | ||
onChangeAmount={setFormattedAmount} | ||
placeholder={placeholder} | ||
ref={ref} | ||
selection={selection} | ||
onSelectionChange={(event: NativeSyntheticEvent<TextInputSelectionChangeEventData>) => { | ||
onSelectionChange(event); | ||
}} | ||
onKeyPress={onKeyPress} | ||
style={styles.pr1} | ||
/> | ||
); | ||
|
||
if (isCurrencySymbolLTR) { | ||
return ( | ||
<> | ||
{currencySymbolButton} | ||
{amountTextInput} | ||
</> | ||
); | ||
} | ||
|
||
return ( | ||
<> | ||
{amountTextInput} | ||
{currencySymbolButton} | ||
</> | ||
); | ||
} | ||
|
||
BaseTextInputWithCurrencySymbol.displayName = 'BaseTextInputWithCurrencySymbol'; | ||
|
||
export default React.forwardRef(BaseTextInputWithCurrencySymbol); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import type {NativeSyntheticEvent, TextInputSelectionChangeEventData} from 'react-native'; | ||
import type {TextSelection} from '@components/Composer/types'; | ||
|
||
type TextInputWithCurrencySymbolProps = { | ||
/** Formatted amount in local currency */ | ||
formattedAmount: string; | ||
|
||
/** Function to call when amount in text input is changed */ | ||
onChangeAmount?: (value: string) => void; | ||
|
||
/** Function to call when currency button is pressed */ | ||
onCurrencyButtonPress?: () => void; | ||
|
||
/** Placeholder value for amount text input */ | ||
placeholder: string; | ||
|
||
/** Currency code of user's selected currency */ | ||
selectedCurrencyCode: string; | ||
|
||
/** Selection Object */ | ||
selection?: TextSelection; | ||
|
||
/** Function to call when selection in text input is changed */ | ||
onSelectionChange?: (event: NativeSyntheticEvent<TextInputSelectionChangeEventData>) => void; | ||
|
||
/** 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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think to solve it you'd just need to copy over the
isCurrencyPressable = true
param to line 54, but def understand if you don't wanna worry about it and just make the issues NABsThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That is one thing, but also BaseTextInputRef doesn't exist here yet and then I found a couple other files with missing imports so I didn't want to risk it since I'm not sure what is not on staging yet. I'd have to correct all of those files :yikes:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah okay yeah fair enough! :nevermind: