Permalink
Browse files

Fix padding with Text on Android

Summary: Text was not correctly respecting padding.  We would account for it when measuring, but then not actually apply the padding to the text.  This adds support for proper padding

Reviewed By: andreicoman11

Differential Revision: D3516692

fbshipit-source-id: 9a0991d89e9194c0e87af0af56c6631a6b95700a
  • Loading branch information...
1 parent 0fde81c commit c3f2bba834a5ffcc42352bb738132baceafce76d @dmmiller dmmiller committed with Facebook Github Bot 9 Jul 6, 2016
@@ -530,7 +530,7 @@ public void onCollectExtraUpdates(UIViewOperationQueue uiViewOperationQueue) {
super.onCollectExtraUpdates(uiViewOperationQueue);
if (mPreparedSpannableText != null) {
ReactTextUpdate reactTextUpdate =
- new ReactTextUpdate(mPreparedSpannableText, UNSET, mContainsImages);
+ new ReactTextUpdate(mPreparedSpannableText, UNSET, mContainsImages, getPadding());
uiViewOperationQueue.enqueueUpdateExtraData(getReactTag(), reactTextUpdate);
}
}
@@ -11,6 +11,8 @@
import android.text.Spannable;
+import com.facebook.csslayout.Spacing;
+
/**
* Class that contains the data needed for a text update.
* Used by both <Text/> and <TextInput/>
@@ -21,11 +23,17 @@
private final Spannable mText;
private final int mJsEventCounter;
private final boolean mContainsImages;
+ private final Spacing mPadding;
- public ReactTextUpdate(Spannable text, int jsEventCounter, boolean containsImages) {
+ public ReactTextUpdate(
+ Spannable text,
+ int jsEventCounter,
+ boolean containsImages,
+ Spacing padding) {
mText = text;
mJsEventCounter = jsEventCounter;
mContainsImages = containsImages;
+ mPadding = padding;
}
public Spannable getText() {
@@ -39,4 +47,8 @@ public int getJsEventCounter() {
public boolean containsImages() {
return mContainsImages;
}
+
+ public Spacing getPadding() {
+ return mPadding;
+ }
}
@@ -17,6 +17,7 @@
import android.view.ViewGroup;
import android.widget.TextView;
+import com.facebook.csslayout.Spacing;
import com.facebook.react.uimanager.ReactCompoundView;
public class ReactTextView extends TextView implements ReactCompoundView {
@@ -45,6 +46,12 @@ public void setText(ReactTextUpdate update) {
setLayoutParams(EMPTY_LAYOUT_PARAMS);
}
setText(update.getText());
+ Spacing padding = update.getPadding();
+ setPadding(
+ (int) Math.ceil(padding.get(Spacing.LEFT)),
+ (int) Math.ceil(padding.get(Spacing.TOP)),
+ (int) Math.ceil(padding.get(Spacing.RIGHT)),
+ (int) Math.ceil(padding.get(Spacing.BOTTOM)));
}
@Override
@@ -119,7 +119,7 @@ public void onCollectExtraUpdates(UIViewOperationQueue uiViewOperationQueue) {
if (mJsEventCount != UNSET) {
Spannable preparedSpannableText = fromTextCSSNode(this);
ReactTextUpdate reactTextUpdate =
- new ReactTextUpdate(preparedSpannableText, mJsEventCount, mContainsImages);
+ new ReactTextUpdate(preparedSpannableText, mJsEventCount, mContainsImages, getPadding());
uiViewOperationQueue.enqueueUpdateExtraData(getReactTag(), reactTextUpdate);
}
}

5 comments on commit c3f2bba

@tomauty
Contributor

:)

@silentcloud

👍

@antoinerousseau
Contributor
antoinerousseau commented on c3f2bba Aug 5, 2016 edited

woohoo that fixes my bug 👍

EDIT: it doesn't :/

@Pein892

good job!

@coderwin

good

Please sign in to comment.