Skip to content

Commit 0fa7e01

Browse files
NickGerlemanfacebook-github-bot
authored andcommitted
Remove ReactScrollView Legacy Background Path (facebook#46168)
Summary: Pull Request resolved: facebook#46168 ## This Diff This removes the legacy path from ReactScrollView 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: tdn120 Differential Revision: D61658081 fbshipit-source-id: d6db43e25faf8e1ebd42d2816c7a915b3ed9404e
1 parent e58d300 commit 0fa7e01

File tree

2 files changed

+29
-95
lines changed

2 files changed

+29
-95
lines changed

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/scroll/ReactScrollView.java

Lines changed: 15 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@
3939
import com.facebook.react.bridge.ReactContext;
4040
import com.facebook.react.bridge.ReadableMap;
4141
import com.facebook.react.common.ReactConstants;
42-
import com.facebook.react.internal.featureflags.ReactNativeFeatureFlags;
4342
import com.facebook.react.uimanager.BackgroundStyleApplicator;
4443
import com.facebook.react.uimanager.LengthPercentage;
4544
import com.facebook.react.uimanager.LengthPercentageType;
@@ -50,7 +49,6 @@
5049
import com.facebook.react.uimanager.ReactClippingViewGroupHelper;
5150
import com.facebook.react.uimanager.ReactOverflowViewWithInset;
5251
import com.facebook.react.uimanager.StateWrapper;
53-
import com.facebook.react.uimanager.ViewProps;
5452
import com.facebook.react.uimanager.events.NativeGestureUtil;
5553
import com.facebook.react.uimanager.style.BorderRadiusProp;
5654
import com.facebook.react.uimanager.style.BorderStyle;
@@ -62,7 +60,6 @@
6260
import com.facebook.react.views.scroll.ReactScrollViewHelper.HasSmoothScroll;
6361
import com.facebook.react.views.scroll.ReactScrollViewHelper.HasStateWrapper;
6462
import com.facebook.react.views.scroll.ReactScrollViewHelper.ReactScrollViewScrollState;
65-
import com.facebook.react.views.view.ReactViewBackgroundManager;
6663
import com.facebook.systrace.Systrace;
6764
import java.lang.reflect.Field;
6865
import java.util.List;
@@ -119,7 +116,6 @@ public class ReactScrollView extends ScrollView
119116
private boolean mSnapToEnd = true;
120117
private int mSnapToAlignment = SNAP_ALIGNMENT_DISABLED;
121118
private @Nullable View mContentView;
122-
private ReactViewBackgroundManager mReactBackgroundManager;
123119
private @Nullable ReadableMap mCurrentContentOffset = null;
124120
private int pendingContentOffsetX = UNSET_CONTENT_OFFSET;
125121
private int pendingContentOffsetY = UNSET_CONTENT_OFFSET;
@@ -140,13 +136,11 @@ public ReactScrollView(Context context) {
140136
public ReactScrollView(Context context, @Nullable FpsListener fpsListener) {
141137
super(context);
142138
mFpsListener = fpsListener;
143-
mReactBackgroundManager = new ReactViewBackgroundManager(this);
144139

145140
mScroller = getOverScrollerFromParent();
146141
setOnHierarchyChangeListener(this);
147142
setScrollBarStyle(SCROLLBARS_OUTSIDE_OVERLAY);
148143
setClipChildren(false);
149-
mReactBackgroundManager.setOverflow(ViewProps.SCROLL);
150144

151145
ViewCompat.setAccessibilityDelegate(this, new ReactScrollViewAccessibilityDelegate());
152146
}
@@ -278,7 +272,6 @@ public void setOverflow(@Nullable String overflow) {
278272
mOverflow = parsedOverflow == null ? Overflow.SCROLL : parsedOverflow;
279273
}
280274

281-
mReactBackgroundManager.setOverflow(overflow == null ? ViewProps.SCROLL : overflow);
282275
invalidate();
283276
}
284277

@@ -684,12 +677,8 @@ public void draw(Canvas canvas) {
684677

685678
@Override
686679
public void onDraw(Canvas canvas) {
687-
if (ReactNativeFeatureFlags.enableBackgroundStyleApplicator()) {
688-
if (mOverflow != Overflow.VISIBLE) {
689-
BackgroundStyleApplicator.clipToPaddingBox(this, canvas);
690-
}
691-
} else {
692-
mReactBackgroundManager.maybeClipToPaddingBox(canvas);
680+
if (mOverflow != Overflow.VISIBLE) {
681+
BackgroundStyleApplicator.clipToPaddingBox(this, canvas);
693682
}
694683
super.onDraw(canvas);
695684
}
@@ -1261,55 +1250,35 @@ public void onLayoutChange(
12611250

12621251
@Override
12631252
public void setBackgroundColor(int color) {
1264-
if (ReactNativeFeatureFlags.enableBackgroundStyleApplicator()) {
1265-
BackgroundStyleApplicator.setBackgroundColor(this, color);
1266-
} else {
1267-
mReactBackgroundManager.setBackgroundColor(color);
1268-
}
1253+
BackgroundStyleApplicator.setBackgroundColor(this, color);
12691254
}
12701255

12711256
public void setBorderWidth(int position, float width) {
1272-
if (ReactNativeFeatureFlags.enableBackgroundStyleApplicator()) {
1273-
BackgroundStyleApplicator.setBorderWidth(
1274-
this, LogicalEdge.values()[position], PixelUtil.toDIPFromPixel(width));
1275-
} else {
1276-
mReactBackgroundManager.setBorderWidth(position, width);
1277-
}
1257+
BackgroundStyleApplicator.setBorderWidth(
1258+
this, LogicalEdge.values()[position], PixelUtil.toDIPFromPixel(width));
12781259
}
12791260

12801261
public void setBorderColor(int position, @Nullable Integer color) {
1281-
if (ReactNativeFeatureFlags.enableBackgroundStyleApplicator()) {
1282-
BackgroundStyleApplicator.setBorderColor(this, LogicalEdge.values()[position], color);
1283-
} else {
1284-
mReactBackgroundManager.setBorderColor(position, color);
1285-
}
1262+
BackgroundStyleApplicator.setBorderColor(this, LogicalEdge.values()[position], color);
12861263
}
12871264

12881265
public void setBorderRadius(float borderRadius) {
12891266
setBorderRadius(borderRadius, BorderRadiusProp.BORDER_RADIUS.ordinal());
12901267
}
12911268

12921269
public void setBorderRadius(float borderRadius, int position) {
1293-
if (ReactNativeFeatureFlags.enableBackgroundStyleApplicator()) {
1294-
@Nullable
1295-
LengthPercentage radius =
1296-
Float.isNaN(borderRadius)
1297-
? null
1298-
: new LengthPercentage(
1299-
PixelUtil.toDIPFromPixel(borderRadius), LengthPercentageType.POINT);
1300-
BackgroundStyleApplicator.setBorderRadius(this, BorderRadiusProp.values()[position], radius);
1301-
} else {
1302-
mReactBackgroundManager.setBorderRadius(borderRadius, position);
1303-
}
1270+
@Nullable
1271+
LengthPercentage radius =
1272+
Float.isNaN(borderRadius)
1273+
? null
1274+
: new LengthPercentage(
1275+
PixelUtil.toDIPFromPixel(borderRadius), LengthPercentageType.POINT);
1276+
BackgroundStyleApplicator.setBorderRadius(this, BorderRadiusProp.values()[position], radius);
13041277
}
13051278

13061279
public void setBorderStyle(@Nullable String style) {
1307-
if (ReactNativeFeatureFlags.enableBackgroundStyleApplicator()) {
1308-
BackgroundStyleApplicator.setBorderStyle(
1309-
this, style == null ? null : BorderStyle.fromString(style));
1310-
} else {
1311-
mReactBackgroundManager.setBorderStyle(style);
1312-
}
1280+
BackgroundStyleApplicator.setBorderStyle(
1281+
this, style == null ? null : BorderStyle.fromString(style));
13131282
}
13141283

13151284
/**

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/scroll/ReactScrollViewManager.java

Lines changed: 14 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
import com.facebook.react.bridge.ReadableMap;
1818
import com.facebook.react.bridge.RetryableMountingLayerException;
1919
import com.facebook.react.common.MapBuilder;
20-
import com.facebook.react.internal.featureflags.ReactNativeFeatureFlags;
2120
import com.facebook.react.module.annotations.ReactModule;
2221
import com.facebook.react.uimanager.BackgroundStyleApplicator;
2322
import com.facebook.react.uimanager.LengthPercentage;
@@ -245,36 +244,20 @@ public void scrollTo(
245244
},
246245
defaultFloat = Float.NaN)
247246
public void setBorderRadius(ReactScrollView view, int index, float borderRadius) {
248-
if (ReactNativeFeatureFlags.enableBackgroundStyleApplicator()) {
249-
@Nullable
250-
LengthPercentage radius =
251-
Float.isNaN(borderRadius)
252-
? null
253-
: new LengthPercentage(borderRadius, LengthPercentageType.POINT);
254-
BackgroundStyleApplicator.setBorderRadius(view, BorderRadiusProp.values()[index], radius);
255-
} else {
256-
if (!Float.isNaN(borderRadius)) {
257-
borderRadius = PixelUtil.toPixelFromDIP(borderRadius);
258-
}
259-
260-
if (index == 0) {
261-
view.setBorderRadius(borderRadius);
262-
} else {
263-
view.setBorderRadius(borderRadius, index - 1);
264-
}
265-
}
247+
@Nullable
248+
LengthPercentage radius =
249+
Float.isNaN(borderRadius)
250+
? null
251+
: new LengthPercentage(borderRadius, LengthPercentageType.POINT);
252+
BackgroundStyleApplicator.setBorderRadius(view, BorderRadiusProp.values()[index], radius);
266253
}
267254

268255
@ReactProp(name = "borderStyle")
269256
public void setBorderStyle(ReactScrollView view, @Nullable String borderStyle) {
270-
if (ReactNativeFeatureFlags.enableBackgroundStyleApplicator()) {
271-
@Nullable
272-
BorderStyle parsedBorderStyle =
273-
borderStyle == null ? null : BorderStyle.fromString(borderStyle);
274-
BackgroundStyleApplicator.setBorderStyle(view, parsedBorderStyle);
275-
} else {
276-
view.setBorderStyle(borderStyle);
277-
}
257+
@Nullable
258+
BorderStyle parsedBorderStyle =
259+
borderStyle == null ? null : BorderStyle.fromString(borderStyle);
260+
BackgroundStyleApplicator.setBorderStyle(view, parsedBorderStyle);
278261
}
279262

280263
@ReactPropGroup(
@@ -287,15 +270,7 @@ public void setBorderStyle(ReactScrollView view, @Nullable String borderStyle) {
287270
},
288271
defaultFloat = Float.NaN)
289272
public void setBorderWidth(ReactScrollView view, int index, float width) {
290-
if (ReactNativeFeatureFlags.enableBackgroundStyleApplicator()) {
291-
BackgroundStyleApplicator.setBorderWidth(view, LogicalEdge.values()[index], width);
292-
} else {
293-
if (!Float.isNaN(width)) {
294-
width = PixelUtil.toPixelFromDIP(width);
295-
}
296-
297-
view.setBorderWidth(SPACING_TYPES[index], width);
298-
}
273+
BackgroundStyleApplicator.setBorderWidth(view, LogicalEdge.values()[index], width);
299274
}
300275

301276
@ReactPropGroup(
@@ -308,11 +283,7 @@ public void setBorderWidth(ReactScrollView view, int index, float width) {
308283
},
309284
customType = "Color")
310285
public void setBorderColor(ReactScrollView view, int index, @Nullable Integer color) {
311-
if (ReactNativeFeatureFlags.enableBackgroundStyleApplicator()) {
312-
BackgroundStyleApplicator.setBorderColor(view, LogicalEdge.ALL, color);
313-
} else {
314-
view.setBorderColor(SPACING_TYPES[index], color);
315-
}
286+
BackgroundStyleApplicator.setBorderColor(view, LogicalEdge.ALL, color);
316287
}
317288

318289
@ReactProp(name = "overflow")
@@ -374,18 +345,12 @@ public void setMaintainVisibleContentPosition(ReactScrollView view, ReadableMap
374345

375346
@ReactProp(name = ViewProps.BOX_SHADOW, customType = "BoxShadow")
376347
public void setBoxShadow(ReactScrollView view, @Nullable ReadableArray shadows) {
377-
if (ReactNativeFeatureFlags.enableBackgroundStyleApplicator()) {
378-
BackgroundStyleApplicator.setBoxShadow(view, shadows);
379-
}
348+
BackgroundStyleApplicator.setBoxShadow(view, shadows);
380349
}
381350

382351
@Override
383352
public void setBackgroundColor(ReactScrollView view, @ColorInt int backgroundColor) {
384-
if (ReactNativeFeatureFlags.enableBackgroundStyleApplicator()) {
385-
BackgroundStyleApplicator.setBackgroundColor(view, backgroundColor);
386-
} else {
387-
super.setBackgroundColor(view, backgroundColor);
388-
}
353+
BackgroundStyleApplicator.setBackgroundColor(view, backgroundColor);
389354
}
390355

391356
@Override

0 commit comments

Comments
 (0)