-
- All Implemented Interfaces:
-
com.facebook.react.bridge.LifecycleEventListener
,com.facebook.react.bridge.NativeModule
,com.facebook.react.bridge.ReactModuleWithSpec
,com.facebook.react.bridge.UIManagerListener
,com.facebook.react.turbomodule.core.interfaces.TurboModule
public class NativeAnimatedModule extends NativeAnimatedModuleSpec implements LifecycleEventListener, UIManagerListener
Module that exposes interface for creating and managing animated nodes on the "native" side.
Animated.js library is based on a concept of a graph where nodes are values or transform operations (such as interpolation, addition, etc) and connection are used to describe how change of the value in one node can affect other nodes.
Few examples of the nodes that can be created on the JS side:
- Animated.Value is a simplest type of node with a numeric value which can be driven by an animation engine (spring, decay, etc) or by calling setValue on it directly from JS
- Animated.add is a type of node that may have two or more input nodes. It outputs the sum of all the input node values
- interpolate - is actually a method you can call on any node and it creates a new node that takes the parent node as an input and outputs its interpolated value (e.g. if you have value that can animate from 0 to 1 you can create interpolated node and set output range to be 0 to 100 and when the input node changes the output of interpolated node will multiply the values by 100)
You can mix and chain nodes however you like and this way create nodes graph with connections between them.
To map animated node values to view properties there is a special type of a node: AnimatedProps. It is created by AnimatedImplementation whenever you render Animated.View and stores a mapping from the view properties to the corresponding animated values (so it's actually also a node with connections to the value nodes).
Last "special" elements of the graph are "animation drivers". Those are objects (represented as a graph nodes too) that based on some criteria updates attached values every frame (we have few types of those, e.g., spring, timing, decay). Animation objects can be "started" and "stopped". Those are like "pulse generators" for the rest of the nodes graph. Those pulses then propagate along the graph to the children nodes up to the special node type: AnimatedProps which then can be used to calculate property update map for a view.
This class acts as a proxy between the "native" API that can be called from JS and the main class that coordinates all the action: NativeAnimatedNodesManager. Since all the methods from NativeAnimatedNodesManager need to be called from the UI thread, we we create a queue of animated graph operations that is then enqueued to be executed in the UI Thread at the end of the batch of JS->native calls (similarly to how it's handled in UIManagerModule). This isolates us from the problems that may be caused by concurrent updates of animated graph while UI thread is "executing" the animation loop.
-
-
Field Summary
Fields Modifier and Type Field Description public final static String
NAME
public final static boolean
ANIMATED_MODULE_DEBUG
-
Constructor Summary
Constructors Constructor Description NativeAnimatedModule(ReactApplicationContext reactContext)
-
Method Summary
Modifier and Type Method Description void
initialize()
This is called at the end of createCatalystInstance afterthe CatalystInstance has been created, in order to initialize NativeModules that require theCatalystInstance or JS modules. void
onHostResume()
Called either when the host activity receives a resume event (e.g. void
didScheduleMountItems(UIManager uiManager)
void
didDispatchMountItems(UIManager uiManager)
void
willDispatchViewUpdates(UIManager uiManager)
Called right before view updates are dispatched at the end of a batch. void
onHostPause()
Called when host activity receives pause event (e.g. void
onHostDestroy()
Called when host activity receives destroy event (e.g. String
getName()
void
setNodesManager(NativeAnimatedNodesManager nodesManager)
void
startOperationBatch()
void
finishOperationBatch()
void
createAnimatedNode(double tagDouble, ReadableMap config)
void
updateAnimatedNodeConfig(double tagDouble, ReadableMap config)
void
startListeningToAnimatedNodeValue(double tagDouble)
void
stopListeningToAnimatedNodeValue(double tagDouble)
void
dropAnimatedNode(double tagDouble)
void
setAnimatedNodeValue(double tagDouble, double value)
void
setAnimatedNodeOffset(double tagDouble, double value)
void
flattenAnimatedNodeOffset(double tagDouble)
void
extractAnimatedNodeOffset(double tagDouble)
void
startAnimatingNode(double animationIdDouble, double animatedNodeTagDouble, ReadableMap animationConfig, Callback endCallback)
void
stopAnimation(double animationIdDouble)
void
connectAnimatedNodes(double parentNodeTagDouble, double childNodeTagDouble)
void
disconnectAnimatedNodes(double parentNodeTagDouble, double childNodeTagDouble)
void
connectAnimatedNodeToView(double animatedNodeTagDouble, double viewTagDouble)
void
disconnectAnimatedNodeFromView(double animatedNodeTagDouble, double viewTagDouble)
void
restoreDefaultValues(double animatedNodeTagDouble)
void
addAnimatedEventToView(double viewTagDouble, String eventName, ReadableMap eventMapping)
void
removeAnimatedEventFromView(double viewTagDouble, String eventName, double animatedValueTagDouble)
void
addListener(String eventName)
void
removeListeners(double count)
void
getValue(double animatedValueNodeTagDouble, Callback callback)
void
invalidate()
The CatalystInstance is going away with Venice. -
Methods inherited from class com.facebook.fbreact.specs.NativeAnimatedModuleSpec
addAnimatedEventToView, connectAnimatedNodeToView, connectAnimatedNodes, createAnimatedNode, disconnectAnimatedNodeFromView, disconnectAnimatedNodes, dropAnimatedNode, extractAnimatedNodeOffset, flattenAnimatedNodeOffset, getValue, removeAnimatedEventFromView, restoreDefaultValues, setAnimatedNodeOffset, setAnimatedNodeValue, startAnimatingNode, startListeningToAnimatedNodeValue, stopAnimation, stopListeningToAnimatedNodeValue, updateAnimatedNodeConfig
-
Methods inherited from class com.facebook.react.bridge.BaseJavaModule
canOverrideExistingModule, getConstants, hasConstants, onCatalystInstanceDestroy
-
Methods inherited from class com.facebook.react.bridge.UIManagerListener
willDispatchViewUpdates
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
-
Constructor Detail
-
NativeAnimatedModule
NativeAnimatedModule(ReactApplicationContext reactContext)
-
-
Method Detail
-
initialize
void initialize()
This is called at the end of createCatalystInstance afterthe CatalystInstance has been created, in order to initialize NativeModules that require theCatalystInstance or JS modules.
-
onHostResume
void onHostResume()
Called either when the host activity receives a resume event (e.g. onResume orif the native module that implements this is initialized while the host activity is alreadyresumed. Always called for the most current activity.
-
didScheduleMountItems
void didScheduleMountItems(UIManager uiManager)
-
didDispatchMountItems
@UiThread() void didDispatchMountItems(UIManager uiManager)
-
willDispatchViewUpdates
@UiThread() void willDispatchViewUpdates(UIManager uiManager)
Called right before view updates are dispatched at the end of a batch. This is useful if amodule needs to add UIBlocks to the queue before it is flushed.
-
onHostPause
void onHostPause()
Called when host activity receives pause event (e.g. onPause. Always calledfor the most current activity.
-
onHostDestroy
void onHostDestroy()
Called when host activity receives destroy event (e.g. onDestroy. Only calledfor the last React activity to be destroyed.
-
setNodesManager
void setNodesManager(NativeAnimatedNodesManager nodesManager)
-
startOperationBatch
void startOperationBatch()
-
finishOperationBatch
void finishOperationBatch()
-
createAnimatedNode
void createAnimatedNode(double tagDouble, ReadableMap config)
-
updateAnimatedNodeConfig
void updateAnimatedNodeConfig(double tagDouble, ReadableMap config)
-
startListeningToAnimatedNodeValue
void startListeningToAnimatedNodeValue(double tagDouble)
-
stopListeningToAnimatedNodeValue
void stopListeningToAnimatedNodeValue(double tagDouble)
-
dropAnimatedNode
void dropAnimatedNode(double tagDouble)
-
setAnimatedNodeValue
void setAnimatedNodeValue(double tagDouble, double value)
-
setAnimatedNodeOffset
void setAnimatedNodeOffset(double tagDouble, double value)
-
flattenAnimatedNodeOffset
void flattenAnimatedNodeOffset(double tagDouble)
-
extractAnimatedNodeOffset
void extractAnimatedNodeOffset(double tagDouble)
-
startAnimatingNode
void startAnimatingNode(double animationIdDouble, double animatedNodeTagDouble, ReadableMap animationConfig, Callback endCallback)
-
stopAnimation
void stopAnimation(double animationIdDouble)
-
connectAnimatedNodes
void connectAnimatedNodes(double parentNodeTagDouble, double childNodeTagDouble)
-
disconnectAnimatedNodes
void disconnectAnimatedNodes(double parentNodeTagDouble, double childNodeTagDouble)
-
connectAnimatedNodeToView
void connectAnimatedNodeToView(double animatedNodeTagDouble, double viewTagDouble)
-
disconnectAnimatedNodeFromView
void disconnectAnimatedNodeFromView(double animatedNodeTagDouble, double viewTagDouble)
-
restoreDefaultValues
void restoreDefaultValues(double animatedNodeTagDouble)
-
addAnimatedEventToView
void addAnimatedEventToView(double viewTagDouble, String eventName, ReadableMap eventMapping)
-
removeAnimatedEventFromView
void removeAnimatedEventFromView(double viewTagDouble, String eventName, double animatedValueTagDouble)
-
addListener
void addListener(String eventName)
-
removeListeners
void removeListeners(double count)
-
invalidate
void invalidate()
The CatalystInstance is going away with Venice. Therefore, the TurboModule infra introduces theinvalidate() method to allow NativeModules to clean up after themselves.
-
-
-
-