Convert basic shadow nodes to use @ReactProp.

Differential Revision: D2537318

fb-gh-sync-id: 3061545f27953299904fe224e973fa409650d239
This commit is contained in:
Krzysztof Magiera 2015-10-13 12:47:58 -07:00 committed by facebook-github-bot-3
parent 08e79deebd
commit f4e2a670d3
5 changed files with 97 additions and 115 deletions

View File

@ -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);
}
}
} }

View File

@ -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;
/** /**

View File

@ -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,58 +289,62 @@ 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) {
mNumberOfLines = numberOfLines;
markUpdated(); markUpdated();
} }
if (styles.hasKey(ViewProps.NUMBER_OF_LINES)) {
mNumberOfLines = styles.getInt(ViewProps.NUMBER_OF_LINES, UNSET); @ReactProp(name = ViewProps.LINE_HEIGHT, defaultInt = UNSET)
public void setLineHeight(int lineHeight) {
mLineHeight = lineHeight;
markUpdated(); markUpdated();
} }
if (styles.hasKey(ViewProps.LINE_HEIGHT)) {
mLineHeight = styles.getInt(ViewProps.LINE_HEIGHT, UNSET); @ReactProp(name = ViewProps.FONT_SIZE, defaultFloat = UNSET)
public void setFontSize(float fontSize) {
if (fontSize != UNSET) {
fontSize = (float) Math.ceil(PixelUtil.toPixelFromSP(fontSize));
}
mFontSize = (int) fontSize;
markUpdated(); markUpdated();
} }
if (styles.hasKey(ViewProps.FONT_SIZE)) {
if (styles.isNull(ViewProps.FONT_SIZE)) { @ReactProp(name = ViewProps.COLOR)
mFontSize = UNSET; public void setColor(@Nullable Integer color) {
} else { mIsColorSet = (color != null);
mFontSize = (int) Math.ceil(PixelUtil.toPixelFromSP( if (mIsColorSet) {
styles.getFloat(ViewProps.FONT_SIZE, ViewDefaults.FONT_SIZE_SP))); mColor = color;
}
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(); markUpdated();
} }
if (styles.hasKey(ViewProps.FONT_WEIGHT)) { @ReactProp(name = ViewProps.FONT_WEIGHT)
String fontWeightString = styles.getString(ViewProps.FONT_WEIGHT); public void setFontWeight(@Nullable String fontWeightString) {
int fontWeightNumeric = fontWeightString != null ? int fontWeightNumeric = fontWeightString != null ?
parseNumericFontWeight(fontWeightString) : -1; parseNumericFontWeight(fontWeightString) : -1;
int fontWeight = UNSET; int fontWeight = UNSET;
@ -354,8 +360,8 @@ public class ReactTextShadowNode extends ReactShadowNode {
} }
} }
if (styles.hasKey(ViewProps.FONT_STYLE)) { @ReactProp(name = ViewProps.FONT_STYLE)
String fontStyleString = styles.getString(ViewProps.FONT_STYLE); public void setFontStyle(@Nullable String fontStyleString) {
int fontStyle = UNSET; int fontStyle = UNSET;
if ("italic".equals(fontStyleString)) { if ("italic".equals(fontStyleString)) {
fontStyle = Typeface.ITALIC; fontStyle = Typeface.ITALIC;
@ -367,7 +373,6 @@ public class ReactTextShadowNode extends ReactShadowNode {
markUpdated(); markUpdated();
} }
} }
}
@Override @Override
public boolean isVirtualAnchor() { public boolean isVirtualAnchor() {

View File

@ -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";

View File

@ -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);
if (styles.hasKey(ViewProps.FONT_SIZE)) {
float fontSize = styles.getFloat(ViewProps.FONT_SIZE, ViewDefaults.FONT_SIZE_SP);
mFontSize = (int) Math.ceil(PixelUtil.toPixelFromSP(fontSize)); 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