-
Notifications
You must be signed in to change notification settings - Fork 24.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix setBackground for Android sdk version 15 and below
Reviewed By: achen1 Differential Revision: D5854430 fbshipit-source-id: 1276f3d7e94b757f9a9dd412a2ef8b72e8427ffb
- Loading branch information
1 parent
87a1dc4
commit 5180995
Showing
9 changed files
with
180 additions
and
140 deletions.
There are no files selected for viewing
14 changes: 14 additions & 0 deletions
14
ReactAndroid/src/main/java/com/facebook/react/views/common/BUCK
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
include_defs("//ReactAndroid/DEFS") | ||
|
||
android_library( | ||
name = "common", | ||
srcs = glob(["*.java"]), | ||
provided_deps = [ | ||
react_native_dep("third-party/android/support/v4:lib-support-v4"), | ||
], | ||
visibility = [ | ||
"PUBLIC", | ||
], | ||
deps = [ | ||
], | ||
) |
28 changes: 28 additions & 0 deletions
28
ReactAndroid/src/main/java/com/facebook/react/views/common/ViewHelper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// Copyright 2004-present Facebook. All Rights Reserved. | ||
|
||
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) { | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
caschomburg123
via email
|
||
view.setBackground(drawable); | ||
} else { | ||
view.setBackgroundDrawable(drawable); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Isn't React Native only for API 16 (Jelly bean) and above? In that case when would this condition ever be not true.