public class NativeAnimatedModule extends NativeAnimatedModuleSpec implements LifecycleEventListener, UIManagerModuleListener
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:
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.
NativeModule.NativeMethod| Modifier and Type | Field and Description |
|---|---|
static java.lang.String |
NAME |
METHOD_TYPE_ASYNC, METHOD_TYPE_PROMISE, METHOD_TYPE_SYNC| Constructor and Description |
|---|
NativeAnimatedModule(ReactApplicationContext reactContext) |
| Modifier and Type | Method and Description |
|---|---|
void |
addAnimatedEventToView(double viewTagDouble,
java.lang.String eventName,
ReadableMap eventMapping) |
void |
addListener(java.lang.String eventName) |
void |
connectAnimatedNodes(double parentNodeTagDouble,
double childNodeTagDouble) |
void |
connectAnimatedNodeToView(double animatedNodeTagDouble,
double viewTagDouble) |
void |
createAnimatedNode(double tagDouble,
ReadableMap config) |
void |
disconnectAnimatedNodeFromView(double animatedNodeTagDouble,
double viewTagDouble) |
void |
disconnectAnimatedNodes(double parentNodeTagDouble,
double childNodeTagDouble) |
void |
dropAnimatedNode(double tagDouble) |
void |
extractAnimatedNodeOffset(double tagDouble) |
void |
flattenAnimatedNodeOffset(double tagDouble) |
java.lang.String |
getName() |
void |
initialize()
This is called at the end of
CatalystApplicationFragment#createCatalystInstance() after
the CatalystInstance has been created, in order to initialize NativeModules that require the
CatalystInstance or JS modules. |
void |
onHostDestroy()
Called when host activity receives destroy event (e.g.
|
void |
onHostPause()
Called when host activity receives pause event (e.g.
|
void |
onHostResume()
Called either when the host activity receives a resume event (e.g.
|
void |
removeAnimatedEventFromView(double viewTagDouble,
java.lang.String eventName,
double animatedValueTagDouble) |
void |
removeListeners(double count) |
void |
restoreDefaultValues(double animatedNodeTagDouble) |
void |
setAnimatedNodeOffset(double tagDouble,
double value) |
void |
setAnimatedNodeValue(double tagDouble,
double value) |
void |
setNodesManager(com.facebook.react.animated.NativeAnimatedNodesManager nodesManager) |
void |
startAnimatingNode(double animationIdDouble,
double animatedNodeTagDouble,
ReadableMap animationConfig,
Callback endCallback) |
void |
startListeningToAnimatedNodeValue(double tagDouble) |
void |
stopAnimation(double animationIdDouble) |
void |
stopListeningToAnimatedNodeValue(double tagDouble) |
void |
willDispatchViewUpdates(UIManagerModule uiManager)
Called right before view updates are dispatched at the end of a batch.
|
getCurrentActivity, getReactApplicationContext, getReactApplicationContextIfActiveOrWarncanOverrideExistingModule, getConstants, hasConstants, invalidate, onCatalystInstanceDestroyclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitinvalidatepublic static final java.lang.String NAME
public NativeAnimatedModule(ReactApplicationContext reactContext)
public void initialize()
NativeModuleCatalystApplicationFragment#createCatalystInstance() after
the CatalystInstance has been created, in order to initialize NativeModules that require the
CatalystInstance or JS modules.initialize in interface NativeModuleinitialize in class BaseJavaModulepublic void onHostResume()
LifecycleEventListenerActivity#onResume or
if the native module that implements this is initialized while the host activity is already
resumed. Always called for the most current activity.onHostResume in interface LifecycleEventListenerpublic void willDispatchViewUpdates(UIManagerModule uiManager)
UIManagerModuleListenerwillDispatchViewUpdates in interface UIManagerModuleListenerpublic void onHostPause()
LifecycleEventListenerActivity#onPause. Always called
for the most current activity.onHostPause in interface LifecycleEventListenerpublic void onHostDestroy()
LifecycleEventListenerActivity#onDestroy. Only called
for the last React activity to be destroyed.onHostDestroy in interface LifecycleEventListenerpublic java.lang.String getName()
getName in interface NativeModulerequire() this module
from javascript.public void setNodesManager(com.facebook.react.animated.NativeAnimatedNodesManager nodesManager)
public void createAnimatedNode(double tagDouble,
ReadableMap config)
createAnimatedNode in class NativeAnimatedModuleSpecpublic void startListeningToAnimatedNodeValue(double tagDouble)
startListeningToAnimatedNodeValue in class NativeAnimatedModuleSpecpublic void stopListeningToAnimatedNodeValue(double tagDouble)
stopListeningToAnimatedNodeValue in class NativeAnimatedModuleSpecpublic void dropAnimatedNode(double tagDouble)
dropAnimatedNode in class NativeAnimatedModuleSpecpublic void setAnimatedNodeValue(double tagDouble,
double value)
setAnimatedNodeValue in class NativeAnimatedModuleSpecpublic void setAnimatedNodeOffset(double tagDouble,
double value)
setAnimatedNodeOffset in class NativeAnimatedModuleSpecpublic void flattenAnimatedNodeOffset(double tagDouble)
flattenAnimatedNodeOffset in class NativeAnimatedModuleSpecpublic void extractAnimatedNodeOffset(double tagDouble)
extractAnimatedNodeOffset in class NativeAnimatedModuleSpecpublic void startAnimatingNode(double animationIdDouble,
double animatedNodeTagDouble,
ReadableMap animationConfig,
Callback endCallback)
startAnimatingNode in class NativeAnimatedModuleSpecpublic void stopAnimation(double animationIdDouble)
stopAnimation in class NativeAnimatedModuleSpecpublic void connectAnimatedNodes(double parentNodeTagDouble,
double childNodeTagDouble)
connectAnimatedNodes in class NativeAnimatedModuleSpecpublic void disconnectAnimatedNodes(double parentNodeTagDouble,
double childNodeTagDouble)
disconnectAnimatedNodes in class NativeAnimatedModuleSpecpublic void connectAnimatedNodeToView(double animatedNodeTagDouble,
double viewTagDouble)
connectAnimatedNodeToView in class NativeAnimatedModuleSpecpublic void disconnectAnimatedNodeFromView(double animatedNodeTagDouble,
double viewTagDouble)
disconnectAnimatedNodeFromView in class NativeAnimatedModuleSpecpublic void restoreDefaultValues(double animatedNodeTagDouble)
restoreDefaultValues in class NativeAnimatedModuleSpecpublic void addAnimatedEventToView(double viewTagDouble,
java.lang.String eventName,
ReadableMap eventMapping)
addAnimatedEventToView in class NativeAnimatedModuleSpecpublic void removeAnimatedEventFromView(double viewTagDouble,
java.lang.String eventName,
double animatedValueTagDouble)
removeAnimatedEventFromView in class NativeAnimatedModuleSpecpublic void addListener(java.lang.String eventName)
addListener in class NativeAnimatedModuleSpecpublic void removeListeners(double count)
removeListeners in class NativeAnimatedModuleSpec