mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
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
62 lines
2.3 KiB
Java
62 lines
2.3 KiB
Java
/*
|
|
* 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 androidx.annotation.Nullable;
|
|
import com.facebook.react.bridge.JavaOnlyMap;
|
|
import com.facebook.react.bridge.ReadableMap;
|
|
import com.facebook.react.bridge.ReadableMapKeySetIterator;
|
|
import java.util.HashMap;
|
|
import java.util.Map;
|
|
|
|
/**
|
|
* Native counterpart of style animated node (see AnimatedStyle class in AnimatedImplementation.js)
|
|
*/
|
|
/*package*/ class StyleAnimatedNode extends AnimatedNode {
|
|
|
|
private final NativeAnimatedNodesManager mNativeAnimatedNodesManager;
|
|
private final Map<String, Integer> mPropMapping;
|
|
|
|
StyleAnimatedNode(ReadableMap config, NativeAnimatedNodesManager nativeAnimatedNodesManager) {
|
|
ReadableMap style = config.getMap("style");
|
|
ReadableMapKeySetIterator iter = style.keySetIterator();
|
|
mPropMapping = new HashMap<>();
|
|
while (iter.hasNextKey()) {
|
|
String propKey = iter.nextKey();
|
|
int nodeIndex = style.getInt(propKey);
|
|
mPropMapping.put(propKey, nodeIndex);
|
|
}
|
|
mNativeAnimatedNodesManager = nativeAnimatedNodesManager;
|
|
}
|
|
|
|
public void collectViewUpdates(JavaOnlyMap propsMap) {
|
|
for (Map.Entry<String, Integer> entry : mPropMapping.entrySet()) {
|
|
@Nullable AnimatedNode node = mNativeAnimatedNodesManager.getNodeById(entry.getValue());
|
|
if (node == null) {
|
|
throw new IllegalArgumentException("Mapped style node does not exists");
|
|
} else if (node instanceof TransformAnimatedNode) {
|
|
((TransformAnimatedNode) node).collectViewUpdates(propsMap);
|
|
} else if (node instanceof ValueAnimatedNode) {
|
|
propsMap.putDouble(entry.getKey(), ((ValueAnimatedNode) node).getValue());
|
|
} else if (node instanceof ColorAnimatedNode) {
|
|
propsMap.putInt(entry.getKey(), ((ColorAnimatedNode) node).getColor());
|
|
} else {
|
|
throw new IllegalArgumentException(
|
|
"Unsupported type of node used in property node " + node.getClass());
|
|
}
|
|
}
|
|
}
|
|
|
|
public String prettyPrint() {
|
|
return "StyleAnimatedNode["
|
|
+ mTag
|
|
+ "] mPropMapping: "
|
|
+ (mPropMapping != null ? mPropMapping.toString() : "null");
|
|
}
|
|
}
|