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

IOU - digit appears cutoff for a moment when entering a digit before decimal point #18579

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
19 changes: 16 additions & 3 deletions src/components/TextInput/BaseTextInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,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;
Expand Down Expand Up @@ -72,13 +73,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) {
if (inputValue !== this.state.hiddenInputValue) {
this.setState({hiddenInputValue: inputValue, selection: this.props.selection});
}

if (prevState.textInputWidth === this.state.textInputWidth && this.props.shouldWaitWidthCalculation) {
return;
narefyev91 marked this conversation as resolved.
Show resolved Hide resolved
}
}

// eslint-disable-next-line react/no-did-update-set-state
this.setState({value: inputValue, selection: this.props.selection});

Expand Down Expand Up @@ -148,7 +159,9 @@ class BaseTextInput extends Component {
if (this.props.onInputChange) {
this.props.onInputChange(value);
}
this.setState({value});
if (!this.props.autoGrow) {
this.setState({value});
}
Str.result(this.props.onChangeText, value);
this.activateLabel();
}
Expand Down Expand Up @@ -380,7 +393,7 @@ class BaseTextInput extends Component {
style={[...this.props.inputStyle, this.props.autoGrowHeight ? {maxWidth: this.state.width} : {}, styles.hiddenElementOutsideOfWindow, styles.visibilityHidden]}
onLayout={e => this.setState({textInputWidth: e.nativeEvent.layout.width + 2, textInputHeight: e.nativeEvent.layout.height})}
>
{this.state.value || this.props.placeholder}
{this.props.autoGrowHeight ? this.state.value : this.state.hiddenInputValue || this.props.placeholder}
</Text>
)}
</>
Expand Down
4 changes: 4 additions & 0 deletions src/components/TextInput/baseTextInputPropTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,9 @@ const propTypes = {

/** Set the default value to the input if there is a valid saved value */
shouldUseDefaultValue: PropTypes.bool,

/** Indicate whether input should wait until getting calculated width based on value */
shouldWaitWidthCalculation: PropTypes.bool,
};

const defaultProps = {
Expand Down Expand Up @@ -124,6 +127,7 @@ const defaultProps = {
icon: null,
shouldUseDefaultValue: false,
multiline: false,
shouldWaitWidthCalculation: false,
};

export {propTypes, defaultProps};
1 change: 1 addition & 0 deletions src/components/TextInput/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class TextInput extends React.Component {
<BaseTextInput
// eslint-disable-next-line react/jsx-props-no-spreading
{...this.props}
shouldWaitWidthCalculation
innerRef={(el) => {
this.textInput = el;
if (!this.props.innerRef) {
Expand Down