mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Breaking: Remove ReactViewBackgroundManager and ReactViewBackgroundDrawable (#46166)
Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/46166 ## This Diff This removes some of the legacy utilties used for background manipulation, no longer used anywhere (and very rarely used externally from some previous tests). These conflict with BackgroundStyleApplicator, which should be used instead. ## 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: [Android][Breaking] - Remove ReactViewBackgroundManager and ReactViewBackgroundDrawable Reviewed By: sammy-SC Differential Revision: D61658084 fbshipit-source-id: 611f6d78fa4859574c063e9f0395c3dadc1588cc
This commit is contained in:
committed by
Facebook GitHub Bot
parent
0fa7e01c5f
commit
51673e41ae
@@ -8315,10 +8315,6 @@ public class com/facebook/react/views/view/ReactDrawableHelper {
|
||||
public static fun createDrawableFromJSDescription (Landroid/content/Context;Lcom/facebook/react/bridge/ReadableMap;)Landroid/graphics/drawable/Drawable;
|
||||
}
|
||||
|
||||
public class com/facebook/react/views/view/ReactViewBackgroundDrawable : com/facebook/react/uimanager/drawable/CSSBackgroundDrawable {
|
||||
public fun <init> (Landroid/content/Context;)V
|
||||
}
|
||||
|
||||
public class com/facebook/react/views/view/ReactViewGroup : android/view/ViewGroup, com/facebook/react/touch/ReactHitSlopView, com/facebook/react/touch/ReactInterceptingViewGroup, com/facebook/react/uimanager/ReactClippingViewGroup, com/facebook/react/uimanager/ReactOverflowViewWithInset, com/facebook/react/uimanager/ReactPointerEventsView, com/facebook/react/uimanager/ReactZIndexedViewGroup {
|
||||
public fun <init> (Landroid/content/Context;)V
|
||||
public fun addView (Landroid/view/View;ILandroid/view/ViewGroup$LayoutParams;)V
|
||||
|
||||
-25
@@ -1,25 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
package com.facebook.react.views.view;
|
||||
|
||||
import android.content.Context;
|
||||
import com.facebook.react.uimanager.drawable.CSSBackgroundDrawable;
|
||||
|
||||
/**
|
||||
* @deprecated Please use {@link CSSBackgroundDrawable} instead
|
||||
*/
|
||||
@Deprecated(since = "0.75.0", forRemoval = true)
|
||||
public class ReactViewBackgroundDrawable extends CSSBackgroundDrawable {
|
||||
/**
|
||||
* @deprecated Please use {@link CSSBackgroundDrawable} instead
|
||||
*/
|
||||
@Deprecated(since = "0.75.0", forRemoval = true)
|
||||
public ReactViewBackgroundDrawable(Context context) {
|
||||
super(context);
|
||||
}
|
||||
}
|
||||
-146
@@ -1,146 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
package com.facebook.react.views.view;
|
||||
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.Path;
|
||||
import android.graphics.Rect;
|
||||
import android.graphics.RectF;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.graphics.drawable.LayerDrawable;
|
||||
import android.view.View;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.core.view.ViewCompat;
|
||||
import com.facebook.react.common.annotations.UnstableReactNativeAPI;
|
||||
import com.facebook.react.uimanager.drawable.CSSBackgroundDrawable;
|
||||
|
||||
/** Class that manages the background for views and borders. */
|
||||
@UnstableReactNativeAPI
|
||||
public class ReactViewBackgroundManager {
|
||||
private static enum Overflow {
|
||||
VISIBLE,
|
||||
HIDDEN,
|
||||
SCROLL,
|
||||
}
|
||||
|
||||
private @Nullable CSSBackgroundDrawable mCSSBackgroundDrawable;
|
||||
private View mView;
|
||||
private int mColor = Color.TRANSPARENT;
|
||||
private Overflow mOverflow = Overflow.VISIBLE;
|
||||
|
||||
public ReactViewBackgroundManager(View view) {
|
||||
mView = view;
|
||||
}
|
||||
|
||||
public void cleanup() {
|
||||
ViewCompat.setBackground(mView, null);
|
||||
mView = null;
|
||||
mCSSBackgroundDrawable = null;
|
||||
}
|
||||
|
||||
private CSSBackgroundDrawable getOrCreateReactViewBackground() {
|
||||
if (mCSSBackgroundDrawable == null) {
|
||||
mCSSBackgroundDrawable = new CSSBackgroundDrawable(mView.getContext());
|
||||
Drawable backgroundDrawable = mView.getBackground();
|
||||
ViewCompat.setBackground(
|
||||
mView, null); // required so that drawable callback is cleared before we add the
|
||||
// drawable back as a part of LayerDrawable
|
||||
if (backgroundDrawable == null) {
|
||||
ViewCompat.setBackground(mView, mCSSBackgroundDrawable);
|
||||
} else {
|
||||
LayerDrawable layerDrawable =
|
||||
new LayerDrawable(new Drawable[] {mCSSBackgroundDrawable, backgroundDrawable});
|
||||
ViewCompat.setBackground(mView, layerDrawable);
|
||||
}
|
||||
}
|
||||
return mCSSBackgroundDrawable;
|
||||
}
|
||||
|
||||
public void setBackgroundColor(int color) {
|
||||
if (color == Color.TRANSPARENT && mCSSBackgroundDrawable == null) {
|
||||
// don't do anything, no need to allocate ReactBackgroundDrawable for transparent background
|
||||
} else {
|
||||
getOrCreateReactViewBackground().setColor(color);
|
||||
}
|
||||
}
|
||||
|
||||
public int getBackgroundColor() {
|
||||
return mColor;
|
||||
}
|
||||
|
||||
public void setBorderWidth(int position, float width) {
|
||||
getOrCreateReactViewBackground().setBorderWidth(position, width);
|
||||
}
|
||||
|
||||
public void setBorderColor(int position, @Nullable Integer color) {
|
||||
getOrCreateReactViewBackground().setBorderColor(position, color);
|
||||
}
|
||||
|
||||
public int getBorderColor(int position) {
|
||||
return getOrCreateReactViewBackground().getBorderColor(position);
|
||||
}
|
||||
|
||||
public void setBorderRadius(float borderRadius) {
|
||||
getOrCreateReactViewBackground().setRadius(borderRadius);
|
||||
}
|
||||
|
||||
public void setBorderRadius(float borderRadius, int position) {
|
||||
getOrCreateReactViewBackground().setRadius(borderRadius, position);
|
||||
}
|
||||
|
||||
public void setBorderStyle(@Nullable String style) {
|
||||
getOrCreateReactViewBackground().setBorderStyle(style);
|
||||
}
|
||||
|
||||
public void setOverflow(@Nullable String overflow) {
|
||||
Overflow lastOverflow = mOverflow;
|
||||
|
||||
if ("hidden".equals(overflow)) {
|
||||
mOverflow = Overflow.HIDDEN;
|
||||
} else if ("scroll".equals(overflow)) {
|
||||
mOverflow = Overflow.SCROLL;
|
||||
} else {
|
||||
mOverflow = Overflow.VISIBLE;
|
||||
}
|
||||
|
||||
if (lastOverflow != mOverflow) {
|
||||
mView.invalidate();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the canvas clipping region to exclude any area below or outside of borders if "overflow"
|
||||
* is set to clip to padding box.
|
||||
*/
|
||||
public void maybeClipToPaddingBox(Canvas canvas) {
|
||||
if (mOverflow == Overflow.VISIBLE) {
|
||||
return;
|
||||
}
|
||||
|
||||
// The canvas may be scrolled, so we need to offset
|
||||
Rect drawingRect = new Rect();
|
||||
mView.getDrawingRect(drawingRect);
|
||||
|
||||
@Nullable CSSBackgroundDrawable cssBackground = mCSSBackgroundDrawable;
|
||||
if (cssBackground == null) {
|
||||
canvas.clipRect(drawingRect);
|
||||
return;
|
||||
}
|
||||
|
||||
@Nullable Path paddingBoxPath = cssBackground.getPaddingBoxPath();
|
||||
if (paddingBoxPath != null) {
|
||||
paddingBoxPath.offset(drawingRect.left, drawingRect.top);
|
||||
canvas.clipPath(paddingBoxPath);
|
||||
} else {
|
||||
RectF paddingBoxRect = cssBackground.getPaddingBoxRect();
|
||||
paddingBoxRect.offset(drawingRect.left, drawingRect.top);
|
||||
canvas.clipRect(paddingBoxRect);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user