From e58d3005147f17fae7d0364de8e45ca330d6bc3f Mon Sep 17 00:00:00 2001 From: Nick Gerleman Date: Mon, 16 Sep 2024 19:14:53 -0700 Subject: [PATCH] Remove ReactHorizontalScrollView Legacy Background Path (#46161) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/46161 ## This Diff This removes the legacy path from ReactHorizontalScrollView 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: D61658082 fbshipit-source-id: 98cab5dfcad8beee6d131fcfe122313730a6f665 --- .../scroll/ReactHorizontalScrollView.java | 60 +++++------------- .../ReactHorizontalScrollViewManager.java | 62 +++++-------------- 2 files changed, 29 insertions(+), 93 deletions(-) diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/scroll/ReactHorizontalScrollView.java b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/scroll/ReactHorizontalScrollView.java index f9ab9492e75..919777a11fd 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/scroll/ReactHorizontalScrollView.java +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/scroll/ReactHorizontalScrollView.java @@ -49,7 +49,6 @@ import com.facebook.react.uimanager.ReactClippingViewGroup; import com.facebook.react.uimanager.ReactClippingViewGroupHelper; import com.facebook.react.uimanager.ReactOverflowViewWithInset; import com.facebook.react.uimanager.StateWrapper; -import com.facebook.react.uimanager.ViewProps; import com.facebook.react.uimanager.events.NativeGestureUtil; import com.facebook.react.uimanager.style.BorderRadiusProp; import com.facebook.react.uimanager.style.BorderStyle; @@ -61,7 +60,6 @@ import com.facebook.react.views.scroll.ReactScrollViewHelper.HasScrollState; import com.facebook.react.views.scroll.ReactScrollViewHelper.HasSmoothScroll; import com.facebook.react.views.scroll.ReactScrollViewHelper.HasStateWrapper; import com.facebook.react.views.scroll.ReactScrollViewHelper.ReactScrollViewScrollState; -import com.facebook.react.views.view.ReactViewBackgroundManager; import com.facebook.systrace.Systrace; import java.lang.reflect.Field; import java.util.ArrayList; @@ -118,7 +116,6 @@ public class ReactHorizontalScrollView extends HorizontalScrollView private boolean mSnapToStart = true; private boolean mSnapToEnd = true; private int mSnapToAlignment = SNAP_ALIGNMENT_DISABLED; - private ReactViewBackgroundManager mReactBackgroundManager; private boolean mPagedArrowScrolling = false; private int pendingContentOffsetX = UNSET_CONTENT_OFFSET; private int pendingContentOffsetY = UNSET_CONTENT_OFFSET; @@ -139,7 +136,6 @@ public class ReactHorizontalScrollView extends HorizontalScrollView public ReactHorizontalScrollView(Context context, @Nullable FpsListener fpsListener) { super(context); - mReactBackgroundManager = new ReactViewBackgroundManager(this); mFpsListener = fpsListener; ViewCompat.setAccessibilityDelegate(this, new ReactScrollViewAccessibilityDelegate()); @@ -155,7 +151,6 @@ public class ReactHorizontalScrollView extends HorizontalScrollView setOnHierarchyChangeListener(this); setClipChildren(false); - mReactBackgroundManager.setOverflow(ViewProps.SCROLL); } public boolean getScrollEnabled() { @@ -290,7 +285,6 @@ public class ReactHorizontalScrollView extends HorizontalScrollView mOverflow = parsedOverflow == null ? Overflow.SCROLL : parsedOverflow; } - mReactBackgroundManager.setOverflow(overflow == null ? ViewProps.SCROLL : overflow); invalidate(); } @@ -334,12 +328,8 @@ public class ReactHorizontalScrollView extends HorizontalScrollView @Override public void onDraw(Canvas canvas) { - if (ReactNativeFeatureFlags.enableBackgroundStyleApplicator()) { - if (mOverflow != Overflow.VISIBLE) { - BackgroundStyleApplicator.clipToPaddingBox(this, canvas); - } - } else { - mReactBackgroundManager.maybeClipToPaddingBox(canvas); + if (mOverflow != Overflow.VISIBLE) { + BackgroundStyleApplicator.clipToPaddingBox(this, canvas); } super.onDraw(canvas); } @@ -1330,28 +1320,16 @@ public class ReactHorizontalScrollView extends HorizontalScrollView @Override public void setBackgroundColor(int color) { - if (ReactNativeFeatureFlags.enableBackgroundStyleApplicator()) { - BackgroundStyleApplicator.setBackgroundColor(this, color); - } else { - mReactBackgroundManager.setBackgroundColor(color); - } + BackgroundStyleApplicator.setBackgroundColor(this, color); } public void setBorderWidth(int position, float width) { - if (ReactNativeFeatureFlags.enableBackgroundStyleApplicator()) { - BackgroundStyleApplicator.setBorderWidth( - this, LogicalEdge.values()[position], PixelUtil.toDIPFromPixel(width)); - } else { - mReactBackgroundManager.setBorderWidth(position, width); - } + BackgroundStyleApplicator.setBorderWidth( + this, LogicalEdge.values()[position], PixelUtil.toDIPFromPixel(width)); } public void setBorderColor(int position, @Nullable Integer color) { - if (ReactNativeFeatureFlags.enableBackgroundStyleApplicator()) { - BackgroundStyleApplicator.setBorderColor(this, LogicalEdge.values()[position], color); - } else { - mReactBackgroundManager.setBorderColor(position, color); - } + BackgroundStyleApplicator.setBorderColor(this, LogicalEdge.values()[position], color); } public void setBorderRadius(float borderRadius) { @@ -1359,26 +1337,18 @@ public class ReactHorizontalScrollView extends HorizontalScrollView } public void setBorderRadius(float borderRadius, int position) { - if (ReactNativeFeatureFlags.enableBackgroundStyleApplicator()) { - @Nullable - LengthPercentage radius = - Float.isNaN(borderRadius) - ? null - : new LengthPercentage( - PixelUtil.toDIPFromPixel(borderRadius), LengthPercentageType.POINT); - BackgroundStyleApplicator.setBorderRadius(this, BorderRadiusProp.values()[position], radius); - } else { - mReactBackgroundManager.setBorderRadius(borderRadius, position); - } + @Nullable + LengthPercentage radius = + Float.isNaN(borderRadius) + ? null + : new LengthPercentage( + PixelUtil.toDIPFromPixel(borderRadius), LengthPercentageType.POINT); + BackgroundStyleApplicator.setBorderRadius(this, BorderRadiusProp.values()[position], radius); } public void setBorderStyle(@Nullable String style) { - if (ReactNativeFeatureFlags.enableBackgroundStyleApplicator()) { - BackgroundStyleApplicator.setBorderStyle( - this, style == null ? null : BorderStyle.fromString(style)); - } else { - mReactBackgroundManager.setBorderStyle(style); - } + BackgroundStyleApplicator.setBorderStyle( + this, style == null ? null : BorderStyle.fromString(style)); } /** diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/scroll/ReactHorizontalScrollViewManager.java b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/scroll/ReactHorizontalScrollViewManager.java index 861ee180a91..1828ff0eac5 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/scroll/ReactHorizontalScrollViewManager.java +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/scroll/ReactHorizontalScrollViewManager.java @@ -16,7 +16,6 @@ import com.facebook.infer.annotation.Nullsafe; import com.facebook.react.bridge.ReadableArray; import com.facebook.react.bridge.ReadableMap; import com.facebook.react.bridge.RetryableMountingLayerException; -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.LengthPercentage; @@ -264,36 +263,20 @@ public class ReactHorizontalScrollViewManager extends ViewGroupManager