-
Notifications
You must be signed in to change notification settings - Fork 24.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Convert DiffClampAnimatedNode to Kotlin (#45716)
Summary: Pull Request resolved: #45716 # Changelog: [Internal] - As in the title. Reviewed By: steelrooter Differential Revision: D60283709 fbshipit-source-id: 110e9ee9deecd0c39575b94b0604ad3fa9a9b96e
- Loading branch information
1 parent
c07ca78
commit 58a4e2e
Showing
2 changed files
with
51 additions
and
66 deletions.
There are no files selected for viewing
66 changes: 0 additions & 66 deletions
66
...-native/ReactAndroid/src/main/java/com/facebook/react/animated/DiffClampAnimatedNode.java
This file was deleted.
Oops, something went wrong.
51 changes: 51 additions & 0 deletions
51
...ct-native/ReactAndroid/src/main/java/com/facebook/react/animated/DiffClampAnimatedNode.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/* | ||
* 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 | ||
import kotlin.math.max | ||
import kotlin.math.min | ||
|
||
internal class DiffClampAnimatedNode( | ||
config: ReadableMap, | ||
private val nativeAnimatedNodesManager: NativeAnimatedNodesManager | ||
) : ValueAnimatedNode() { | ||
private val inputNodeTag: Int | ||
private val minValue: Double | ||
private val maxValue: Double | ||
private var lastValue: Double = 0.0 | ||
|
||
init { | ||
inputNodeTag = config.getInt("input") | ||
minValue = config.getDouble("min") | ||
maxValue = config.getDouble("max") | ||
mValue = lastValue | ||
} | ||
|
||
override fun update() { | ||
val value = inputNodeValue | ||
val diff = value - lastValue | ||
lastValue = value | ||
mValue = min(max(mValue + diff, minValue), maxValue) | ||
} | ||
|
||
private val inputNodeValue: Double | ||
get() { | ||
val animatedNode = nativeAnimatedNodesManager.getNodeById(inputNodeTag) | ||
if (animatedNode == null || animatedNode !is ValueAnimatedNode) { | ||
throw JSApplicationCausedNativeException( | ||
"Illegal node ID set as an input for Animated.DiffClamp node") | ||
} | ||
return animatedNode.value | ||
} | ||
|
||
override fun prettyPrint(): String = | ||
"DiffClampAnimatedNode[$mTag]: InputNodeTag: $inputNodeTag min: $minValue " + | ||
"max: $maxValue lastValue: $lastValue super: ${super.prettyPrint()}" | ||
} |