mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Support AnimatedColor.setValue for platform colors
Summary: In order to support AnimatedColor.setValue for platform colors, we need to pass the platform color object to the native animated node which will then resolve and apply the color. Thus, the approach is: - Add a new API updateAnimatedNodeConfig to NativeAnimatedModule - [JS] On AnimatedColor.setValue, if the value is a platform color, then we call updateAnimatedNodeConfig - [Android] We introduce AnimatedNodeWithUpdateableConfig interface with a method updateConfig. On ColorAnimatedNode.java, we use updateConfig to resolve and apply the color Changelog: [Internal][Fixed] - Use context from view when resolving platform color Reviewed By: javache, mdvacca Differential Revision: D34025193 fbshipit-source-id: 8b368f6b7cb2cf7cebe8b66461cd4185cbadd44c
This commit is contained in:
committed by
Facebook GitHub Bot
parent
5b66bb90c6
commit
bb435a2b11
+15
@@ -0,0 +1,15 @@
|
||||
/*
|
||||
* 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;
|
||||
|
||||
/** Indicates that AnimatedNode is able to receive native config updates. */
|
||||
public interface AnimatedNodeWithUpdateableConfig {
|
||||
void onUpdateConfig(ReadableMap config);
|
||||
}
|
||||
@@ -16,15 +16,16 @@ import com.facebook.react.bridge.ReadableMap;
|
||||
import com.facebook.react.views.view.ColorUtil;
|
||||
|
||||
/** Animated node that represents a color. */
|
||||
/*package*/ class ColorAnimatedNode extends AnimatedNode {
|
||||
/*package*/ class ColorAnimatedNode extends AnimatedNode
|
||||
implements AnimatedNodeWithUpdateableConfig {
|
||||
|
||||
private final NativeAnimatedNodesManager mNativeAnimatedNodesManager;
|
||||
private final ReactApplicationContext mReactApplicationContext;
|
||||
private final int mRNodeId;
|
||||
private final int mGNodeId;
|
||||
private final int mBNodeId;
|
||||
private final int mANodeId;
|
||||
private final ReadableMap mNativeColor;
|
||||
private int mRNodeId;
|
||||
private int mGNodeId;
|
||||
private int mBNodeId;
|
||||
private int mANodeId;
|
||||
private ReadableMap mNativeColor;
|
||||
private boolean mNativeColorApplied;
|
||||
|
||||
public ColorAnimatedNode(
|
||||
@@ -33,12 +34,7 @@ import com.facebook.react.views.view.ColorUtil;
|
||||
ReactApplicationContext reactApplicationContext) {
|
||||
mNativeAnimatedNodesManager = nativeAnimatedNodesManager;
|
||||
mReactApplicationContext = reactApplicationContext;
|
||||
mRNodeId = config.getInt("r");
|
||||
mGNodeId = config.getInt("g");
|
||||
mBNodeId = config.getInt("b");
|
||||
mANodeId = config.getInt("a");
|
||||
mNativeColor = config.getMap("nativeColor");
|
||||
tryApplyNativeColor();
|
||||
onUpdateConfig(config);
|
||||
}
|
||||
|
||||
public int getColor() {
|
||||
@@ -57,6 +53,16 @@ import com.facebook.react.views.view.ColorUtil;
|
||||
return ColorUtil.normalize(r, g, b, a);
|
||||
}
|
||||
|
||||
public void onUpdateConfig(ReadableMap config) {
|
||||
mRNodeId = config.getInt("r");
|
||||
mGNodeId = config.getInt("g");
|
||||
mBNodeId = config.getInt("b");
|
||||
mANodeId = config.getInt("a");
|
||||
mNativeColor = config.getMap("nativeColor");
|
||||
mNativeColorApplied = false;
|
||||
tryApplyNativeColor();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String prettyPrint() {
|
||||
return "ColorAnimatedNode["
|
||||
|
||||
@@ -460,6 +460,32 @@ public class NativeAnimatedModule extends NativeAnimatedModuleSpec
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateAnimatedNodeConfig(final double tagDouble, final ReadableMap config) {
|
||||
final int tag = (int) tagDouble;
|
||||
if (ANIMATED_MODULE_DEBUG) {
|
||||
FLog.d(
|
||||
NAME,
|
||||
"queue updateAnimatedNodeConfig: " + tag + " config: " + config.toHashMap().toString());
|
||||
}
|
||||
|
||||
addOperation(
|
||||
new UIThreadOperation() {
|
||||
@Override
|
||||
public void execute(NativeAnimatedNodesManager animatedNodesManager) {
|
||||
if (ANIMATED_MODULE_DEBUG) {
|
||||
FLog.d(
|
||||
NAME,
|
||||
"execute updateAnimatedNodeConfig: "
|
||||
+ tag
|
||||
+ " config: "
|
||||
+ config.toHashMap().toString());
|
||||
}
|
||||
animatedNodesManager.updateAnimatedNodeConfig(tag, config);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void startListeningToAnimatedNodeValue(final double tagDouble) {
|
||||
final int tag = (int) tagDouble;
|
||||
|
||||
+15
@@ -159,6 +159,21 @@ import java.util.Queue;
|
||||
mUpdatedNodes.put(tag, node);
|
||||
}
|
||||
|
||||
@UiThread
|
||||
public void updateAnimatedNodeConfig(int tag, ReadableMap config) {
|
||||
AnimatedNode node = mAnimatedNodes.get(tag);
|
||||
if (node == null) {
|
||||
throw new JSApplicationIllegalArgumentException(
|
||||
"updateAnimatedNode: Animated node [" + tag + "] does not exist");
|
||||
}
|
||||
|
||||
if (node instanceof AnimatedNodeWithUpdateableConfig) {
|
||||
stopAnimationsForNode(node);
|
||||
((AnimatedNodeWithUpdateableConfig) node).onUpdateConfig(config);
|
||||
mUpdatedNodes.put(tag, node);
|
||||
}
|
||||
}
|
||||
|
||||
@UiThread
|
||||
public void dropAnimatedNode(int tag) {
|
||||
mAnimatedNodes.remove(tag);
|
||||
|
||||
Reference in New Issue
Block a user