mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Migrate DivisionAnimatedNode, Java->Kotlin (#45762)
Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/45762 # Changelog: [Internal] - As in the title. Reviewed By: cortinico Differential Revision: D60341635 fbshipit-source-id: 2d897ee0727ba7608eced9c3b22bac852c22254f
This commit is contained in:
committed by
Facebook GitHub Bot
parent
675a2a1d76
commit
e51658abef
-64
@@ -1,64 +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 an in-order division of
|
||||
* their values.
|
||||
*/
|
||||
/*package*/ class DivisionAnimatedNode extends ValueAnimatedNode {
|
||||
|
||||
private final NativeAnimatedNodesManager mNativeAnimatedNodesManager;
|
||||
private final int[] mInputNodes;
|
||||
|
||||
public DivisionAnimatedNode(
|
||||
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() {
|
||||
for (int i = 0; i < mInputNodes.length; i++) {
|
||||
AnimatedNode animatedNode = mNativeAnimatedNodesManager.getNodeById(mInputNodes[i]);
|
||||
if (animatedNode != null && animatedNode instanceof ValueAnimatedNode) {
|
||||
double value = ((ValueAnimatedNode) animatedNode).getValue();
|
||||
if (i == 0) {
|
||||
nodeValue = value;
|
||||
continue;
|
||||
}
|
||||
if (value == 0) {
|
||||
throw new JSApplicationCausedNativeException(
|
||||
"Detected a division by zero in Animated.divide node with Animated ID " + tag);
|
||||
}
|
||||
nodeValue /= value;
|
||||
} else {
|
||||
throw new JSApplicationCausedNativeException(
|
||||
"Illegal node ID set as an input for Animated.divide node with Animated ID " + tag);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String prettyPrint() {
|
||||
return "DivisionAnimatedNode["
|
||||
+ tag
|
||||
+ "]: input nodes: "
|
||||
+ (mInputNodes != null ? mInputNodes.toString() : "null")
|
||||
+ " - super: "
|
||||
+ super.prettyPrint();
|
||||
}
|
||||
}
|
||||
+55
@@ -0,0 +1,55 @@
|
||||
/*
|
||||
* 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 an in-order division of
|
||||
* their values.
|
||||
*/
|
||||
internal class DivisionAnimatedNode(
|
||||
config: ReadableMap,
|
||||
private val nativeAnimatedNodesManager: NativeAnimatedNodesManager
|
||||
) : ValueAnimatedNode() {
|
||||
private val 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() {
|
||||
inputNodes.forEachIndexed { i, inputNode ->
|
||||
val animatedNode = nativeAnimatedNodesManager.getNodeById(inputNode)
|
||||
if (animatedNode != null && animatedNode is ValueAnimatedNode) {
|
||||
val v = animatedNode.nodeValue
|
||||
if (i == 0) {
|
||||
nodeValue = v
|
||||
} else if (v == 0.0) {
|
||||
throw JSApplicationCausedNativeException(
|
||||
"Detected a division by zero in Animated.divide node with Animated ID $tag")
|
||||
} else {
|
||||
nodeValue /= v
|
||||
}
|
||||
} else {
|
||||
throw JSApplicationCausedNativeException(
|
||||
"Illegal node ID set as an input for Animated.divide node with Animated ID $tag")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun prettyPrint(): String =
|
||||
"DivisionAnimatedNode[$tag]: input nodes: $inputNodes - super: ${super.prettyPrint()}"
|
||||
}
|
||||
Reference in New Issue
Block a user