Skip to content
82 changes: 58 additions & 24 deletions packages/react-native/ReactAndroid/api/ReactAndroid.api
Original file line number Diff line number Diff line change
Expand Up @@ -464,6 +464,26 @@ public abstract interface class com/facebook/react/animated/AnimatedNodeWithUpda
public abstract fun onUpdateConfig (Lcom/facebook/react/bridge/ReadableMap;)V
}

public final class com/facebook/react/animated/InterpolationAnimatedNode : com/facebook/react/animated/ValueAnimatedNode {
public static final field Companion Lcom/facebook/react/animated/InterpolationAnimatedNode$Companion;
public static final field EXTRAPOLATE_TYPE_CLAMP Ljava/lang/String;
public static final field EXTRAPOLATE_TYPE_EXTEND Ljava/lang/String;
public static final field EXTRAPOLATE_TYPE_IDENTITY Ljava/lang/String;
public fun <init> (Lcom/facebook/react/bridge/ReadableMap;)V
public fun getAnimatedObject ()Ljava/lang/Object;
public fun onAttachedToNode (Lcom/facebook/react/animated/AnimatedNode;)V
public fun onDetachedFromNode (Lcom/facebook/react/animated/AnimatedNode;)V
public fun prettyPrint ()Ljava/lang/String;
public fun update ()V
}

public final class com/facebook/react/animated/InterpolationAnimatedNode$Companion {
public final fun interpolate (DDDDDLjava/lang/String;Ljava/lang/String;)D
public final fun interpolate (D[D[DLjava/lang/String;Ljava/lang/String;)D
public final fun interpolateColor (D[D[I)I
public final fun interpolateString (Ljava/lang/String;D[D[[DLjava/lang/String;Ljava/lang/String;)Ljava/lang/String;
}

public class com/facebook/react/animated/NativeAnimatedModule : com/facebook/fbreact/specs/NativeAnimatedModuleSpec, com/facebook/react/bridge/LifecycleEventListener, com/facebook/react/bridge/UIManagerListener {
public static final field ANIMATED_MODULE_DEBUG Z
public fun <init> (Lcom/facebook/react/bridge/ReactApplicationContext;)V
Expand Down Expand Up @@ -505,32 +525,46 @@ public class com/facebook/react/animated/NativeAnimatedModule : com/facebook/fbr
public fun willMountItems (Lcom/facebook/react/bridge/UIManager;)V
}

public class com/facebook/react/animated/NativeAnimatedNodesManager : com/facebook/react/uimanager/events/EventDispatcherListener {
public final class com/facebook/react/animated/NativeAnimatedNodesManager : com/facebook/react/uimanager/events/EventDispatcherListener {
public fun <init> (Lcom/facebook/react/bridge/ReactApplicationContext;)V
public fun addAnimatedEventToView (ILjava/lang/String;Lcom/facebook/react/bridge/ReadableMap;)V
public fun connectAnimatedNodeToView (II)V
public fun connectAnimatedNodes (II)V
public fun createAnimatedNode (ILcom/facebook/react/bridge/ReadableMap;)V
public fun disconnectAnimatedNodeFromView (II)V
public fun disconnectAnimatedNodes (II)V
public fun dropAnimatedNode (I)V
public fun extractAnimatedNodeOffset (I)V
public fun flattenAnimatedNodeOffset (I)V
public fun getNodeById (I)Lcom/facebook/react/animated/AnimatedNode;
public fun getValue (ILcom/facebook/react/bridge/Callback;)V
public fun hasActiveAnimations ()Z
public fun initializeEventListenerForUIManagerType (I)V
public final fun addAnimatedEventToView (ILjava/lang/String;Lcom/facebook/react/bridge/ReadableMap;)V
public final fun connectAnimatedNodeToView (II)V
public final fun connectAnimatedNodes (II)V
public final fun createAnimatedNode (ILcom/facebook/react/bridge/ReadableMap;)V
public final fun disconnectAnimatedNodeFromView (II)V
public final fun disconnectAnimatedNodes (II)V
public final fun dropAnimatedNode (I)V
public final fun extractAnimatedNodeOffset (I)V
public final fun flattenAnimatedNodeOffset (I)V
public final fun getNodeById (I)Lcom/facebook/react/animated/AnimatedNode;
public final fun getTagsOfConnectedNodes (ILjava/lang/String;)Ljava/util/Set;
public final fun getValue (ILcom/facebook/react/bridge/Callback;)V
public final fun hasActiveAnimations ()Z
public final fun initializeEventListenerForUIManagerType (I)V
public fun onEventDispatch (Lcom/facebook/react/uimanager/events/Event;)V
public fun removeAnimatedEventFromView (ILjava/lang/String;I)V
public fun restoreDefaultValues (I)V
public fun runUpdates (J)V
public fun setAnimatedNodeOffset (ID)V
public fun setAnimatedNodeValue (ID)V
public fun startAnimatingNode (IILcom/facebook/react/bridge/ReadableMap;Lcom/facebook/react/bridge/Callback;)V
public fun startListeningToAnimatedNodeValue (ILcom/facebook/react/animated/AnimatedNodeValueListener;)V
public fun stopAnimation (I)V
public fun stopListeningToAnimatedNodeValue (I)V
public fun updateAnimatedNodeConfig (ILcom/facebook/react/bridge/ReadableMap;)V
public final fun removeAnimatedEventFromView (ILjava/lang/String;I)V
public final fun restoreDefaultValues (I)V
public final fun runUpdates (J)V
public final fun setAnimatedNodeOffset (ID)V
public final fun setAnimatedNodeValue (ID)V
public final fun startAnimatingNode (IILcom/facebook/react/bridge/ReadableMap;Lcom/facebook/react/bridge/Callback;)V
public final fun startListeningToAnimatedNodeValue (ILcom/facebook/react/animated/AnimatedNodeValueListener;)V
public final fun stopAnimation (I)V
public final fun stopListeningToAnimatedNodeValue (I)V
public final fun updateAnimatedNodeConfig (ILcom/facebook/react/bridge/ReadableMap;)V
}

public class com/facebook/react/animated/ValueAnimatedNode : com/facebook/react/animated/AnimatedNode {
public fun <init> ()V
public fun <init> (Lcom/facebook/react/bridge/ReadableMap;)V
public synthetic fun <init> (Lcom/facebook/react/bridge/ReadableMap;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
public final fun extractOffset ()V
public final fun flattenOffset ()V
public fun getAnimatedObject ()Ljava/lang/Object;
public final fun getValue ()D
public final fun onValueUpdate ()V
public fun prettyPrint ()Ljava/lang/String;
public final fun setValueListener (Lcom/facebook/react/animated/AnimatedNodeValueListener;)V
}

public abstract interface class com/facebook/react/bridge/ActivityEventListener {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
/*
* 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.animated

import android.content.Context
import android.graphics.Color
import com.facebook.react.bridge.ColorPropConverter
import com.facebook.react.bridge.ReactApplicationContext
import com.facebook.react.bridge.ReadableMap
import com.facebook.react.views.view.ColorUtil.normalize

/** Animated node that represents a color. */
internal class ColorAnimatedNode(
config: ReadableMap,
private val nativeAnimatedNodesManager: NativeAnimatedNodesManager,
private val reactApplicationContext: ReactApplicationContext
) : AnimatedNode(), AnimatedNodeWithUpdateableConfig {
private var rNodeId = 0
private var gNodeId = 0
private var bNodeId = 0
private var aNodeId = 0
private var nativeColor: ReadableMap? = null
private var nativeColorApplied = false

init {
onUpdateConfig(config)
}

val color: Int
get() {
tryApplyNativeColor()
val rNode = nativeAnimatedNodesManager.getNodeById(rNodeId) as ValueAnimatedNode?
val gNode = nativeAnimatedNodesManager.getNodeById(gNodeId) as ValueAnimatedNode?
val bNode = nativeAnimatedNodesManager.getNodeById(bNodeId) as ValueAnimatedNode?
val aNode = nativeAnimatedNodesManager.getNodeById(aNodeId) as ValueAnimatedNode?
val r = rNode?.nodeValue ?: 0.0
val g = gNode?.nodeValue ?: 0.0
val b = bNode?.nodeValue ?: 0.0
val a = aNode?.nodeValue ?: 0.0
return normalize(r, g, b, a)
}

override fun onUpdateConfig(config: ReadableMap?) {
if (config != null) {
rNodeId = config.getInt("r")
gNodeId = config.getInt("g")
bNodeId = config.getInt("b")
aNodeId = config.getInt("a")
nativeColor = config.getMap("nativeColor")
nativeColorApplied = false
tryApplyNativeColor()
} else {
rNodeId = 0
gNodeId = 0
bNodeId = 0
aNodeId = 0
nativeColor = null
nativeColorApplied = false
}
}

override fun prettyPrint(): String =
"ColorAnimatedNode[$tag]: r: $rNodeId g: $gNodeId b: $bNodeId a: $aNodeId"

private fun tryApplyNativeColor() {
if (nativeColor == null || nativeColorApplied) {
return
}
val context = context ?: return
val color = ColorPropConverter.getColor(nativeColor, context)
val rNode = nativeAnimatedNodesManager.getNodeById(rNodeId) as ValueAnimatedNode?
val gNode = nativeAnimatedNodesManager.getNodeById(gNodeId) as ValueAnimatedNode?
val bNode = nativeAnimatedNodesManager.getNodeById(bNodeId) as ValueAnimatedNode?
val aNode = nativeAnimatedNodesManager.getNodeById(aNodeId) as ValueAnimatedNode?
rNode?.nodeValue = Color.red(color).toDouble()
gNode?.nodeValue = Color.green(color).toDouble()
bNode?.nodeValue = Color.blue(color).toDouble()
aNode?.nodeValue = Color.alpha(color) / 255.0
nativeColorApplied = true
}

private val context: Context?
get() {
// There are cases where the activity may not exist (such as for VRShell panel apps). In this
// case we will search for a view associated with a PropsAnimatedNode to get the context.
return reactApplicationContext.currentActivity ?: getContextHelper(this)
}

companion object {
private fun getContextHelper(node: AnimatedNode): Context? {
// Search children depth-first until we get to a PropsAnimatedNode, from which we can
// get the view and its context
node.children?.let { children ->
for (child in children) {
return if (child is PropsAnimatedNode) {
val view = child.connectedView
view?.context
} else {
getContextHelper(child)
}
}
}
return null
}
}
}
Loading