mirror of
https://github.com/facebook/react-native.git
synced 2026-11-18 20:19:07 +00:00
Move background drawing code from "react/views/view" to "react/uimanager/drawable" (#43720)
Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/43720 This lets us use BG drawing code in rules which view depends on. I also removed some lib usage. The original class is still present, subclassing the class in its new location, but is marked deprecated. Next diffs in stack clean up some of our own now deprecated usage. Changelog: [Android][Breaking] - Deprecate `ReactViewBackgroundDrawable` in favor of `CSSBackgroundDrawable` Reviewed By: javache Differential Revision: D55565035 fbshipit-source-id: 501b3e2f674c09a88b1825657ba6349823054e8c
This commit is contained in:
1 parent
1b152f6eca
commit
d7766fa927
5 files changed
+1512
-1526
No files matched your search
@@ -5448,6 +5448,53 @@ public abstract interface class com/facebook/react/uimanager/debug/NotThreadSafe
|
||||
public abstract fun onViewHierarchyUpdateFinished ()V
|
||||
}
|
||||
|
||||
public class com/facebook/react/uimanager/drawable/CSSBackgroundDrawable : android/graphics/drawable/Drawable {
|
||||
public fun <init> (Landroid/content/Context;)V
|
||||
public fun borderBoxPath ()Landroid/graphics/Path;
|
||||
public fun draw (Landroid/graphics/Canvas;)V
|
||||
public fun getAlpha ()I
|
||||
public fun getBorderColor (I)I
|
||||
public fun getBorderRadius (Lcom/facebook/react/uimanager/drawable/CSSBackgroundDrawable$BorderRadiusLocation;)F
|
||||
public fun getBorderRadiusOrDefaultTo (FLcom/facebook/react/uimanager/drawable/CSSBackgroundDrawable$BorderRadiusLocation;)F
|
||||
public fun getBorderWidthOrDefaultTo (FI)F
|
||||
public fun getDirectionAwareBorderInsets ()Landroid/graphics/RectF;
|
||||
public fun getFullBorderRadius ()F
|
||||
public fun getFullBorderWidth ()F
|
||||
public fun getOpacity ()I
|
||||
public fun getOutline (Landroid/graphics/Outline;)V
|
||||
public fun getResolvedLayoutDirection ()I
|
||||
public fun hasRoundedBorders ()Z
|
||||
protected fun onBoundsChange (Landroid/graphics/Rect;)V
|
||||
public fun onResolvedLayoutDirectionChanged (I)Z
|
||||
public fun paddingBoxPath ()Landroid/graphics/Path;
|
||||
public fun setAlpha (I)V
|
||||
public fun setBorderColor (IFF)V
|
||||
public fun setBorderStyle (Ljava/lang/String;)V
|
||||
public fun setBorderWidth (IF)V
|
||||
public fun setColor (I)V
|
||||
public fun setColorFilter (Landroid/graphics/ColorFilter;)V
|
||||
public fun setRadius (F)V
|
||||
public fun setRadius (FI)V
|
||||
public fun setResolvedLayoutDirection (I)Z
|
||||
}
|
||||
|
||||
public final class com/facebook/react/uimanager/drawable/CSSBackgroundDrawable$BorderRadiusLocation : java/lang/Enum {
|
||||
public static final field BOTTOM_END Lcom/facebook/react/uimanager/drawable/CSSBackgroundDrawable$BorderRadiusLocation;
|
||||
public static final field BOTTOM_LEFT Lcom/facebook/react/uimanager/drawable/CSSBackgroundDrawable$BorderRadiusLocation;
|
||||
public static final field BOTTOM_RIGHT Lcom/facebook/react/uimanager/drawable/CSSBackgroundDrawable$BorderRadiusLocation;
|
||||
public static final field BOTTOM_START Lcom/facebook/react/uimanager/drawable/CSSBackgroundDrawable$BorderRadiusLocation;
|
||||
public static final field END_END Lcom/facebook/react/uimanager/drawable/CSSBackgroundDrawable$BorderRadiusLocation;
|
||||
public static final field END_START Lcom/facebook/react/uimanager/drawable/CSSBackgroundDrawable$BorderRadiusLocation;
|
||||
public static final field START_END Lcom/facebook/react/uimanager/drawable/CSSBackgroundDrawable$BorderRadiusLocation;
|
||||
public static final field START_START Lcom/facebook/react/uimanager/drawable/CSSBackgroundDrawable$BorderRadiusLocation;
|
||||
public static final field TOP_END Lcom/facebook/react/uimanager/drawable/CSSBackgroundDrawable$BorderRadiusLocation;
|
||||
public static final field TOP_LEFT Lcom/facebook/react/uimanager/drawable/CSSBackgroundDrawable$BorderRadiusLocation;
|
||||
public static final field TOP_RIGHT Lcom/facebook/react/uimanager/drawable/CSSBackgroundDrawable$BorderRadiusLocation;
|
||||
public static final field TOP_START Lcom/facebook/react/uimanager/drawable/CSSBackgroundDrawable$BorderRadiusLocation;
|
||||
public static fun valueOf (Ljava/lang/String;)Lcom/facebook/react/uimanager/drawable/CSSBackgroundDrawable$BorderRadiusLocation;
|
||||
public static fun values ()[Lcom/facebook/react/uimanager/drawable/CSSBackgroundDrawable$BorderRadiusLocation;
|
||||
}
|
||||
|
||||
public abstract interface class com/facebook/react/uimanager/events/BatchEventDispatchedListener {
|
||||
public abstract fun onBatchEventDispatched ()V
|
||||
}
|
||||
@@ -7672,8 +7719,6 @@ public final class com/facebook/react/views/unimplementedview/ReactUnimplemented
|
||||
|
||||
public final class com/facebook/react/views/view/ColorUtil {
|
||||
public static final field INSTANCE Lcom/facebook/react/views/view/ColorUtil;
|
||||
public static final fun getOpacityFromColor (I)I
|
||||
public static final fun multiplyColorAlpha (II)I
|
||||
public static final fun normalize (DDDD)I
|
||||
}
|
||||
|
||||
@@ -7706,49 +7751,8 @@ 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 : android/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 fun draw (Landroid/graphics/Canvas;)V
|
||||
public fun getAlpha ()I
|
||||
public fun getBorderColor (I)I
|
||||
public fun getBorderRadius (Lcom/facebook/react/views/view/ReactViewBackgroundDrawable$BorderRadiusLocation;)F
|
||||
public fun getBorderRadiusOrDefaultTo (FLcom/facebook/react/views/view/ReactViewBackgroundDrawable$BorderRadiusLocation;)F
|
||||
public fun getBorderWidthOrDefaultTo (FI)F
|
||||
public fun getDirectionAwareBorderInsets ()Landroid/graphics/RectF;
|
||||
public fun getFullBorderRadius ()F
|
||||
public fun getFullBorderWidth ()F
|
||||
public fun getOpacity ()I
|
||||
public fun getOutline (Landroid/graphics/Outline;)V
|
||||
public fun getResolvedLayoutDirection ()I
|
||||
public fun hasRoundedBorders ()Z
|
||||
protected fun onBoundsChange (Landroid/graphics/Rect;)V
|
||||
public fun onResolvedLayoutDirectionChanged (I)Z
|
||||
public fun setAlpha (I)V
|
||||
public fun setBorderColor (IFF)V
|
||||
public fun setBorderStyle (Ljava/lang/String;)V
|
||||
public fun setBorderWidth (IF)V
|
||||
public fun setColor (I)V
|
||||
public fun setColorFilter (Landroid/graphics/ColorFilter;)V
|
||||
public fun setRadius (F)V
|
||||
public fun setRadius (FI)V
|
||||
public fun setResolvedLayoutDirection (I)Z
|
||||
}
|
||||
|
||||
public final class com/facebook/react/views/view/ReactViewBackgroundDrawable$BorderRadiusLocation : java/lang/Enum {
|
||||
public static final field BOTTOM_END Lcom/facebook/react/views/view/ReactViewBackgroundDrawable$BorderRadiusLocation;
|
||||
public static final field BOTTOM_LEFT Lcom/facebook/react/views/view/ReactViewBackgroundDrawable$BorderRadiusLocation;
|
||||
public static final field BOTTOM_RIGHT Lcom/facebook/react/views/view/ReactViewBackgroundDrawable$BorderRadiusLocation;
|
||||
public static final field BOTTOM_START Lcom/facebook/react/views/view/ReactViewBackgroundDrawable$BorderRadiusLocation;
|
||||
public static final field END_END Lcom/facebook/react/views/view/ReactViewBackgroundDrawable$BorderRadiusLocation;
|
||||
public static final field END_START Lcom/facebook/react/views/view/ReactViewBackgroundDrawable$BorderRadiusLocation;
|
||||
public static final field START_END Lcom/facebook/react/views/view/ReactViewBackgroundDrawable$BorderRadiusLocation;
|
||||
public static final field START_START Lcom/facebook/react/views/view/ReactViewBackgroundDrawable$BorderRadiusLocation;
|
||||
public static final field TOP_END Lcom/facebook/react/views/view/ReactViewBackgroundDrawable$BorderRadiusLocation;
|
||||
public static final field TOP_LEFT Lcom/facebook/react/views/view/ReactViewBackgroundDrawable$BorderRadiusLocation;
|
||||
public static final field TOP_RIGHT Lcom/facebook/react/views/view/ReactViewBackgroundDrawable$BorderRadiusLocation;
|
||||
public static final field TOP_START Lcom/facebook/react/views/view/ReactViewBackgroundDrawable$BorderRadiusLocation;
|
||||
public static fun valueOf (Ljava/lang/String;)Lcom/facebook/react/views/view/ReactViewBackgroundDrawable$BorderRadiusLocation;
|
||||
public static fun values ()[Lcom/facebook/react/views/view/ReactViewBackgroundDrawable$BorderRadiusLocation;
|
||||
}
|
||||
|
||||
public class com/facebook/react/views/view/ReactViewBackgroundManager {
|
||||
|
||||
+1458
File diff suppressed because it is too large.
Load diff
-38
@@ -7,7 +7,6 @@
|
||||
|
||||
package com.facebook.react.views.view
|
||||
|
||||
import android.graphics.PixelFormat
|
||||
import kotlin.math.roundToInt
|
||||
|
||||
/**
|
||||
@@ -17,43 +16,6 @@ import kotlin.math.roundToInt
|
||||
*/
|
||||
public object ColorUtil {
|
||||
|
||||
/**
|
||||
* Multiplies the color with the given alpha.
|
||||
*
|
||||
* @param color color to be multiplied
|
||||
* @param alpha value between 0 and 255
|
||||
* @return multiplied color
|
||||
*/
|
||||
@JvmStatic
|
||||
public fun multiplyColorAlpha(color: Int, alpha: Int): Int {
|
||||
if (alpha == 255) {
|
||||
return color
|
||||
} else if (alpha == 0) {
|
||||
return color and 0x00FFFFFF
|
||||
}
|
||||
|
||||
val scaledAlpha = alpha + (alpha shr 7) // make it 0..256
|
||||
val colorAlpha = color ushr 24
|
||||
val multipliedAlpha = (colorAlpha * scaledAlpha) shr 8
|
||||
return (multipliedAlpha shl 24) or (color and 0x00FFFFFF)
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the opacity from a color. Inspired by Android ColorDrawable.
|
||||
*
|
||||
* @param color color to get opacity from
|
||||
* @return opacity expressed by one of PixelFormat constants
|
||||
*/
|
||||
@JvmStatic
|
||||
public fun getOpacityFromColor(color: Int): Int {
|
||||
val colorAlpha = color ushr 24
|
||||
return when (colorAlpha) {
|
||||
255 -> PixelFormat.OPAQUE
|
||||
0 -> PixelFormat.TRANSPARENT
|
||||
else -> PixelFormat.TRANSLUCENT
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts individual {r, g, b, a} channel values to a single integer representation of the color
|
||||
* as 0xAARRGGBB.
|
||||
|
||||
+6
-1422
File diff suppressed because it is too large.
Load diff
-22
@@ -7,7 +7,6 @@
|
||||
|
||||
package com.facebook.react.views.view
|
||||
|
||||
import android.graphics.PixelFormat
|
||||
import junit.framework.TestCase.assertEquals
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
@@ -16,27 +15,6 @@ import org.robolectric.RobolectricTestRunner
|
||||
/** Based on Fresco's DrawableUtilsTest (https://github.com/facebook/fresco). */
|
||||
@RunWith(RobolectricTestRunner::class)
|
||||
class ColorUtilTest {
|
||||
@Test
|
||||
fun testMultiplyColorAlpha() {
|
||||
assertEquals(0x00123456U.toInt(), ColorUtil.multiplyColorAlpha(0xC0123456U.toInt(), 0))
|
||||
assertEquals(0x07123456U.toInt(), ColorUtil.multiplyColorAlpha(0xC0123456U.toInt(), 10))
|
||||
assertEquals(0x96123456U.toInt(), ColorUtil.multiplyColorAlpha(0xC0123456U.toInt(), 200))
|
||||
assertEquals(0xC0123456U.toInt(), ColorUtil.multiplyColorAlpha(0xC0123456U.toInt(), 255))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testGetOpacityFromColor() {
|
||||
assertEquals(PixelFormat.TRANSPARENT, ColorUtil.getOpacityFromColor(0x00000000))
|
||||
assertEquals(PixelFormat.TRANSPARENT, ColorUtil.getOpacityFromColor(0x00123456))
|
||||
assertEquals(PixelFormat.TRANSPARENT, ColorUtil.getOpacityFromColor(0x00FFFFFF))
|
||||
assertEquals(PixelFormat.TRANSLUCENT, ColorUtil.getOpacityFromColor(0xC0000000.toInt()))
|
||||
assertEquals(PixelFormat.TRANSLUCENT, ColorUtil.getOpacityFromColor(0xC0123456.toInt()))
|
||||
assertEquals(PixelFormat.TRANSLUCENT, ColorUtil.getOpacityFromColor(0xC0FFFFFF.toInt()))
|
||||
assertEquals(PixelFormat.OPAQUE, ColorUtil.getOpacityFromColor(0xFF000000.toInt()))
|
||||
assertEquals(PixelFormat.OPAQUE, ColorUtil.getOpacityFromColor(0xFF123456.toInt()))
|
||||
assertEquals(PixelFormat.OPAQUE, ColorUtil.getOpacityFromColor(0xFFFFFFFF.toInt()))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testNormalize() {
|
||||
assertEquals(0x800B1621U.toInt(), ColorUtil.normalize(11.0, 22.0, 33.0, 0.5))
|
||||
|
||||
Reference in new issue
Block a user