mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
65ccdffc8d
Summary:This is the first from the series of PRs I'm going to be sending shorty that would let Animated.js animations to run off the JS thread (for Android only). This PR introduce a new native module that will be used for offloading animations - NativeAnimatedModule. It has a simple API that allows for animated nodes management via methods like: create/drop animated node, connect/disconnect nodes, start animation of a value node, attach/detach animated from a native view. Similarly to how we handle UIManager view hierarchy updates we create a queue of animated graph operations that are then executed on the UI thread. This isolates us from problems that may be caused by concurrent updates of animated graph while UI thread is "executing" the animation. The most important class NativeAnimatedNodesManager.java implements a management interface for animated nodes graph as well as implements a graph traversal algorithm that is run for each animation frame. For each animation frame we visit animated nodes th Closes https://github.com/facebook/react-native/pull/6466 Differential Revision: D3092739 Pulled By: astreet fb-gh-sync-id: 665b49900b7367c91a93b9d8864f78fb90bb36ba shipit-source-id: 665b49900b7367c91a93b9d8864f78fb90bb36ba
72 lines
2.1 KiB
Java
72 lines
2.1 KiB
Java
/**
|
|
* Copyright (c) 2015-present, Facebook, Inc.
|
|
* All rights reserved.
|
|
*
|
|
* This source code is licensed under the BSD-style license found in the
|
|
* LICENSE file in the root directory of this source tree. An additional grant
|
|
* of patent rights can be found in the PATENTS file in the same directory.
|
|
*/
|
|
|
|
package com.facebook.react.animated;
|
|
|
|
import com.facebook.infer.annotation.Assertions;
|
|
|
|
import java.util.ArrayList;
|
|
import java.util.List;
|
|
|
|
import javax.annotation.Nullable;
|
|
|
|
/**
|
|
* Base class for all Animated.js library node types that can be created on the "native" side.
|
|
*/
|
|
/*package*/ abstract class AnimatedNode {
|
|
|
|
public static final int INITIAL_BFS_COLOR = 0;
|
|
|
|
private static final int DEFAULT_ANIMATED_NODE_CHILD_COUNT = 1;
|
|
|
|
/*package*/ @Nullable List<AnimatedNode> mChildren; /* lazy-initialized when a child is added */
|
|
/*package*/ int mActiveIncomingNodes = 0;
|
|
/*package*/ int mBFSColor = INITIAL_BFS_COLOR;
|
|
/*package*/ int mTag = -1;
|
|
|
|
public final void addChild(AnimatedNode child) {
|
|
if (mChildren == null) {
|
|
mChildren = new ArrayList<>(DEFAULT_ANIMATED_NODE_CHILD_COUNT);
|
|
}
|
|
Assertions.assertNotNull(mChildren).add(child);
|
|
child.onAttachedToNode(this);
|
|
}
|
|
|
|
public final void removeChild(AnimatedNode child) {
|
|
if (mChildren == null) {
|
|
return;
|
|
}
|
|
child.onDetachedFromNode(this);
|
|
mChildren.remove(child);
|
|
}
|
|
|
|
/**
|
|
* Subclasses may want to override this method in order to store a reference to the parent of a
|
|
* given node that can then be used to calculate current node's value in {@link #update}.
|
|
* In that case it is important to also override {@link #onDetachedFromNode} to clear that
|
|
* reference once current node gets detached.
|
|
*/
|
|
public void onAttachedToNode(AnimatedNode parent) {
|
|
}
|
|
|
|
/**
|
|
* See {@link #onAttachedToNode}
|
|
*/
|
|
public void onDetachedFromNode(AnimatedNode parent) {
|
|
}
|
|
|
|
/**
|
|
* This method will be run on each node at most once every repetition of the animation loop. It
|
|
* will be executed on a node only when all the node's parent has already been updated. Therefore
|
|
* it can be used to calculate node's value.
|
|
*/
|
|
public void update() {
|
|
}
|
|
}
|