From 393b3fce371d638904f5f71a7c76e37dd3924e1b Mon Sep 17 00:00:00 2001 From: Ruslan Shestopalyuk Date: Tue, 30 Jul 2024 02:32:13 -0700 Subject: [PATCH] Migrate MultiplicationAnimatedNode to Kotlin Differential Revision: D60340884 --- .../animated/MultiplicationAnimatedNode.java | 56 ------------------- .../animated/MultiplicationAnimatedNode.kt | 50 +++++++++++++++++ 2 files changed, 50 insertions(+), 56 deletions(-) delete mode 100644 packages/react-native/ReactAndroid/src/main/java/com/facebook/react/animated/MultiplicationAnimatedNode.java create mode 100644 packages/react-native/ReactAndroid/src/main/java/com/facebook/react/animated/MultiplicationAnimatedNode.kt diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/animated/MultiplicationAnimatedNode.java b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/animated/MultiplicationAnimatedNode.java deleted file mode 100644 index 06296ea7eb5f49..00000000000000 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/animated/MultiplicationAnimatedNode.java +++ /dev/null @@ -1,56 +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.JSApplicationCausedNativeException; -import com.facebook.react.bridge.ReadableArray; -import com.facebook.react.bridge.ReadableMap; - -/** - * Animated node which takes two or more value node as an input and outputs a product of their - * values - */ -/*package*/ class MultiplicationAnimatedNode extends ValueAnimatedNode { - - private final NativeAnimatedNodesManager mNativeAnimatedNodesManager; - private final int[] mInputNodes; - - public MultiplicationAnimatedNode( - ReadableMap config, NativeAnimatedNodesManager nativeAnimatedNodesManager) { - mNativeAnimatedNodesManager = nativeAnimatedNodesManager; - ReadableArray inputNodes = config.getArray("input"); - mInputNodes = new int[inputNodes.size()]; - for (int i = 0; i < mInputNodes.length; i++) { - mInputNodes[i] = inputNodes.getInt(i); - } - } - - @Override - public void update() { - nodeValue = 1; - for (int i = 0; i < mInputNodes.length; i++) { - AnimatedNode animatedNode = mNativeAnimatedNodesManager.getNodeById(mInputNodes[i]); - if (animatedNode != null && animatedNode instanceof ValueAnimatedNode) { - nodeValue *= ((ValueAnimatedNode) animatedNode).getValue(); - } else { - throw new JSApplicationCausedNativeException( - "Illegal node ID set as an input for Animated.multiply node"); - } - } - } - - @Override - public String prettyPrint() { - return "MultiplicationAnimatedNode[" - + tag - + "]: input nodes: " - + (mInputNodes != null ? mInputNodes.toString() : "null") - + " - super: " - + super.prettyPrint(); - } -} diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/animated/MultiplicationAnimatedNode.kt b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/animated/MultiplicationAnimatedNode.kt new file mode 100644 index 00000000000000..fa1f7d4a8e18ba --- /dev/null +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/animated/MultiplicationAnimatedNode.kt @@ -0,0 +1,50 @@ +/* + * 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.JSApplicationCausedNativeException +import com.facebook.react.bridge.ReadableMap + +/** + * Animated node which takes two or more value node as an input and outputs a product of their + * values + */ +internal class MultiplicationAnimatedNode( + config: ReadableMap, + private val nativeAnimatedNodesManager: NativeAnimatedNodesManager +) : ValueAnimatedNode() { + private var inputNodes: IntArray + + init { + val input = config.getArray("input") + inputNodes = + if (input == null) { + IntArray(0) + } else { + IntArray(input.size()) { i -> input.getInt(i) } + } + } + + override fun update() { + nodeValue = 1.0 + for (i in inputNodes.indices) { + val animatedNode = nativeAnimatedNodesManager.getNodeById(inputNodes[i]) + val multiplier = + if (animatedNode != null && animatedNode is ValueAnimatedNode) { + animatedNode.getValue() + } else { + throw JSApplicationCausedNativeException( + "Illegal node ID set as an input for Animated.multiply node") + } + nodeValue *= multiplier + } + } + + override fun prettyPrint(): String = + "MultiplicationAnimatedNode[$tag]: input nodes: $inputNodes - super: ${super.prettyPrint()}" +}