diff --git a/ReactAndroid/src/main/java/com/facebook/react/views/progressbar/ProgressBarShadowNode.java b/ReactAndroid/src/main/java/com/facebook/react/views/progressbar/ProgressBarShadowNode.java index e9df4cc3c..8f7a4b4f5 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/views/progressbar/ProgressBarShadowNode.java +++ b/ReactAndroid/src/main/java/com/facebook/react/views/progressbar/ProgressBarShadowNode.java @@ -21,9 +21,8 @@ import android.widget.ProgressBar; import com.facebook.csslayout.CSSNode; 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.infer.annotation.Assertions; /** * 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 { - private @Nullable String style; + private String mStyle = ReactProgressBarViewManager.DEFAULT_STYLE; private final SparseIntArray mHeight = new SparseIntArray(); private final SparseIntArray mWidth = new SparseIntArray(); @@ -43,11 +42,12 @@ public class ProgressBarShadowNode extends ReactShadowNode implements CSSNode.Me } public @Nullable String getStyle() { - return style; + return mStyle; } - public void setStyle(String style) { - this.style = style; + @ReactProp(name = ReactProgressBarViewManager.PROP_STYLE) + public void setStyle(@Nullable String style) { + mStyle = style == null ? ReactProgressBarViewManager.DEFAULT_STYLE : style; } @Override @@ -67,20 +67,4 @@ public class ProgressBarShadowNode extends ReactShadowNode implements CSSNode.Me measureOutput.height = mHeight.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); - } - } } diff --git a/ReactAndroid/src/main/java/com/facebook/react/views/text/ReactRawTextManager.java b/ReactAndroid/src/main/java/com/facebook/react/views/text/ReactRawTextManager.java index ebb387897..83f556823 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/views/text/ReactRawTextManager.java +++ b/ReactAndroid/src/main/java/com/facebook/react/views/text/ReactRawTextManager.java @@ -9,8 +9,8 @@ package com.facebook.react.views.text; -import com.facebook.react.uimanager.CatalystStylesDiffMap; import com.facebook.react.common.annotations.VisibleForTesting; +import com.facebook.react.uimanager.CatalystStylesDiffMap; import com.facebook.react.uimanager.ThemedReactContext; /** diff --git a/ReactAndroid/src/main/java/com/facebook/react/views/text/ReactTextShadowNode.java b/ReactAndroid/src/main/java/com/facebook/react/views/text/ReactTextShadowNode.java index 8841ced48..ef5c97e5f 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/views/text/ReactTextShadowNode.java +++ b/ReactAndroid/src/main/java/com/facebook/react/views/text/ReactTextShadowNode.java @@ -14,7 +14,6 @@ import javax.annotation.Nullable; import java.util.ArrayList; import java.util.List; -import android.graphics.Color; import android.graphics.Typeface; import android.text.BoringLayout; import android.text.Layout; @@ -32,9 +31,10 @@ import com.facebook.csslayout.CSSConstants; import com.facebook.csslayout.CSSNode; import com.facebook.csslayout.MeasureOutput; 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.PixelUtil; +import com.facebook.react.uimanager.ReactProp; import com.facebook.react.uimanager.ReactShadowNode; import com.facebook.react.uimanager.UIViewOperationQueue; import com.facebook.react.uimanager.ViewDefaults; @@ -55,9 +55,11 @@ import com.facebook.react.uimanager.ViewProps; */ public class ReactTextShadowNode extends ReactShadowNode { - public static final String PROP_TEXT = "text"; public static final int UNSET = -1; + @VisibleForTesting + public static final String PROP_TEXT = "text"; + private static final TextPaint sTextPaintInstance = new TextPaint(); static { @@ -287,85 +289,88 @@ public class ReactTextShadowNode extends ReactShadowNode { } } - @Override - public void updateShadowNode(CatalystStylesDiffMap styles) { - super.updateShadowNode(styles); + @ReactProp(name = PROP_TEXT) + public void setText(@Nullable String text) { + mText = text; + markUpdated(); + } - if (styles.hasKey(PROP_TEXT)) { - mText = styles.getString(PROP_TEXT); - markUpdated(); + @ReactProp(name = ViewProps.NUMBER_OF_LINES, defaultInt = UNSET) + public void setNumberOfLines(int numberOfLines) { + 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)) { - mNumberOfLines = styles.getInt(ViewProps.NUMBER_OF_LINES, UNSET); - markUpdated(); - } - if (styles.hasKey(ViewProps.LINE_HEIGHT)) { - mLineHeight = styles.getInt(ViewProps.LINE_HEIGHT, UNSET); - markUpdated(); - } - if (styles.hasKey(ViewProps.FONT_SIZE)) { - 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(); + mFontSize = (int) fontSize; + markUpdated(); + } + + @ReactProp(name = ViewProps.COLOR) + public void setColor(@Nullable Integer color) { + mIsColorSet = (color != null); + if (mIsColorSet) { + mColor = color; } + 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 - if (styles.hasKey(ViewProps.BACKGROUND_COLOR) && this.isVirtualAnchor() == false) { - if (styles.isNull(ViewProps.BACKGROUND_COLOR)) { - mIsBackgroundColorSet = false; - } else { - mBackgroundColor = styles.getInt(ViewProps.BACKGROUND_COLOR, Color.TRANSPARENT); - mIsBackgroundColorSet = true; + if (!isVirtualAnchor()) { + mIsBackgroundColorSet = (color != null); + if (mIsBackgroundColorSet) { + mBackgroundColor = color; } markUpdated(); } + } - if (styles.hasKey(ViewProps.FONT_FAMILY)) { - mFontFamily = styles.getString(ViewProps.FONT_FAMILY); + @ReactProp(name = 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(); } + } - if (styles.hasKey(ViewProps.FONT_WEIGHT)) { - String fontWeightString = styles.getString(ViewProps.FONT_WEIGHT); - 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(); - } + @ReactProp(name = ViewProps.FONT_STYLE) + public void setFontStyle(@Nullable String fontStyleString) { + int fontStyle = UNSET; + if ("italic".equals(fontStyleString)) { + fontStyle = Typeface.ITALIC; + } else if ("normal".equals(fontStyleString)) { + fontStyle = Typeface.NORMAL; } - - if (styles.hasKey(ViewProps.FONT_STYLE)) { - String fontStyleString = styles.getString(ViewProps.FONT_STYLE); - int fontStyle = UNSET; - if ("italic".equals(fontStyleString)) { - fontStyle = Typeface.ITALIC; - } else if ("normal".equals(fontStyleString)) { - fontStyle = Typeface.NORMAL; - } - if (fontStyle != mFontStyle) { - mFontStyle = fontStyle; - markUpdated(); - } + if (fontStyle != mFontStyle) { + mFontStyle = fontStyle; + markUpdated(); } } diff --git a/ReactAndroid/src/main/java/com/facebook/react/views/textinput/ReactTextInputManager.java b/ReactAndroid/src/main/java/com/facebook/react/views/textinput/ReactTextInputManager.java index 4e8449d99..e7c28d556 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/views/textinput/ReactTextInputManager.java +++ b/ReactAndroid/src/main/java/com/facebook/react/views/textinput/ReactTextInputManager.java @@ -52,13 +52,6 @@ public class ReactTextInputManager extends private static final int FOCUS_TEXT_INPUT = 1; 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_NUMERIC = "numeric"; diff --git a/ReactAndroid/src/main/java/com/facebook/react/views/textinput/ReactTextInputShadowNode.java b/ReactAndroid/src/main/java/com/facebook/react/views/textinput/ReactTextInputShadowNode.java index 14e77cdc2..0ef974826 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/views/textinput/ReactTextInputShadowNode.java +++ b/ReactAndroid/src/main/java/com/facebook/react/views/textinput/ReactTextInputShadowNode.java @@ -21,15 +21,18 @@ import com.facebook.csslayout.CSSNode; import com.facebook.csslayout.MeasureOutput; import com.facebook.csslayout.Spacing; import com.facebook.infer.annotation.Assertions; +import com.facebook.react.common.annotations.VisibleForTesting; import com.facebook.react.uimanager.CatalystStylesDiffMap; import com.facebook.react.uimanager.PixelUtil; +import com.facebook.react.uimanager.ReactProp; import com.facebook.react.uimanager.ThemedReactContext; import com.facebook.react.uimanager.UIViewOperationQueue; import com.facebook.react.uimanager.ViewDefaults; import com.facebook.react.uimanager.ViewProps; import com.facebook.react.views.text.ReactTextShadowNode; -/* package */ class ReactTextInputShadowNode extends ReactTextShadowNode implements +@VisibleForTesting +public class ReactTextInputShadowNode extends ReactTextShadowNode implements CSSNode.MeasureFunction { private static final int MEASURE_SPEC = View.MeasureSpec.makeMeasureSpec( @@ -96,22 +99,19 @@ import com.facebook.react.views.text.ReactTextShadowNode; return; } - @Override - public void updateShadowNode(CatalystStylesDiffMap styles) { - 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)); - } + @ReactProp(name = ViewProps.FONT_SIZE, defaultFloat = ViewDefaults.FONT_SIZE_SP) + public void setFontSize(float fontSize) { + mFontSize = (int) Math.ceil(PixelUtil.toPixelFromSP(fontSize)); + } - if (styles.hasKey(ReactTextInputManager.PROP_TEXT_INPUT_MOST_RECENT_EVENT_COUNT)) { - mJsEventCount = - styles.getInt(ReactTextInputManager.PROP_TEXT_INPUT_MOST_RECENT_EVENT_COUNT, 0); - } + @ReactProp(name = "mostRecentEventCount") + public void setMostRecentEventCount(int mostRecentEventCount) { + mJsEventCount = mostRecentEventCount; + } - if (styles.hasKey(ViewProps.NUMBER_OF_LINES)) { - mNumLines = styles.getInt(ViewProps.NUMBER_OF_LINES, UNSET); - } + @ReactProp(name = ViewProps.NUMBER_OF_LINES, defaultInt = UNSET) + public void setNumberOfLines(int numberOfLines) { + mNumLines = numberOfLines; } @Override