diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/animated/TrackingAnimatedNode.java b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/animated/TrackingAnimatedNode.java deleted file mode 100644 index e5d28b7a3f87a6..00000000000000 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/animated/TrackingAnimatedNode.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * 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.JavaOnlyMap; -import com.facebook.react.bridge.ReadableMap; - -/* package */ class TrackingAnimatedNode extends AnimatedNode { - - private final NativeAnimatedNodesManager mNativeAnimatedNodesManager; - private final int mAnimationId; - private final int mToValueNode; - private final int mValueNode; - private final JavaOnlyMap mAnimationConfig; - - TrackingAnimatedNode(ReadableMap config, NativeAnimatedNodesManager nativeAnimatedNodesManager) { - mNativeAnimatedNodesManager = nativeAnimatedNodesManager; - mAnimationId = config.getInt("animationId"); - mToValueNode = config.getInt("toValue"); - mValueNode = config.getInt("value"); - mAnimationConfig = JavaOnlyMap.deepClone(config.getMap("animationConfig")); - } - - @Override - public void update() { - AnimatedNode toValue = mNativeAnimatedNodesManager.getNodeById(mToValueNode); - mAnimationConfig.putDouble("toValue", ((ValueAnimatedNode) toValue).getValue()); - mNativeAnimatedNodesManager.startAnimatingNode( - mAnimationId, mValueNode, mAnimationConfig, null); - } - - @Override - public String prettyPrint() { - return "TrackingAnimatedNode[" - + tag - + "]: animationID: " - + mAnimationId - + " toValueNode: " - + mToValueNode - + " valueNode: " - + mValueNode - + " animationConfig: " - + mAnimationConfig; - } -} diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/animated/TrackingAnimatedNode.kt b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/animated/TrackingAnimatedNode.kt new file mode 100644 index 00000000000000..cffb1894fc6720 --- /dev/null +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/animated/TrackingAnimatedNode.kt @@ -0,0 +1,36 @@ +/* + * 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.JavaOnlyMap +import com.facebook.react.bridge.ReadableMap + +internal class TrackingAnimatedNode( + config: ReadableMap, + private val nativeAnimatedNodesManager: NativeAnimatedNodesManager +) : AnimatedNode() { + private val animationId: Int = config.getInt("animationId") + private val toValueNode: Int = config.getInt("toValue") + private val valueNode: Int = config.getInt("value") + private val animationConfig: JavaOnlyMap = JavaOnlyMap.deepClone(config.getMap("animationConfig")) + + public override fun update() { + val toValue = nativeAnimatedNodesManager.getNodeById(toValueNode) + val valAnimatedNode = toValue as? ValueAnimatedNode + if (valAnimatedNode != null) { + animationConfig.putDouble("toValue", valAnimatedNode.getValue()) + } else { + animationConfig.putNull("toValue") + } + nativeAnimatedNodesManager.startAnimatingNode(animationId, valueNode, animationConfig, null) + } + + public override fun prettyPrint(): String = + "TrackingAnimatedNode[$tag]: animationID: $animationId toValueNode: $toValueNode " + + "valueNode: $valueNode animationConfig: $animationConfig" +}