Skip to content

Commit

Permalink
Fix TextInput contentSize
Browse files Browse the repository at this point in the history
Summary:
This fixes some inaccuracies in our reporting of textinput's contentsize.
First, we were not using the correct padding info. Then, we are converting the
contentSize width and height to ints right before sending
them over to JS. This adds some inaccuracy with the textinput behaviour,
especially in the case of auto expending text inputs, since those same sizes are
then sent right back.

Reviewed By: astreet

Differential Revision: D3806008

fbshipit-source-id: 7e32f91fde50099fd8a122833fd0042683e68df1
  • Loading branch information
andreicoman11 authored and Facebook Github Bot 9 committed Sep 6, 2016
1 parent 0d9490f commit 7c268b3
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 13 deletions.
Expand Up @@ -21,13 +21,13 @@ public class ReactContentSizeChangedEvent extends Event<ReactTextChangedEvent> {

public static final String EVENT_NAME = "topContentSizeChange";

private int mContentWidth;
private int mContentHeight;
private float mContentWidth;
private float mContentHeight;

public ReactContentSizeChangedEvent(
int viewId,
int contentSizeWidth,
int contentSizeHeight) {
float contentSizeWidth,
float contentSizeHeight) {
super(viewId);
mContentWidth = contentSizeWidth;
mContentHeight = contentSizeHeight;
Expand Down
Expand Up @@ -23,15 +23,15 @@ public class ReactTextChangedEvent extends Event<ReactTextChangedEvent> {
public static final String EVENT_NAME = "topChange";

private String mText;
private int mContentWidth;
private int mContentHeight;
private float mContentWidth;
private float mContentHeight;
private int mEventCount;

public ReactTextChangedEvent(
int viewId,
String text,
int contentSizeWidth,
int contentSizeHeight,
float contentSizeWidth,
float contentSizeHeight,
int eventCount) {
super(viewId);
mText = text;
Expand Down
Expand Up @@ -590,8 +590,8 @@ public void onTextChanged(CharSequence s, int start, int before, int count) {
new ReactTextChangedEvent(
mEditText.getId(),
s.toString(),
(int) PixelUtil.toDIPFromPixel(contentWidth),
(int) PixelUtil.toDIPFromPixel(contentHeight),
PixelUtil.toDIPFromPixel(contentWidth),
PixelUtil.toDIPFromPixel(contentHeight),
mEditText.incrementAndGetEventCounter()));

mEventDispatcher.dispatchEvent(
Expand Down Expand Up @@ -683,7 +683,7 @@ public void onLayout() {
contentWidth = mEditText.getCompoundPaddingLeft() + mEditText.getLayout().getWidth() +
mEditText.getCompoundPaddingRight();
contentHeight = mEditText.getCompoundPaddingTop() + mEditText.getLayout().getHeight() +
mEditText.getCompoundPaddingTop();
mEditText.getCompoundPaddingBottom();
}

if (contentWidth != mPreviousContentWidth || contentHeight != mPreviousContentHeight) {
Expand All @@ -693,8 +693,8 @@ public void onLayout() {
mEventDispatcher.dispatchEvent(
new ReactContentSizeChangedEvent(
mEditText.getId(),
(int) PixelUtil.toDIPFromPixel(contentWidth),
(int) PixelUtil.toDIPFromPixel(contentHeight)));
PixelUtil.toDIPFromPixel(contentWidth),
PixelUtil.toDIPFromPixel(contentHeight)));
}
}
}
Expand Down

0 comments on commit 7c268b3

Please sign in to comment.