mirror of
https://github.com/status-im/react-native.git
synced 2025-02-27 00:20:31 +00:00
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
This commit is contained in:
parent
0fde81c816
commit
c3f2bba834
@ -530,7 +530,7 @@ public class ReactTextShadowNode extends LayoutShadowNode {
|
||||
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 @@ package com.facebook.react.views.text;
|
||||
|
||||
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 @@ public class ReactTextUpdate {
|
||||
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 class ReactTextUpdate {
|
||||
public boolean containsImages() {
|
||||
return mContainsImages;
|
||||
}
|
||||
|
||||
public Spacing getPadding() {
|
||||
return mPadding;
|
||||
}
|
||||
}
|
||||
|
@ -17,6 +17,7 @@ import android.view.Gravity;
|
||||
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 class ReactTextView extends TextView implements ReactCompoundView {
|
||||
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 class ReactTextInputShadowNode extends ReactTextShadowNode implements
|
||||
if (mJsEventCount != UNSET) {
|
||||
Spannable preparedSpannableText = fromTextCSSNode(this);
|
||||
ReactTextUpdate reactTextUpdate =
|
||||
new ReactTextUpdate(preparedSpannableText, mJsEventCount, mContainsImages);
|
||||
new ReactTextUpdate(preparedSpannableText, mJsEventCount, mContainsImages, getPadding());
|
||||
uiViewOperationQueue.enqueueUpdateExtraData(getReactTag(), reactTextUpdate);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user