-
Notifications
You must be signed in to change notification settings - Fork 3.2k
IOU - digit appears cutoff for a moment when entering a digit before decimal point #18579
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
Changes from all commits
9fad803
3c4a37a
ae5eaad
e4c70a3
f40d168
710d9da
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 |
---|---|---|
|
@@ -37,6 +37,7 @@ class BaseTextInput extends Component { | |
|
||
// Value should be kept in state for the autoGrow feature to work - https://github.com/Expensify/App/pull/8232#issuecomment-1077282006 | ||
value, | ||
hiddenInputValue: value, | ||
}; | ||
|
||
this.input = null; | ||
|
@@ -67,13 +68,23 @@ class BaseTextInput extends Component { | |
this.input.focus(); | ||
} | ||
|
||
componentDidUpdate(prevProps) { | ||
componentDidUpdate(prevProps, prevState) { | ||
// Activate or deactivate the label when value is changed programmatically from outside | ||
const inputValue = _.isUndefined(this.props.value) ? this.input.value : this.props.value; | ||
if ((_.isUndefined(inputValue) || this.state.value === inputValue) && _.isEqual(prevProps.selection, this.props.selection)) { | ||
return; | ||
} | ||
|
||
if (this.props.autoGrow && this.props.shouldWaitWidthCalculation) { | ||
if (inputValue !== this.state.hiddenInputValue) { | ||
this.setState({hiddenInputValue: inputValue, selection: this.props.selection}); | ||
} | ||
|
||
if (prevState.textInputWidth === this.state.textInputWidth) { | ||
return; | ||
} | ||
} | ||
|
||
// eslint-disable-next-line react/no-did-update-set-state | ||
this.setState({value: inputValue, selection: this.props.selection}); | ||
|
||
|
@@ -147,7 +158,9 @@ class BaseTextInput extends Component { | |
if (this.props.onInputChange) { | ||
this.props.onInputChange(value); | ||
} | ||
this.setState({value}); | ||
if (!this.props.autoGrow || !this.props.shouldWaitWidthCalculation) { | ||
this.setState({value}); | ||
} | ||
Comment on lines
+161
to
+163
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 have been playing around with this PR to try to avoid this bug, and I'm pretty sure that this is the change causing it. When the input is full and you type a new digit, With this change, we don't set the longer than permitted value in the state immediately as we used to, and we end up rendering the input with an old I don't understand fully the problem, but I think it is related to this. 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. @aldo-expensify yes you are right that we set state immediately without waiting width calculation - this is the issue we currently have - and to avoid this we should not use state variable for input until width will be calculated 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. @aldo-expensify And also to be clear about render logic:
But we still in re-render process - because MoneyRequestAmountPage page force re-render by doing setState.
And e.nativeEvent.selection will be last position of the element in input |
||
Str.result(this.props.onChangeText, value); | ||
this.activateLabel(); | ||
} | ||
|
@@ -222,6 +235,8 @@ class BaseTextInput extends Component { | |
{}, | ||
); | ||
const isMultiline = this.props.multiline || this.props.autoGrowHeight; | ||
const inputValue = this.state.value || this.props.placeholder; | ||
const hiddenInputValue = this.state.hiddenInputValue || this.props.placeholder; | ||
|
||
return ( | ||
<> | ||
|
@@ -386,9 +401,14 @@ class BaseTextInput extends Component { | |
styles.hiddenElementOutsideOfWindow, | ||
styles.visibilityHidden, | ||
]} | ||
onLayout={(e) => this.setState({textInputWidth: e.nativeEvent.layout.width + 2, textInputHeight: e.nativeEvent.layout.height})} | ||
onLayout={(e) => | ||
this.setState({textInputWidth: e.nativeEvent.layout.width + 2, textInputHeight: e.nativeEvent.layout.height}, () => { | ||
if (!this.props.shouldWaitWidthCalculation) return; | ||
this.setState((prevState) => ({value: prevState.hiddenInputValue, selection: this.props.selection})); | ||
}) | ||
} | ||
> | ||
{this.state.value || this.props.placeholder} | ||
{this.props.autoGrowHeight || !this.props.shouldWaitWidthCalculation ? inputValue : hiddenInputValue} | ||
</Text> | ||
)} | ||
</> | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ import _ from 'underscore'; | |
import styles from '../../styles/styles'; | ||
import BaseTextInput from './BaseTextInput'; | ||
import * as baseTextInputPropTypes from './baseTextInputPropTypes'; | ||
import * as BrowserUtils from '../../libs/Browser'; | ||
|
||
class TextInput extends React.Component { | ||
componentDidMount() { | ||
|
@@ -22,6 +23,7 @@ class TextInput extends React.Component { | |
<BaseTextInput | ||
// eslint-disable-next-line react/jsx-props-no-spreading | ||
{...this.props} | ||
shouldWaitWidthCalculation={BrowserUtils.isMobile()} | ||
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. As @parasharrajat posted, I agree it would be good to investigate this further before just disabling it for desktop. If we don't understand the cause, we may be creating a bug. |
||
innerRef={(el) => { | ||
this.textInput = el; | ||
if (!this.props.innerRef) { | ||
|
Uh oh!
There was an error while loading. Please reload this page.