-
Notifications
You must be signed in to change notification settings - Fork 24.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support color animation with native driver for Android
Summary: Adds support for Animated.Color with native driver for Android. Reads the native config for the rbga channel AnimatedNodes, and on update(), converts the values into an integer (0xaarrggbb) Followup changes will include support for iOS and platform colors. Changelog: [Android][Added] - Support running animations with AnimatedColor with native driver Reviewed By: javache Differential Revision: D33833600 fbshipit-source-id: 2bf05c9715b603cf014ace09e9308b2bfd67f30a
- Loading branch information
1 parent
0ab0c5a
commit 3f49e67
Showing
10 changed files
with
128 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 66 additions & 0 deletions
66
ReactAndroid/src/main/java/com/facebook/react/animated/ColorAnimatedNode.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
/* | ||
* 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 com.facebook.react.bridge.ReadableMap; | ||
import com.facebook.react.views.view.ColorUtil; | ||
|
||
/** Animated node that represents a color. */ | ||
/*package*/ class ColorAnimatedNode extends AnimatedNode { | ||
|
||
private final NativeAnimatedNodesManager mNativeAnimatedNodesManager; | ||
private final int mRNodeId; | ||
private final int mGNodeId; | ||
private final int mBNodeId; | ||
private final int mANodeId; | ||
private int mColor; | ||
|
||
public ColorAnimatedNode( | ||
ReadableMap config, NativeAnimatedNodesManager nativeAnimatedNodesManager) { | ||
mNativeAnimatedNodesManager = nativeAnimatedNodesManager; | ||
mRNodeId = config.getInt("r"); | ||
mGNodeId = config.getInt("g"); | ||
mBNodeId = config.getInt("b"); | ||
mANodeId = config.getInt("a"); | ||
|
||
// TODO (T110930421): Support platform color | ||
} | ||
|
||
public int getColor() { | ||
return mColor; | ||
} | ||
|
||
@Override | ||
public void update() { | ||
AnimatedNode rNode = mNativeAnimatedNodesManager.getNodeById(mRNodeId); | ||
AnimatedNode gNode = mNativeAnimatedNodesManager.getNodeById(mGNodeId); | ||
AnimatedNode bNode = mNativeAnimatedNodesManager.getNodeById(mBNodeId); | ||
AnimatedNode aNode = mNativeAnimatedNodesManager.getNodeById(mANodeId); | ||
|
||
double r = ((ValueAnimatedNode) rNode).getValue(); | ||
double g = ((ValueAnimatedNode) gNode).getValue(); | ||
double b = ((ValueAnimatedNode) bNode).getValue(); | ||
double a = ((ValueAnimatedNode) aNode).getValue(); | ||
|
||
mColor = ColorUtil.normalize(r, g, b, a); | ||
} | ||
|
||
@Override | ||
public String prettyPrint() { | ||
return "ColorAnimatedNode[" | ||
+ mTag | ||
+ "]: r: " | ||
+ mRNodeId | ||
+ " g: " | ||
+ mGNodeId | ||
+ " b: " | ||
+ mBNodeId | ||
+ " a: " | ||
+ mANodeId; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters