Skip to content

Commit

Permalink
Rebase on top of text inheritance changes
Browse files Browse the repository at this point in the history
  • Loading branch information
janicduplessis committed Jan 19, 2019
1 parent c70df42 commit ca640db
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@
import com.facebook.react.uimanager.ViewProps;
import com.facebook.react.uimanager.annotations.ReactProp;
import com.facebook.yoga.YogaDirection;

import org.w3c.dom.Text;

import java.util.ArrayList;
import java.util.List;
import javax.annotation.Nullable;
Expand Down Expand Up @@ -94,7 +97,10 @@ private static void buildSpannedFromShadowNode(
ReactShadowNode child = textShadowNode.getChildAt(i);

if (child instanceof ReactRawTextShadowNode) {
sb.append(((ReactRawTextShadowNode) child).getText());
sb.append(
TextTransform.apply(
((ReactRawTextShadowNode) child).getText(),
textAttributes.getTextTransform()));
} else if (child instanceof ReactBaseTextShadowNode) {
buildSpannedFromShadowNode((ReactBaseTextShadowNode) child, sb, ops, textAttributes, sb.length());
} else if (child instanceof ReactTextInlineImageShadowNode) {
Expand Down Expand Up @@ -182,13 +188,6 @@ private static void buildSpannedFromShadowNode(
new SetSpanOperation(
start, end, new CustomLineHeightSpan(effectiveLineHeight)));
}
if (textShadowNode.mTextTransform != TextTransform.UNSET) {
ops.add(
new SetSpanOperation(
start,
end,
new CustomTextTransformSpan(textShadowNode.mTextTransform)));
}
ops.add(new SetSpanOperation(start, end, new ReactTagSpan(textShadowNode.getReactTag())));
}
}
Expand All @@ -207,7 +206,7 @@ protected static Spannable spannedFromShadowNode(
if (text != null) {
// Handle text that is provided via a prop (e.g. the `value` and `defaultValue` props on
// TextInput).
sb.append(text);
sb.append(TextTransform.apply(text, textShadowNode.mTextAttributes.getTextTransform()));
}

buildSpannedFromShadowNode(textShadowNode, sb, ops, null, 0);
Expand Down Expand Up @@ -266,7 +265,6 @@ private static int parseNumericFontWeight(String fontWeightString) {
protected int mTextAlign = Gravity.NO_GRAVITY;
protected int mTextBreakStrategy =
(Build.VERSION.SDK_INT < Build.VERSION_CODES.M) ? 0 : Layout.BREAK_STRATEGY_HIGH_QUALITY;
protected TextTransform mTextTransform = TextTransform.UNSET;

protected float mTextShadowOffsetDx = 0;
protected float mTextShadowOffsetDy = 0;
Expand Down Expand Up @@ -520,14 +518,16 @@ public void setTextShadowColor(int textShadowColor) {

@ReactProp(name = PROP_TEXT_TRANSFORM)
public void setTextTransform(@Nullable String textTransform) {
if (textTransform == null || "none".equals(textTransform)) {
mTextTransform = TextTransform.NONE;
if (textTransform == null) {
mTextAttributes.setTextTransform(TextTransform.UNSET);
} else if ("none".equals(textTransform)) {
mTextAttributes.setTextTransform(TextTransform.NONE);
} else if ("uppercase".equals(textTransform)) {
mTextTransform = TextTransform.UPPERCASE;
mTextAttributes.setTextTransform(TextTransform.UPPERCASE);
} else if ("lowercase".equals(textTransform)) {
mTextTransform = TextTransform.LOWERCASE;
mTextAttributes.setTextTransform(TextTransform.LOWERCASE);
} else if ("capitalize".equals(textTransform)) {
mTextTransform = TextTransform.CAPITALIZE;
mTextAttributes.setTextTransform(TextTransform.CAPITALIZE);
} else {
throw new JSApplicationIllegalArgumentException("Invalid textTransform: " + textTransform);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public class TextAttributes {
private float mLineHeight = Float.NaN;
private float mLetterSpacing = Float.NaN;
private float mHeightOfTallestInlineImage = Float.NaN;
private TextTransform mTextTransform = TextTransform.UNSET;

public TextAttributes() {
}
Expand All @@ -38,6 +39,7 @@ public TextAttributes applyChild(TextAttributes child) {
result.mLineHeight = !Float.isNaN(child.mLineHeight) ? child.mLineHeight : mLineHeight;
result.mLetterSpacing = !Float.isNaN(child.mLetterSpacing) ? child.mLetterSpacing : mLetterSpacing;
result.mHeightOfTallestInlineImage = !Float.isNaN(child.mHeightOfTallestInlineImage) ? child.mHeightOfTallestInlineImage : mHeightOfTallestInlineImage;
result.mTextTransform = child.mTextTransform != TextTransform.UNSET ? child.mTextTransform : mTextTransform;

return result;
}
Expand Down Expand Up @@ -85,6 +87,14 @@ public void setHeightOfTallestInlineImage(float value) {
mHeightOfTallestInlineImage = value;
}

public TextTransform getTextTransform() {
return mTextTransform;
}

public void setTextTransform(TextTransform textTransform) {
mTextTransform = textTransform;
}

// Getters for effective values
//
// In general, these return `Float.NaN` if the property doesn't have a value.
Expand Down Expand Up @@ -140,6 +150,7 @@ public String toString() {
+ "\n getEffectiveLetterSpacing(): " + getEffectiveLetterSpacing()
+ "\n getLineHeight(): " + getLineHeight()
+ "\n getEffectiveLineHeight(): " + getEffectiveLineHeight()
+ "\n getTextTransform(): " + getTextTransform()
+ "\n}"
);
}
Expand Down

0 comments on commit ca640db

Please sign in to comment.