-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
Changed the Amount Text to TextInput #6811
Changes from all commits
9e9a7e8
e6d95aa
e538737
6ce2af4
0316560
5be1b9a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,8 @@ import { | |
View, | ||
TouchableOpacity, | ||
InteractionManager, | ||
AppState, | ||
Keyboard, | ||
} from 'react-native'; | ||
import PropTypes from 'prop-types'; | ||
import {withOnyx} from 'react-native-onyx'; | ||
|
@@ -77,6 +79,7 @@ class IOUAmountPage extends React.Component { | |
this.updateAmount = this.updateAmount.bind(this); | ||
this.stripCommaFromAmount = this.stripCommaFromAmount.bind(this); | ||
this.focusTextInput = this.focusTextInput.bind(this); | ||
this.dismissKeyboardWhenBackgrounded = this.dismissKeyboardWhenBackgrounded.bind(this); | ||
|
||
this.state = { | ||
amount: props.selectedAmount, | ||
|
@@ -85,6 +88,10 @@ class IOUAmountPage extends React.Component { | |
|
||
componentDidMount() { | ||
this.focusTextInput(); | ||
this.unsubscribeAppStateSubscription = AppState.addEventListener( | ||
'change', | ||
this.dismissKeyboardWhenBackgrounded, | ||
); | ||
} | ||
|
||
componentDidUpdate(prevProps) { | ||
|
@@ -95,6 +102,20 @@ class IOUAmountPage extends React.Component { | |
this.focusTextInput(); | ||
} | ||
|
||
componentWillUnmount() { | ||
if (!this.unsubscribeAppStateSubscription) { | ||
return; | ||
} | ||
this.unsubscribeAppStateSubscription(); | ||
} | ||
|
||
dismissKeyboardWhenBackgrounded(nextAppState) { | ||
if (!nextAppState.match(/inactive|background/)) { | ||
return; | ||
} | ||
Keyboard.dismiss(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👋 Coming from #26505
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I love that. Thank you for moving it to a platform-specific file! |
||
} | ||
|
||
/** | ||
* Focus text input | ||
*/ | ||
|
@@ -188,24 +209,17 @@ class IOUAmountPage extends React.Component { | |
{lodashGet(this.props.currencyList, [this.props.iou.selectedCurrencyCode, 'symbol'])} | ||
</Text> | ||
</TouchableOpacity> | ||
{this.props.isSmallScreenWidth | ||
? ( | ||
<Text | ||
style={styles.iouAmountText} | ||
> | ||
{this.state.amount} | ||
</Text> | ||
) : ( | ||
<TextInputAutoWidth | ||
inputStyle={styles.iouAmountTextInput} | ||
textStyle={styles.iouAmountText} | ||
onChangeText={this.updateAmount} | ||
ref={el => this.textInput = el} | ||
value={this.state.amount} | ||
placeholder="0" | ||
keyboardType={CONST.KEYBOARD_TYPE.NUMERIC} | ||
/> | ||
)} | ||
<TextInputAutoWidth | ||
inputStyle={styles.iouAmountTextInput} | ||
textStyle={styles.iouAmountText} | ||
onChangeText={this.updateAmount} | ||
ref={el => this.textInput = el} | ||
value={this.state.amount} | ||
placeholder="0" | ||
keyboardType={CONST.KEYBOARD_TYPE.NUMERIC} | ||
showSoftInputOnFocus={false} | ||
inputmode="none" | ||
/> | ||
</View> | ||
<View style={[styles.w100, styles.justifyContentEnd]}> | ||
{this.props.isSmallScreenWidth | ||
|
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.
This function does not return a method to unsubscribe...
https://reactnative.dev/docs/appstate#addeventlistener
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.
this.unsubscribeAppStateSubscription.remove()
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 yes, good catch. I am seeing some console errors for this. @akshayasalvi can you please fix this?
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.
Hi,
Okay sure. I'll do that.
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.
No worries, we've fixed it already. This was taken care of in #6909
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.
Thanks for the help