remove ViewHelper, use ViewCompat instead (#23280)
Summary: ViewHelper has only setBackground method which works identical to ViewCompat.setBackground from Android Support Library. This PR removes ViewHelper, and uses ViewCompat instead. [Android] [Changed] - remove ViewHelper, use ViewCompat instead Pull Request resolved: https://github.com/facebook/react-native/pull/23280 Differential Revision: D13950510 Pulled By: mdvacca fbshipit-source-id: 10b5122affac17d4b66fb995339c6715c0871ed0
This commit is contained in:
parent
05ebf77175
commit
c493cfe708
|
@ -1,31 +0,0 @@
|
|||
// Copyright (c) Facebook, Inc. and its 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.common;
|
||||
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.os.Build;
|
||||
import android.view.View;
|
||||
|
||||
/** Helper class for Views */
|
||||
public class ViewHelper {
|
||||
|
||||
/**
|
||||
* Set the background to a given Drawable, or remove the background. It calls {@link
|
||||
* View#setBackground(Drawable)} or {@link View#setBackgroundDrawable(Drawable)} based on the sdk
|
||||
* version.
|
||||
*
|
||||
* @param view {@link View} to apply the background.
|
||||
* @param drawable {@link Drawable} The Drawable to use as the background, or null to remove the
|
||||
* background
|
||||
*/
|
||||
public static void setBackground(View view, Drawable drawable) {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
|
||||
view.setBackground(drawable);
|
||||
} else {
|
||||
view.setBackgroundDrawable(drawable);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -6,6 +6,9 @@ rn_android_library(
|
|||
visibility = [
|
||||
"PUBLIC",
|
||||
],
|
||||
provided_deps = [
|
||||
react_native_dep("third-party/android/support/v4:lib-support-v4"),
|
||||
],
|
||||
deps = [
|
||||
YOGA_TARGET,
|
||||
react_native_dep("libraries/fbcore/src/main/java/com/facebook/common/logging:logging"),
|
||||
|
|
|
@ -8,8 +8,8 @@ package com.facebook.react.views.view;
|
|||
import android.graphics.Color;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.graphics.drawable.LayerDrawable;
|
||||
import android.support.v4.view.ViewCompat;
|
||||
import android.view.View;
|
||||
import com.facebook.react.views.common.ViewHelper;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
/** Class that manages the background for views and borders. */
|
||||
|
@ -26,15 +26,15 @@ public class ReactViewBackgroundManager {
|
|||
if (mReactBackgroundDrawable == null) {
|
||||
mReactBackgroundDrawable = new ReactViewBackgroundDrawable(mView.getContext());
|
||||
Drawable backgroundDrawable = mView.getBackground();
|
||||
ViewHelper.setBackground(
|
||||
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) {
|
||||
ViewHelper.setBackground(mView, mReactBackgroundDrawable);
|
||||
ViewCompat.setBackground(mView, mReactBackgroundDrawable);
|
||||
} else {
|
||||
LayerDrawable layerDrawable =
|
||||
new LayerDrawable(new Drawable[] {mReactBackgroundDrawable, backgroundDrawable});
|
||||
ViewHelper.setBackground(mView, layerDrawable);
|
||||
ViewCompat.setBackground(mView, layerDrawable);
|
||||
}
|
||||
}
|
||||
return mReactBackgroundDrawable;
|
||||
|
|
Loading…
Reference in New Issue