mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
BackgroundStyleApplicator and boxShadow in TextInput (#45831)
Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/45831 Like the previous diffs, but for TextInput! Changelog: [Internal] Reviewed By: joevilches Differential Revision: D60489444 fbshipit-source-id: 13edc2fada0ef55a84916e6bdff151e4f8a16d34
This commit is contained in:
committed by
Facebook GitHub Bot
parent
f26027e3c0
commit
7047b7eaeb
+3
@@ -739,6 +739,9 @@ export const __INTERNAL_VIEW_CONFIG: PartialViewConfig = {
|
||||
},
|
||||
borderTopLeftRadius: true,
|
||||
borderTopColor: {process: require('../../StyleSheet/processColor').default},
|
||||
experimental_boxShadow: {
|
||||
process: require('../../StyleSheet/processBoxShadow').default,
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
|
||||
@@ -8025,10 +8025,13 @@ public class com/facebook/react/views/textinput/ReactTextInputManager : com/face
|
||||
public fun setAutoCapitalize (Lcom/facebook/react/views/textinput/ReactEditText;Lcom/facebook/react/bridge/Dynamic;)V
|
||||
public fun setAutoCorrect (Lcom/facebook/react/views/textinput/ReactEditText;Ljava/lang/Boolean;)V
|
||||
public fun setAutoFocus (Lcom/facebook/react/views/textinput/ReactEditText;Z)V
|
||||
public synthetic fun setBackgroundColor (Landroid/view/View;I)V
|
||||
public fun setBackgroundColor (Lcom/facebook/react/views/textinput/ReactEditText;I)V
|
||||
public fun setBorderColor (Lcom/facebook/react/views/textinput/ReactEditText;ILjava/lang/Integer;)V
|
||||
public fun setBorderRadius (Lcom/facebook/react/views/textinput/ReactEditText;IF)V
|
||||
public fun setBorderStyle (Lcom/facebook/react/views/textinput/ReactEditText;Ljava/lang/String;)V
|
||||
public fun setBorderWidth (Lcom/facebook/react/views/textinput/ReactEditText;IF)V
|
||||
public fun setBoxShadow (Lcom/facebook/react/views/textinput/ReactEditText;Lcom/facebook/react/bridge/ReadableArray;)V
|
||||
public fun setCaretHidden (Lcom/facebook/react/views/textinput/ReactEditText;Z)V
|
||||
public fun setColor (Lcom/facebook/react/views/textinput/ReactEditText;Ljava/lang/Integer;)V
|
||||
public fun setContextMenuHidden (Lcom/facebook/react/views/textinput/ReactEditText;Z)V
|
||||
|
||||
+60
-8
@@ -49,10 +49,19 @@ import com.facebook.react.bridge.ReactContext;
|
||||
import com.facebook.react.bridge.ReactSoftExceptionLogger;
|
||||
import com.facebook.react.common.ReactConstants;
|
||||
import com.facebook.react.common.build.ReactBuildConfig;
|
||||
import com.facebook.react.internal.featureflags.ReactNativeFeatureFlags;
|
||||
import com.facebook.react.uimanager.BackgroundStyleApplicator;
|
||||
import com.facebook.react.uimanager.LengthPercentage;
|
||||
import com.facebook.react.uimanager.LengthPercentageType;
|
||||
import com.facebook.react.uimanager.PixelUtil;
|
||||
import com.facebook.react.uimanager.ReactAccessibilityDelegate;
|
||||
import com.facebook.react.uimanager.StateWrapper;
|
||||
import com.facebook.react.uimanager.UIManagerModule;
|
||||
import com.facebook.react.uimanager.events.EventDispatcher;
|
||||
import com.facebook.react.uimanager.style.BorderRadiusProp;
|
||||
import com.facebook.react.uimanager.style.BorderStyle;
|
||||
import com.facebook.react.uimanager.style.LogicalEdge;
|
||||
import com.facebook.react.uimanager.style.Overflow;
|
||||
import com.facebook.react.views.text.ReactTextUpdate;
|
||||
import com.facebook.react.views.text.ReactTypefaceUtils;
|
||||
import com.facebook.react.views.text.TextAttributes;
|
||||
@@ -122,6 +131,7 @@ public class ReactEditText extends AppCompatEditText {
|
||||
private boolean mDidAttachToWindow = false;
|
||||
private boolean mSelectTextOnFocus = false;
|
||||
private @Nullable String mPlaceholder = null;
|
||||
private Overflow mOverflow = Overflow.VISIBLE;
|
||||
|
||||
private final ReactViewBackgroundManager mReactBackgroundManager;
|
||||
|
||||
@@ -1077,31 +1087,65 @@ public class ReactEditText extends AppCompatEditText {
|
||||
|
||||
@Override
|
||||
public void setBackgroundColor(int color) {
|
||||
mReactBackgroundManager.setBackgroundColor(color);
|
||||
if (ReactNativeFeatureFlags.enableBackgroundStyleApplicator()) {
|
||||
BackgroundStyleApplicator.setBackgroundColor(this, color);
|
||||
} else {
|
||||
mReactBackgroundManager.setBackgroundColor(color);
|
||||
}
|
||||
}
|
||||
|
||||
public void setBorderWidth(int position, float width) {
|
||||
mReactBackgroundManager.setBorderWidth(position, width);
|
||||
if (ReactNativeFeatureFlags.enableBackgroundStyleApplicator()) {
|
||||
BackgroundStyleApplicator.setBorderWidth(
|
||||
this, LogicalEdge.values()[position], PixelUtil.toDIPFromPixel(width));
|
||||
} else {
|
||||
mReactBackgroundManager.setBorderWidth(position, width);
|
||||
}
|
||||
}
|
||||
|
||||
public void setBorderColor(int position, @Nullable Integer color) {
|
||||
mReactBackgroundManager.setBorderColor(position, color);
|
||||
if (ReactNativeFeatureFlags.enableBackgroundStyleApplicator()) {
|
||||
BackgroundStyleApplicator.setBorderColor(this, LogicalEdge.values()[position], color);
|
||||
} else {
|
||||
mReactBackgroundManager.setBorderColor(position, color);
|
||||
}
|
||||
}
|
||||
|
||||
public int getBorderColor(int position) {
|
||||
return mReactBackgroundManager.getBorderColor(position);
|
||||
if (ReactNativeFeatureFlags.enableBackgroundStyleApplicator()) {
|
||||
@Nullable
|
||||
Integer borderColor =
|
||||
BackgroundStyleApplicator.getBorderColor(this, LogicalEdge.values()[position]);
|
||||
return borderColor == null ? Color.TRANSPARENT : borderColor;
|
||||
} else {
|
||||
return mReactBackgroundManager.getBorderColor(position);
|
||||
}
|
||||
}
|
||||
|
||||
public void setBorderRadius(float borderRadius) {
|
||||
mReactBackgroundManager.setBorderRadius(borderRadius);
|
||||
setBorderRadius(borderRadius, BorderRadiusProp.BORDER_RADIUS.ordinal());
|
||||
}
|
||||
|
||||
public void setBorderRadius(float borderRadius, int position) {
|
||||
mReactBackgroundManager.setBorderRadius(borderRadius, position);
|
||||
if (ReactNativeFeatureFlags.enableBackgroundStyleApplicator()) {
|
||||
@Nullable
|
||||
LengthPercentage radius =
|
||||
Float.isNaN(borderRadius)
|
||||
? null
|
||||
: new LengthPercentage(borderRadius, LengthPercentageType.POINT);
|
||||
BackgroundStyleApplicator.setBorderRadius(this, BorderRadiusProp.values()[position], radius);
|
||||
} else {
|
||||
mReactBackgroundManager.setBorderRadius(borderRadius, position);
|
||||
}
|
||||
}
|
||||
|
||||
public void setBorderStyle(@Nullable String style) {
|
||||
mReactBackgroundManager.setBorderStyle(style);
|
||||
if (ReactNativeFeatureFlags.enableBackgroundStyleApplicator()) {
|
||||
BackgroundStyleApplicator.setBorderStyle(
|
||||
this, style == null ? null : BorderStyle.fromString(style));
|
||||
} else {
|
||||
mReactBackgroundManager.setBorderStyle(style);
|
||||
}
|
||||
}
|
||||
|
||||
public void setLetterSpacingPt(float letterSpacingPt) {
|
||||
@@ -1248,12 +1292,20 @@ public class ReactEditText extends AppCompatEditText {
|
||||
}
|
||||
|
||||
public void setOverflow(@Nullable String overflow) {
|
||||
mOverflow = overflow == null ? Overflow.VISIBLE : Overflow.fromString(overflow);
|
||||
mReactBackgroundManager.setOverflow(overflow);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDraw(Canvas canvas) {
|
||||
mReactBackgroundManager.maybeClipToPaddingBox(canvas);
|
||||
if (ReactNativeFeatureFlags.enableBackgroundStyleApplicator()) {
|
||||
if (mOverflow != Overflow.VISIBLE) {
|
||||
BackgroundStyleApplicator.clipToPaddingBox(this, canvas);
|
||||
}
|
||||
} else {
|
||||
mReactBackgroundManager.maybeClipToPaddingBox(canvas);
|
||||
}
|
||||
|
||||
super.onDraw(canvas);
|
||||
}
|
||||
|
||||
|
||||
+62
-12
@@ -29,6 +29,7 @@ import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.inputmethod.EditorInfo;
|
||||
import android.widget.TextView;
|
||||
import androidx.annotation.ColorInt;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.autofill.HintConstants;
|
||||
import androidx.core.content.ContextCompat;
|
||||
@@ -44,9 +45,13 @@ import com.facebook.react.bridge.WritableNativeMap;
|
||||
import com.facebook.react.common.MapBuilder;
|
||||
import com.facebook.react.common.ReactConstants;
|
||||
import com.facebook.react.common.mapbuffer.MapBuffer;
|
||||
import com.facebook.react.internal.featureflags.ReactNativeFeatureFlags;
|
||||
import com.facebook.react.module.annotations.ReactModule;
|
||||
import com.facebook.react.uimanager.BackgroundStyleApplicator;
|
||||
import com.facebook.react.uimanager.BaseViewManager;
|
||||
import com.facebook.react.uimanager.LayoutShadowNode;
|
||||
import com.facebook.react.uimanager.LengthPercentage;
|
||||
import com.facebook.react.uimanager.LengthPercentageType;
|
||||
import com.facebook.react.uimanager.PixelUtil;
|
||||
import com.facebook.react.uimanager.ReactStylesDiffMap;
|
||||
import com.facebook.react.uimanager.Spacing;
|
||||
@@ -58,6 +63,9 @@ import com.facebook.react.uimanager.ViewProps;
|
||||
import com.facebook.react.uimanager.annotations.ReactProp;
|
||||
import com.facebook.react.uimanager.annotations.ReactPropGroup;
|
||||
import com.facebook.react.uimanager.events.EventDispatcher;
|
||||
import com.facebook.react.uimanager.style.BorderRadiusProp;
|
||||
import com.facebook.react.uimanager.style.BorderStyle;
|
||||
import com.facebook.react.uimanager.style.LogicalEdge;
|
||||
import com.facebook.react.views.imagehelper.ResourceDrawableIdHelper;
|
||||
import com.facebook.react.views.scroll.ScrollEvent;
|
||||
import com.facebook.react.views.scroll.ScrollEventType;
|
||||
@@ -949,20 +957,37 @@ public class ReactTextInputManager extends BaseViewManager<ReactEditText, Layout
|
||||
},
|
||||
defaultFloat = Float.NaN)
|
||||
public void setBorderRadius(ReactEditText view, int index, float borderRadius) {
|
||||
if (!Float.isNaN(borderRadius)) {
|
||||
borderRadius = PixelUtil.toPixelFromDIP(borderRadius);
|
||||
}
|
||||
|
||||
if (index == 0) {
|
||||
view.setBorderRadius(borderRadius);
|
||||
if (ReactNativeFeatureFlags.enableBackgroundStyleApplicator()) {
|
||||
@Nullable
|
||||
LengthPercentage radius =
|
||||
Float.isNaN(borderRadius)
|
||||
? null
|
||||
: new LengthPercentage(
|
||||
PixelUtil.toPixelFromDIP(borderRadius), LengthPercentageType.POINT);
|
||||
BackgroundStyleApplicator.setBorderRadius(view, BorderRadiusProp.values()[index], radius);
|
||||
} else {
|
||||
view.setBorderRadius(borderRadius, index - 1);
|
||||
if (!Float.isNaN(borderRadius)) {
|
||||
borderRadius = PixelUtil.toPixelFromDIP(borderRadius);
|
||||
}
|
||||
|
||||
if (index == 0) {
|
||||
view.setBorderRadius(borderRadius);
|
||||
} else {
|
||||
view.setBorderRadius(borderRadius, index - 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ReactProp(name = "borderStyle")
|
||||
public void setBorderStyle(ReactEditText view, @Nullable String borderStyle) {
|
||||
view.setBorderStyle(borderStyle);
|
||||
if (ReactNativeFeatureFlags.enableBackgroundStyleApplicator()) {
|
||||
@Nullable
|
||||
BorderStyle parsedBorderStyle =
|
||||
borderStyle == null ? null : BorderStyle.fromString(borderStyle);
|
||||
BackgroundStyleApplicator.setBorderStyle(view, parsedBorderStyle);
|
||||
} else {
|
||||
view.setBorderStyle(borderStyle);
|
||||
}
|
||||
}
|
||||
|
||||
@ReactProp(name = "showSoftInputOnFocus", defaultBoolean = true)
|
||||
@@ -999,10 +1024,14 @@ public class ReactTextInputManager extends BaseViewManager<ReactEditText, Layout
|
||||
},
|
||||
defaultFloat = Float.NaN)
|
||||
public void setBorderWidth(ReactEditText view, int index, float width) {
|
||||
if (!Float.isNaN(width)) {
|
||||
width = PixelUtil.toPixelFromDIP(width);
|
||||
if (ReactNativeFeatureFlags.enableBackgroundStyleApplicator()) {
|
||||
BackgroundStyleApplicator.setBorderWidth(view, LogicalEdge.values()[index], width);
|
||||
} else {
|
||||
if (!Float.isNaN(width)) {
|
||||
width = PixelUtil.toPixelFromDIP(width);
|
||||
}
|
||||
view.setBorderWidth(SPACING_TYPES[index], width);
|
||||
}
|
||||
view.setBorderWidth(SPACING_TYPES[index], width);
|
||||
}
|
||||
|
||||
@ReactPropGroup(
|
||||
@@ -1015,7 +1044,12 @@ public class ReactTextInputManager extends BaseViewManager<ReactEditText, Layout
|
||||
},
|
||||
customType = "Color")
|
||||
public void setBorderColor(ReactEditText view, int index, @Nullable Integer color) {
|
||||
view.setBorderColor(SPACING_TYPES[index], color);
|
||||
|
||||
if (ReactNativeFeatureFlags.enableBackgroundStyleApplicator()) {
|
||||
BackgroundStyleApplicator.setBorderColor(view, LogicalEdge.ALL, color);
|
||||
} else {
|
||||
view.setBorderColor(SPACING_TYPES[index], color);
|
||||
}
|
||||
}
|
||||
|
||||
@ReactProp(name = "overflow")
|
||||
@@ -1023,6 +1057,22 @@ public class ReactTextInputManager extends BaseViewManager<ReactEditText, Layout
|
||||
view.setOverflow(overflow);
|
||||
}
|
||||
|
||||
@ReactProp(name = ViewProps.BOX_SHADOW, customType = "BoxShadow")
|
||||
public void setBoxShadow(ReactEditText view, @Nullable ReadableArray shadows) {
|
||||
if (ReactNativeFeatureFlags.enableBackgroundStyleApplicator()) {
|
||||
BackgroundStyleApplicator.setBoxShadow(view, shadows);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setBackgroundColor(ReactEditText view, @ColorInt int backgroundColor) {
|
||||
if (ReactNativeFeatureFlags.enableBackgroundStyleApplicator()) {
|
||||
BackgroundStyleApplicator.setBackgroundColor(view, backgroundColor);
|
||||
} else {
|
||||
super.setBackgroundColor(view, backgroundColor);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onAfterUpdateTransaction(ReactEditText view) {
|
||||
super.onAfterUpdateTransaction(view);
|
||||
|
||||
Reference in New Issue
Block a user