Skip to content

Commit

Permalink
Fix incorrect measurement of TextInput (#42655)
Browse files Browse the repository at this point in the history
Summary:
Pull Request resolved: #42655

This bug is caused by a caching issue: when the user enters a new character into the textInput: ReactTextInput 1) caches the Spannable entered by the user and 2) it updates internal Fabric state, which triggers the measurement of the TextInput component using the cached Spannable.

The problem is that the Spannable entered by the user has the wrong "styles" for the text input. Since measurement is using the cached Spannable, then the measurement of the TextInput ends up being is incorrect.

In this diff I'm fixing the bug by updating the styles (lineHeight) of the cached spannable that is cached when the user updates the TextInput.
The styles weren't updated correctly because mTextAttributes didn't have the proper style props set

Changelog:
    [Android][Fixed] - Fix incorrect measurement of TextInput when new architecture is enabled

Reviewed By: javache, sammy-SC

Differential Revision: D52924982

fbshipit-source-id: ced9f2c348bdb9bf706028b1063858cebd5a071a
  • Loading branch information
mdvacca authored and facebook-github-bot committed Jan 25, 2024
1 parent 97d6d72 commit dc2ce9e
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 0 deletions.
2 changes: 2 additions & 0 deletions packages/react-native/ReactAndroid/api/ReactAndroid.api
Original file line number Diff line number Diff line change
Expand Up @@ -7381,6 +7381,7 @@ public class com/facebook/react/views/textinput/ReactEditText : androidx/appcomp
public fun setFontWeight (Ljava/lang/String;)V
public fun setInputType (I)V
public fun setLetterSpacingPt (F)V
public fun setLineHeight (I)V
public fun setMaxFontSizeMultiplier (F)V
public fun setOnKeyPress (Z)V
public fun setPlaceholder (Ljava/lang/String;)V
Expand Down Expand Up @@ -7468,6 +7469,7 @@ public class com/facebook/react/views/textinput/ReactTextInputManager : com/face
public fun setInlineImagePadding (Lcom/facebook/react/views/textinput/ReactEditText;I)V
public fun setKeyboardType (Lcom/facebook/react/views/textinput/ReactEditText;Ljava/lang/String;)V
public fun setLetterSpacing (Lcom/facebook/react/views/textinput/ReactEditText;F)V
public fun setLineHeight (Lcom/facebook/react/views/textinput/ReactEditText;I)V
public fun setMaxFontSizeMultiplier (Lcom/facebook/react/views/textinput/ReactEditText;F)V
public fun setMaxLength (Lcom/facebook/react/views/textinput/ReactEditText;Ljava/lang/Integer;)V
public fun setMultiline (Lcom/facebook/react/views/textinput/ReactEditText;Z)V
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,12 @@ public boolean onKeyUp(int keyCode, KeyEvent event) {
return super.onKeyUp(keyCode, event);
}

@Override
public void setLineHeight(int lineHeight) {
mTextAttributes.setLineHeight(lineHeight);
super.setLineHeight(lineHeight);
}

@Override
protected void onScrollChanged(int horiz, int vert, int oldHoriz, int oldVert) {
super.onScrollChanged(horiz, vert, oldHoriz, oldVert);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,11 @@ public void updateExtraData(ReactEditText view, Object extraData) {
}
}

@ReactProp(name = ViewProps.LINE_HEIGHT, defaultFloat = ViewDefaults.LINE_HEIGHT)
public void setLineHeight(ReactEditText view, int lineHeight) {
view.setLineHeight(lineHeight);
}

@ReactProp(name = ViewProps.FONT_SIZE, defaultFloat = ViewDefaults.FONT_SIZE_SP)
public void setFontSize(ReactEditText view, float fontSize) {
view.setFontSize(fontSize);
Expand Down

0 comments on commit dc2ce9e

Please sign in to comment.