From 2245b1175ec1fb779c1d60a0f7a7fe50ef033cf6 Mon Sep 17 00:00:00 2001 From: Ruslan Shestopalyuk Date: Sun, 28 Jul 2024 03:54:51 -0700 Subject: [PATCH] Migrate MultiplicationAnimatedNode to Kotlin (#45756) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/45756 # Changelog: [Internal] - As in the title. 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..53eabeb0f59264 --- /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") + val size = input?.size() ?: 0 + inputNodes = IntArray(size) + if (input != null) { + for (i in inputNodes.indices) { + inputNodes[i] = input.getInt(i) + } + } + } + + override fun update() { + nodeValue = 1.0 + for (i in inputNodes.indices) { + val animatedNode = nativeAnimatedNodesManager.getNodeById(inputNodes[i]) + nodeValue *= + if (animatedNode != null && animatedNode is ValueAnimatedNode) { + animatedNode.getValue() + } else { + throw JSApplicationCausedNativeException( + "Illegal node ID set as an input for Animated.multiply node") + } + } + } + + override fun prettyPrint(): String = + "MultiplicationAnimatedNode[$tag]: input nodes: $inputNodes - super: ${super.prettyPrint()}" +}