Convert basic shadow nodes to use @ReactProp.
Differential Revision: D2537318 fb-gh-sync-id: 3061545f27953299904fe224e973fa409650d239
This commit is contained in:
parent
08e79deebd
commit
f4e2a670d3
|
@ -21,9 +21,8 @@ import android.widget.ProgressBar;
|
||||||
|
|
||||||
import com.facebook.csslayout.CSSNode;
|
import com.facebook.csslayout.CSSNode;
|
||||||
import com.facebook.csslayout.MeasureOutput;
|
import com.facebook.csslayout.MeasureOutput;
|
||||||
import com.facebook.react.uimanager.CatalystStylesDiffMap;
|
import com.facebook.react.uimanager.ReactProp;
|
||||||
import com.facebook.react.uimanager.ReactShadowNode;
|
import com.facebook.react.uimanager.ReactShadowNode;
|
||||||
import com.facebook.infer.annotation.Assertions;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Node responsible for holding the style of the ProgressBar, see under
|
* Node responsible for holding the style of the ProgressBar, see under
|
||||||
|
@ -32,7 +31,7 @@ import com.facebook.infer.annotation.Assertions;
|
||||||
*/
|
*/
|
||||||
public class ProgressBarShadowNode extends ReactShadowNode implements CSSNode.MeasureFunction {
|
public class ProgressBarShadowNode extends ReactShadowNode implements CSSNode.MeasureFunction {
|
||||||
|
|
||||||
private @Nullable String style;
|
private String mStyle = ReactProgressBarViewManager.DEFAULT_STYLE;
|
||||||
|
|
||||||
private final SparseIntArray mHeight = new SparseIntArray();
|
private final SparseIntArray mHeight = new SparseIntArray();
|
||||||
private final SparseIntArray mWidth = new SparseIntArray();
|
private final SparseIntArray mWidth = new SparseIntArray();
|
||||||
|
@ -43,11 +42,12 @@ public class ProgressBarShadowNode extends ReactShadowNode implements CSSNode.Me
|
||||||
}
|
}
|
||||||
|
|
||||||
public @Nullable String getStyle() {
|
public @Nullable String getStyle() {
|
||||||
return style;
|
return mStyle;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setStyle(String style) {
|
@ReactProp(name = ReactProgressBarViewManager.PROP_STYLE)
|
||||||
this.style = style;
|
public void setStyle(@Nullable String style) {
|
||||||
|
mStyle = style == null ? ReactProgressBarViewManager.DEFAULT_STYLE : style;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -67,20 +67,4 @@ public class ProgressBarShadowNode extends ReactShadowNode implements CSSNode.Me
|
||||||
measureOutput.height = mHeight.get(style);
|
measureOutput.height = mHeight.get(style);
|
||||||
measureOutput.width = mWidth.get(style);
|
measureOutput.width = mWidth.get(style);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void updateShadowNode(CatalystStylesDiffMap styles) {
|
|
||||||
super.updateShadowNode(styles);
|
|
||||||
|
|
||||||
if (styles.hasKey(ReactProgressBarViewManager.PROP_STYLE)) {
|
|
||||||
String style = styles.getString(ReactProgressBarViewManager.PROP_STYLE);
|
|
||||||
Assertions.assertNotNull(
|
|
||||||
style,
|
|
||||||
"style property should always be set for the progress bar component");
|
|
||||||
// TODO(7255944): Validate progressbar style attribute
|
|
||||||
setStyle(style);
|
|
||||||
} else {
|
|
||||||
setStyle(ReactProgressBarViewManager.DEFAULT_STYLE);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,8 +9,8 @@
|
||||||
|
|
||||||
package com.facebook.react.views.text;
|
package com.facebook.react.views.text;
|
||||||
|
|
||||||
import com.facebook.react.uimanager.CatalystStylesDiffMap;
|
|
||||||
import com.facebook.react.common.annotations.VisibleForTesting;
|
import com.facebook.react.common.annotations.VisibleForTesting;
|
||||||
|
import com.facebook.react.uimanager.CatalystStylesDiffMap;
|
||||||
import com.facebook.react.uimanager.ThemedReactContext;
|
import com.facebook.react.uimanager.ThemedReactContext;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -14,7 +14,6 @@ import javax.annotation.Nullable;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import android.graphics.Color;
|
|
||||||
import android.graphics.Typeface;
|
import android.graphics.Typeface;
|
||||||
import android.text.BoringLayout;
|
import android.text.BoringLayout;
|
||||||
import android.text.Layout;
|
import android.text.Layout;
|
||||||
|
@ -32,9 +31,10 @@ import com.facebook.csslayout.CSSConstants;
|
||||||
import com.facebook.csslayout.CSSNode;
|
import com.facebook.csslayout.CSSNode;
|
||||||
import com.facebook.csslayout.MeasureOutput;
|
import com.facebook.csslayout.MeasureOutput;
|
||||||
import com.facebook.infer.annotation.Assertions;
|
import com.facebook.infer.annotation.Assertions;
|
||||||
import com.facebook.react.uimanager.CatalystStylesDiffMap;
|
import com.facebook.react.common.annotations.VisibleForTesting;
|
||||||
import com.facebook.react.uimanager.IllegalViewOperationException;
|
import com.facebook.react.uimanager.IllegalViewOperationException;
|
||||||
import com.facebook.react.uimanager.PixelUtil;
|
import com.facebook.react.uimanager.PixelUtil;
|
||||||
|
import com.facebook.react.uimanager.ReactProp;
|
||||||
import com.facebook.react.uimanager.ReactShadowNode;
|
import com.facebook.react.uimanager.ReactShadowNode;
|
||||||
import com.facebook.react.uimanager.UIViewOperationQueue;
|
import com.facebook.react.uimanager.UIViewOperationQueue;
|
||||||
import com.facebook.react.uimanager.ViewDefaults;
|
import com.facebook.react.uimanager.ViewDefaults;
|
||||||
|
@ -55,9 +55,11 @@ import com.facebook.react.uimanager.ViewProps;
|
||||||
*/
|
*/
|
||||||
public class ReactTextShadowNode extends ReactShadowNode {
|
public class ReactTextShadowNode extends ReactShadowNode {
|
||||||
|
|
||||||
public static final String PROP_TEXT = "text";
|
|
||||||
public static final int UNSET = -1;
|
public static final int UNSET = -1;
|
||||||
|
|
||||||
|
@VisibleForTesting
|
||||||
|
public static final String PROP_TEXT = "text";
|
||||||
|
|
||||||
private static final TextPaint sTextPaintInstance = new TextPaint();
|
private static final TextPaint sTextPaintInstance = new TextPaint();
|
||||||
|
|
||||||
static {
|
static {
|
||||||
|
@ -287,85 +289,88 @@ public class ReactTextShadowNode extends ReactShadowNode {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@ReactProp(name = PROP_TEXT)
|
||||||
public void updateShadowNode(CatalystStylesDiffMap styles) {
|
public void setText(@Nullable String text) {
|
||||||
super.updateShadowNode(styles);
|
mText = text;
|
||||||
|
markUpdated();
|
||||||
|
}
|
||||||
|
|
||||||
if (styles.hasKey(PROP_TEXT)) {
|
@ReactProp(name = ViewProps.NUMBER_OF_LINES, defaultInt = UNSET)
|
||||||
mText = styles.getString(PROP_TEXT);
|
public void setNumberOfLines(int numberOfLines) {
|
||||||
markUpdated();
|
mNumberOfLines = numberOfLines;
|
||||||
|
markUpdated();
|
||||||
|
}
|
||||||
|
|
||||||
|
@ReactProp(name = ViewProps.LINE_HEIGHT, defaultInt = UNSET)
|
||||||
|
public void setLineHeight(int lineHeight) {
|
||||||
|
mLineHeight = lineHeight;
|
||||||
|
markUpdated();
|
||||||
|
}
|
||||||
|
|
||||||
|
@ReactProp(name = ViewProps.FONT_SIZE, defaultFloat = UNSET)
|
||||||
|
public void setFontSize(float fontSize) {
|
||||||
|
if (fontSize != UNSET) {
|
||||||
|
fontSize = (float) Math.ceil(PixelUtil.toPixelFromSP(fontSize));
|
||||||
}
|
}
|
||||||
if (styles.hasKey(ViewProps.NUMBER_OF_LINES)) {
|
mFontSize = (int) fontSize;
|
||||||
mNumberOfLines = styles.getInt(ViewProps.NUMBER_OF_LINES, UNSET);
|
markUpdated();
|
||||||
markUpdated();
|
}
|
||||||
}
|
|
||||||
if (styles.hasKey(ViewProps.LINE_HEIGHT)) {
|
@ReactProp(name = ViewProps.COLOR)
|
||||||
mLineHeight = styles.getInt(ViewProps.LINE_HEIGHT, UNSET);
|
public void setColor(@Nullable Integer color) {
|
||||||
markUpdated();
|
mIsColorSet = (color != null);
|
||||||
}
|
if (mIsColorSet) {
|
||||||
if (styles.hasKey(ViewProps.FONT_SIZE)) {
|
mColor = color;
|
||||||
if (styles.isNull(ViewProps.FONT_SIZE)) {
|
|
||||||
mFontSize = UNSET;
|
|
||||||
} else {
|
|
||||||
mFontSize = (int) Math.ceil(PixelUtil.toPixelFromSP(
|
|
||||||
styles.getFloat(ViewProps.FONT_SIZE, ViewDefaults.FONT_SIZE_SP)));
|
|
||||||
}
|
|
||||||
markUpdated();
|
|
||||||
}
|
|
||||||
if (styles.hasKey(ViewProps.COLOR)) {
|
|
||||||
if (styles.isNull(ViewProps.COLOR)) {
|
|
||||||
mIsColorSet = false;
|
|
||||||
} else {
|
|
||||||
mColor = styles.getInt(ViewProps.COLOR, Color.TRANSPARENT);
|
|
||||||
mIsColorSet = true;
|
|
||||||
}
|
|
||||||
markUpdated();
|
|
||||||
}
|
}
|
||||||
|
markUpdated();
|
||||||
|
}
|
||||||
|
|
||||||
|
@ReactProp(name = ViewProps.BACKGROUND_COLOR)
|
||||||
|
public void setBackgroundColor(Integer color) {
|
||||||
// Don't apply background color to anchor TextView since it will be applied on the View directly
|
// Don't apply background color to anchor TextView since it will be applied on the View directly
|
||||||
if (styles.hasKey(ViewProps.BACKGROUND_COLOR) && this.isVirtualAnchor() == false) {
|
if (!isVirtualAnchor()) {
|
||||||
if (styles.isNull(ViewProps.BACKGROUND_COLOR)) {
|
mIsBackgroundColorSet = (color != null);
|
||||||
mIsBackgroundColorSet = false;
|
if (mIsBackgroundColorSet) {
|
||||||
} else {
|
mBackgroundColor = color;
|
||||||
mBackgroundColor = styles.getInt(ViewProps.BACKGROUND_COLOR, Color.TRANSPARENT);
|
|
||||||
mIsBackgroundColorSet = true;
|
|
||||||
}
|
}
|
||||||
markUpdated();
|
markUpdated();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (styles.hasKey(ViewProps.FONT_FAMILY)) {
|
@ReactProp(name = ViewProps.FONT_FAMILY)
|
||||||
mFontFamily = styles.getString(ViewProps.FONT_FAMILY);
|
public void setFontFamily(@Nullable String fontFamily) {
|
||||||
|
mFontFamily = fontFamily;
|
||||||
|
markUpdated();
|
||||||
|
}
|
||||||
|
|
||||||
|
@ReactProp(name = ViewProps.FONT_WEIGHT)
|
||||||
|
public void setFontWeight(@Nullable String fontWeightString) {
|
||||||
|
int fontWeightNumeric = fontWeightString != null ?
|
||||||
|
parseNumericFontWeight(fontWeightString) : -1;
|
||||||
|
int fontWeight = UNSET;
|
||||||
|
if (fontWeightNumeric >= 500 || "bold".equals(fontWeightString)) {
|
||||||
|
fontWeight = Typeface.BOLD;
|
||||||
|
} else if ("normal".equals(fontWeightString) ||
|
||||||
|
(fontWeightNumeric != -1 && fontWeightNumeric < 500)) {
|
||||||
|
fontWeight = Typeface.NORMAL;
|
||||||
|
}
|
||||||
|
if (fontWeight != mFontWeight) {
|
||||||
|
mFontWeight = fontWeight;
|
||||||
markUpdated();
|
markUpdated();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (styles.hasKey(ViewProps.FONT_WEIGHT)) {
|
@ReactProp(name = ViewProps.FONT_STYLE)
|
||||||
String fontWeightString = styles.getString(ViewProps.FONT_WEIGHT);
|
public void setFontStyle(@Nullable String fontStyleString) {
|
||||||
int fontWeightNumeric = fontWeightString != null ?
|
int fontStyle = UNSET;
|
||||||
parseNumericFontWeight(fontWeightString) : -1;
|
if ("italic".equals(fontStyleString)) {
|
||||||
int fontWeight = UNSET;
|
fontStyle = Typeface.ITALIC;
|
||||||
if (fontWeightNumeric >= 500 || "bold".equals(fontWeightString)) {
|
} else if ("normal".equals(fontStyleString)) {
|
||||||
fontWeight = Typeface.BOLD;
|
fontStyle = Typeface.NORMAL;
|
||||||
} else if ("normal".equals(fontWeightString) ||
|
|
||||||
(fontWeightNumeric != -1 && fontWeightNumeric < 500)) {
|
|
||||||
fontWeight = Typeface.NORMAL;
|
|
||||||
}
|
|
||||||
if (fontWeight != mFontWeight) {
|
|
||||||
mFontWeight = fontWeight;
|
|
||||||
markUpdated();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
if (fontStyle != mFontStyle) {
|
||||||
if (styles.hasKey(ViewProps.FONT_STYLE)) {
|
mFontStyle = fontStyle;
|
||||||
String fontStyleString = styles.getString(ViewProps.FONT_STYLE);
|
markUpdated();
|
||||||
int fontStyle = UNSET;
|
|
||||||
if ("italic".equals(fontStyleString)) {
|
|
||||||
fontStyle = Typeface.ITALIC;
|
|
||||||
} else if ("normal".equals(fontStyleString)) {
|
|
||||||
fontStyle = Typeface.NORMAL;
|
|
||||||
}
|
|
||||||
if (fontStyle != mFontStyle) {
|
|
||||||
mFontStyle = fontStyle;
|
|
||||||
markUpdated();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -52,13 +52,6 @@ public class ReactTextInputManager extends
|
||||||
private static final int FOCUS_TEXT_INPUT = 1;
|
private static final int FOCUS_TEXT_INPUT = 1;
|
||||||
private static final int BLUR_TEXT_INPUT = 2;
|
private static final int BLUR_TEXT_INPUT = 2;
|
||||||
|
|
||||||
@UIProp(UIProp.Type.STRING)
|
|
||||||
public static final String PROP_TEXT_INPUT_TEXT = "text";
|
|
||||||
@UIProp(UIProp.Type.NUMBER)
|
|
||||||
public static final String PROP_TEXT_INPUT_MOST_RECENT_EVENT_COUNT = "mostRecentEventCount";
|
|
||||||
@UIProp(UIProp.Type.COLOR)
|
|
||||||
public static final String PROP_TEXT_INPUT_COLOR = ViewProps.COLOR;
|
|
||||||
|
|
||||||
private static final String KEYBOARD_TYPE_EMAIL_ADDRESS = "email-address";
|
private static final String KEYBOARD_TYPE_EMAIL_ADDRESS = "email-address";
|
||||||
private static final String KEYBOARD_TYPE_NUMERIC = "numeric";
|
private static final String KEYBOARD_TYPE_NUMERIC = "numeric";
|
||||||
|
|
||||||
|
|
|
@ -21,15 +21,18 @@ import com.facebook.csslayout.CSSNode;
|
||||||
import com.facebook.csslayout.MeasureOutput;
|
import com.facebook.csslayout.MeasureOutput;
|
||||||
import com.facebook.csslayout.Spacing;
|
import com.facebook.csslayout.Spacing;
|
||||||
import com.facebook.infer.annotation.Assertions;
|
import com.facebook.infer.annotation.Assertions;
|
||||||
|
import com.facebook.react.common.annotations.VisibleForTesting;
|
||||||
import com.facebook.react.uimanager.CatalystStylesDiffMap;
|
import com.facebook.react.uimanager.CatalystStylesDiffMap;
|
||||||
import com.facebook.react.uimanager.PixelUtil;
|
import com.facebook.react.uimanager.PixelUtil;
|
||||||
|
import com.facebook.react.uimanager.ReactProp;
|
||||||
import com.facebook.react.uimanager.ThemedReactContext;
|
import com.facebook.react.uimanager.ThemedReactContext;
|
||||||
import com.facebook.react.uimanager.UIViewOperationQueue;
|
import com.facebook.react.uimanager.UIViewOperationQueue;
|
||||||
import com.facebook.react.uimanager.ViewDefaults;
|
import com.facebook.react.uimanager.ViewDefaults;
|
||||||
import com.facebook.react.uimanager.ViewProps;
|
import com.facebook.react.uimanager.ViewProps;
|
||||||
import com.facebook.react.views.text.ReactTextShadowNode;
|
import com.facebook.react.views.text.ReactTextShadowNode;
|
||||||
|
|
||||||
/* package */ class ReactTextInputShadowNode extends ReactTextShadowNode implements
|
@VisibleForTesting
|
||||||
|
public class ReactTextInputShadowNode extends ReactTextShadowNode implements
|
||||||
CSSNode.MeasureFunction {
|
CSSNode.MeasureFunction {
|
||||||
|
|
||||||
private static final int MEASURE_SPEC = View.MeasureSpec.makeMeasureSpec(
|
private static final int MEASURE_SPEC = View.MeasureSpec.makeMeasureSpec(
|
||||||
|
@ -96,22 +99,19 @@ import com.facebook.react.views.text.ReactTextShadowNode;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@ReactProp(name = ViewProps.FONT_SIZE, defaultFloat = ViewDefaults.FONT_SIZE_SP)
|
||||||
public void updateShadowNode(CatalystStylesDiffMap styles) {
|
public void setFontSize(float fontSize) {
|
||||||
super.updateShadowNode(styles);
|
mFontSize = (int) Math.ceil(PixelUtil.toPixelFromSP(fontSize));
|
||||||
if (styles.hasKey(ViewProps.FONT_SIZE)) {
|
}
|
||||||
float fontSize = styles.getFloat(ViewProps.FONT_SIZE, ViewDefaults.FONT_SIZE_SP);
|
|
||||||
mFontSize = (int) Math.ceil(PixelUtil.toPixelFromSP(fontSize));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (styles.hasKey(ReactTextInputManager.PROP_TEXT_INPUT_MOST_RECENT_EVENT_COUNT)) {
|
@ReactProp(name = "mostRecentEventCount")
|
||||||
mJsEventCount =
|
public void setMostRecentEventCount(int mostRecentEventCount) {
|
||||||
styles.getInt(ReactTextInputManager.PROP_TEXT_INPUT_MOST_RECENT_EVENT_COUNT, 0);
|
mJsEventCount = mostRecentEventCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (styles.hasKey(ViewProps.NUMBER_OF_LINES)) {
|
@ReactProp(name = ViewProps.NUMBER_OF_LINES, defaultInt = UNSET)
|
||||||
mNumLines = styles.getInt(ViewProps.NUMBER_OF_LINES, UNSET);
|
public void setNumberOfLines(int numberOfLines) {
|
||||||
}
|
mNumLines = numberOfLines;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
Loading…
Reference in New Issue