Skip to content

Commit b4d2829

Browse files
NickGerlemanfacebook-github-bot
authored andcommitted
Remove ReactTextView Legacy Background Path (facebook#46171)
Summary: Pull Request resolved: facebook#46171 ## This Diff This removes the legacy path from ReactTextView and its view manager. ## This Stack This removes the non-Style-applicator background management paths of the different native components. There have been multiple conflicting changes, and bugs added bc harder to reason about, which motivates making this change as soon as possible. This also lets us formalize guarantees that BaseViewManager may safely manipulate background styling of all built in native components. There is one still known issue, where BackgroundStyleApplicator does not propagate I18nManager derived layout direction to borders (compared to Android derived root direction). This is mostly an issue for apps that with LTR and RTL context, or force a layout direction, which I would guess is relatively rare, so my plan is to forward fix this later this by enabling set_android_layout_direction which will solve that problem mopre generically. Changelog: [Internal] Reviewed By: cortinico Differential Revision: D61658083 fbshipit-source-id: b753d4eb45091aa31ea870a684c35b71c1ee5036
1 parent 6291ff0 commit b4d2829

File tree

2 files changed

+30
-101
lines changed

2 files changed

+30
-101
lines changed

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/text/ReactTextAnchorViewManager.java

Lines changed: 14 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,10 @@
1818
import com.facebook.common.logging.FLog;
1919
import com.facebook.react.bridge.ReadableArray;
2020
import com.facebook.react.common.ReactConstants;
21-
import com.facebook.react.internal.featureflags.ReactNativeFeatureFlags;
2221
import com.facebook.react.uimanager.BackgroundStyleApplicator;
2322
import com.facebook.react.uimanager.BaseViewManager;
2423
import com.facebook.react.uimanager.LengthPercentage;
2524
import com.facebook.react.uimanager.LengthPercentageType;
26-
import com.facebook.react.uimanager.PixelUtil;
2725
import com.facebook.react.uimanager.Spacing;
2826
import com.facebook.react.uimanager.ViewDefaults;
2927
import com.facebook.react.uimanager.ViewProps;
@@ -153,36 +151,20 @@ public void setAndroidHyphenationFrequency(ReactTextView view, @Nullable String
153151
},
154152
defaultFloat = Float.NaN)
155153
public void setBorderRadius(ReactTextView view, int index, float borderRadius) {
156-
if (ReactNativeFeatureFlags.enableBackgroundStyleApplicator()) {
157-
@Nullable
158-
LengthPercentage radius =
159-
Float.isNaN(borderRadius)
160-
? null
161-
: new LengthPercentage(borderRadius, LengthPercentageType.POINT);
162-
BackgroundStyleApplicator.setBorderRadius(view, BorderRadiusProp.values()[index], radius);
163-
} else {
164-
if (!Float.isNaN(borderRadius)) {
165-
borderRadius = PixelUtil.toPixelFromDIP(borderRadius);
166-
}
167-
168-
if (index == 0) {
169-
view.setBorderRadius(borderRadius);
170-
} else {
171-
view.setBorderRadius(borderRadius, index - 1);
172-
}
173-
}
154+
@Nullable
155+
LengthPercentage radius =
156+
Float.isNaN(borderRadius)
157+
? null
158+
: new LengthPercentage(borderRadius, LengthPercentageType.POINT);
159+
BackgroundStyleApplicator.setBorderRadius(view, BorderRadiusProp.values()[index], radius);
174160
}
175161

176162
@ReactProp(name = "borderStyle")
177163
public void setBorderStyle(ReactTextView view, @Nullable String borderStyle) {
178-
if (ReactNativeFeatureFlags.enableBackgroundStyleApplicator()) {
179-
@Nullable
180-
BorderStyle parsedBorderStyle =
181-
borderStyle == null ? null : BorderStyle.fromString(borderStyle);
182-
BackgroundStyleApplicator.setBorderStyle(view, parsedBorderStyle);
183-
} else {
184-
view.setBorderStyle(borderStyle);
185-
}
164+
@Nullable
165+
BorderStyle parsedBorderStyle =
166+
borderStyle == null ? null : BorderStyle.fromString(borderStyle);
167+
BackgroundStyleApplicator.setBorderStyle(view, parsedBorderStyle);
186168
}
187169

188170
@ReactPropGroup(
@@ -197,14 +179,7 @@ public void setBorderStyle(ReactTextView view, @Nullable String borderStyle) {
197179
},
198180
defaultFloat = Float.NaN)
199181
public void setBorderWidth(ReactTextView view, int index, float width) {
200-
if (ReactNativeFeatureFlags.enableBackgroundStyleApplicator()) {
201-
BackgroundStyleApplicator.setBorderWidth(view, LogicalEdge.values()[index], width);
202-
} else {
203-
if (!Float.isNaN(width)) {
204-
width = PixelUtil.toPixelFromDIP(width);
205-
}
206-
view.setBorderWidth(SPACING_TYPES[index], width);
207-
}
182+
BackgroundStyleApplicator.setBorderWidth(view, LogicalEdge.values()[index], width);
208183
}
209184

210185
@ReactPropGroup(
@@ -217,11 +192,7 @@ public void setBorderWidth(ReactTextView view, int index, float width) {
217192
},
218193
customType = "Color")
219194
public void setBorderColor(ReactTextView view, int index, @Nullable Integer color) {
220-
if (ReactNativeFeatureFlags.enableBackgroundStyleApplicator()) {
221-
BackgroundStyleApplicator.setBorderColor(view, LogicalEdge.ALL, color);
222-
} else {
223-
view.setBorderColor(SPACING_TYPES[index], color);
224-
}
195+
BackgroundStyleApplicator.setBorderColor(view, LogicalEdge.ALL, color);
225196
}
226197

227198
@ReactProp(name = ViewProps.INCLUDE_FONT_PADDING, defaultBoolean = true)
@@ -264,17 +235,11 @@ public void setNotifyOnInlineViewLayout(ReactTextView view, boolean notifyOnInli
264235

265236
@ReactProp(name = ViewProps.BOX_SHADOW, customType = "BoxShadow")
266237
public void setBoxShadow(ReactTextView view, @Nullable ReadableArray shadows) {
267-
if (ReactNativeFeatureFlags.enableBackgroundStyleApplicator()) {
268-
BackgroundStyleApplicator.setBoxShadow(view, shadows);
269-
}
238+
BackgroundStyleApplicator.setBoxShadow(view, shadows);
270239
}
271240

272241
@Override
273242
public void setBackgroundColor(T view, @ColorInt int backgroundColor) {
274-
if (ReactNativeFeatureFlags.enableBackgroundStyleApplicator()) {
275-
BackgroundStyleApplicator.setBackgroundColor(view, backgroundColor);
276-
} else {
277-
super.setBackgroundColor(view, backgroundColor);
278-
}
243+
BackgroundStyleApplicator.setBackgroundColor(view, backgroundColor);
279244
}
280245
}

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/text/ReactTextView.java

Lines changed: 16 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636
import com.facebook.react.bridge.WritableMap;
3737
import com.facebook.react.common.ReactConstants;
3838
import com.facebook.react.internal.SystraceSection;
39-
import com.facebook.react.internal.featureflags.ReactNativeFeatureFlags;
4039
import com.facebook.react.uimanager.BackgroundStyleApplicator;
4140
import com.facebook.react.uimanager.LengthPercentage;
4241
import com.facebook.react.uimanager.LengthPercentageType;
@@ -53,7 +52,6 @@
5352
import com.facebook.react.views.text.internal.span.ReactTagSpan;
5453
import com.facebook.react.views.text.internal.span.TextInlineImageSpan;
5554
import com.facebook.react.views.text.internal.span.TextInlineViewPlaceholderSpan;
56-
import com.facebook.react.views.view.ReactViewBackgroundManager;
5755
import com.facebook.yoga.YogaMeasureMode;
5856
import java.util.ArrayList;
5957
import java.util.Collections;
@@ -80,7 +78,6 @@ public class ReactTextView extends AppCompatTextView implements ReactCompoundVie
8078
private boolean mShouldAdjustSpannableFontSize;
8179
private Overflow mOverflow = Overflow.VISIBLE;
8280

83-
private ReactViewBackgroundManager mReactBackgroundManager;
8481
private Spannable mSpanned;
8582

8683
public ReactTextView(Context context) {
@@ -94,12 +91,6 @@ public ReactTextView(Context context) {
9491
* ReactTextView is recycled.
9592
*/
9693
private void initView() {
97-
if (mReactBackgroundManager != null) {
98-
// make sure old background manager doesn't have any references back to this View
99-
mReactBackgroundManager.cleanup();
100-
}
101-
mReactBackgroundManager = new ReactViewBackgroundManager(this);
102-
10394
mNumberOfLines = ViewDefaults.NUMBER_OF_LINES;
10495
mAdjustsFontSizeToFit = false;
10596
mLinkifyMaskType = 0;
@@ -118,9 +109,7 @@ private void initView() {
118109
// Set default field values
119110
initView();
120111

121-
if (ReactNativeFeatureFlags.enableBackgroundStyleApplicator()) {
122-
BackgroundStyleApplicator.reset(this);
123-
}
112+
BackgroundStyleApplicator.reset(this);
124113

125114
// Defaults for these fields:
126115
// https://github.com/aosp-mirror/platform_frameworks_base/blob/master/core/java/android/widget/TextView.java#L1061
@@ -396,12 +385,8 @@ protected void onDraw(Canvas canvas) {
396385
setText(getSpanned());
397386
}
398387

399-
if (ReactNativeFeatureFlags.enableBackgroundStyleApplicator()) {
400-
if (mOverflow != Overflow.VISIBLE) {
401-
BackgroundStyleApplicator.clipToPaddingBox(this, canvas);
402-
}
403-
} else {
404-
mReactBackgroundManager.maybeClipToPaddingBox(canvas);
388+
if (mOverflow != Overflow.VISIBLE) {
389+
BackgroundStyleApplicator.clipToPaddingBox(this, canvas);
405390
}
406391

407392
super.onDraw(canvas);
@@ -709,55 +694,35 @@ public void updateView() {
709694

710695
@Override
711696
public void setBackgroundColor(int color) {
712-
if (ReactNativeFeatureFlags.enableBackgroundStyleApplicator()) {
713-
BackgroundStyleApplicator.setBackgroundColor(this, color);
714-
} else {
715-
mReactBackgroundManager.setBackgroundColor(color);
716-
}
697+
BackgroundStyleApplicator.setBackgroundColor(this, color);
717698
}
718699

719700
public void setBorderWidth(int position, float width) {
720-
if (ReactNativeFeatureFlags.enableBackgroundStyleApplicator()) {
721-
BackgroundStyleApplicator.setBorderWidth(
722-
this, LogicalEdge.values()[position], PixelUtil.toDIPFromPixel(width));
723-
} else {
724-
mReactBackgroundManager.setBorderWidth(position, width);
725-
}
701+
BackgroundStyleApplicator.setBorderWidth(
702+
this, LogicalEdge.values()[position], PixelUtil.toDIPFromPixel(width));
726703
}
727704

728705
public void setBorderColor(int position, @Nullable Integer color) {
729-
if (ReactNativeFeatureFlags.enableBackgroundStyleApplicator()) {
730-
BackgroundStyleApplicator.setBorderColor(this, LogicalEdge.values()[position], color);
731-
} else {
732-
mReactBackgroundManager.setBorderColor(position, color);
733-
}
706+
BackgroundStyleApplicator.setBorderColor(this, LogicalEdge.values()[position], color);
734707
}
735708

736709
public void setBorderRadius(float borderRadius) {
737710
setBorderRadius(borderRadius, BorderRadiusProp.BORDER_RADIUS.ordinal());
738711
}
739712

740713
public void setBorderRadius(float borderRadius, int position) {
741-
if (ReactNativeFeatureFlags.enableBackgroundStyleApplicator()) {
742-
@Nullable
743-
LengthPercentage radius =
744-
Float.isNaN(borderRadius)
745-
? null
746-
: new LengthPercentage(
747-
PixelUtil.toDIPFromPixel(borderRadius), LengthPercentageType.POINT);
748-
BackgroundStyleApplicator.setBorderRadius(this, BorderRadiusProp.values()[position], radius);
749-
} else {
750-
mReactBackgroundManager.setBorderRadius(borderRadius, position);
751-
}
714+
@Nullable
715+
LengthPercentage radius =
716+
Float.isNaN(borderRadius)
717+
? null
718+
: new LengthPercentage(
719+
PixelUtil.toDIPFromPixel(borderRadius), LengthPercentageType.POINT);
720+
BackgroundStyleApplicator.setBorderRadius(this, BorderRadiusProp.values()[position], radius);
752721
}
753722

754723
public void setBorderStyle(@Nullable String style) {
755-
if (ReactNativeFeatureFlags.enableBackgroundStyleApplicator()) {
756-
BackgroundStyleApplicator.setBorderStyle(
757-
this, style == null ? null : BorderStyle.fromString(style));
758-
} else {
759-
mReactBackgroundManager.setBorderStyle(style);
760-
}
724+
BackgroundStyleApplicator.setBorderStyle(
725+
this, style == null ? null : BorderStyle.fromString(style));
761726
}
762727

763728
public void setSpanned(Spannable spanned) {
@@ -810,7 +775,6 @@ public void setOverflow(@Nullable String overflow) {
810775
mOverflow = parsedOverflow == null ? Overflow.VISIBLE : parsedOverflow;
811776
}
812777

813-
mReactBackgroundManager.setOverflow(overflow);
814778
invalidate();
815779
}
816780
}

0 commit comments

Comments
 (0)