forked from facebook/react-native
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Migrate ValueAnimatedNode to Kotlin (facebook#45651)
Summary: Pull Request resolved: facebook#45651 ValueAnimatedNode.java -> ValueAnimatedNode.kt changelog: [internal] internal Reviewed By: rshest Differential Revision: D60188318
- Loading branch information
1 parent
caa4ac7
commit 748557c
Showing
15 changed files
with
88 additions
and
104 deletions.
There are no files selected for viewing
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
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
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
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
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
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
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
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
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
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
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
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
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
66 changes: 0 additions & 66 deletions
66
...eact-native/ReactAndroid/src/main/java/com/facebook/react/animated/ValueAnimatedNode.java
This file was deleted.
Oops, something went wrong.
50 changes: 50 additions & 0 deletions
50
.../react-native/ReactAndroid/src/main/java/com/facebook/react/animated/ValueAnimatedNode.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,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.ReadableMap | ||
|
||
/** | ||
* Basic type of animated node that maps directly from {@code Animated.Value(x)} of Animated.js | ||
* library. | ||
*/ | ||
internal open class ValueAnimatedNode(config: ReadableMap? = null) : AnimatedNode() { | ||
@JvmField internal var nodeValue: Double = config?.getDouble("value") ?: Double.NaN | ||
@JvmField internal var offset: Double = config?.getDouble("offset") ?: 0.0 | ||
private var valueListener: AnimatedNodeValueListener? = null | ||
|
||
public fun getValue(): Double { | ||
if ((offset + nodeValue).isNaN()) { | ||
this.update() | ||
} | ||
return offset + nodeValue | ||
} | ||
|
||
open fun getAnimatedObject(): Any? = null | ||
|
||
public fun flattenOffset(): Unit { | ||
nodeValue += offset | ||
offset = 0.0 | ||
} | ||
|
||
public fun extractOffset(): Unit { | ||
offset += nodeValue | ||
nodeValue = 0.0 | ||
} | ||
|
||
public fun onValueUpdate(): Unit { | ||
valueListener?.onValueUpdate(getValue()) | ||
} | ||
|
||
public fun setValueListener(listener: AnimatedNodeValueListener?): Unit { | ||
valueListener = listener | ||
} | ||
|
||
override public fun prettyPrint(): String = | ||
"ValueAnimatedNode[$tag]: value: $nodeValue offset: $offset" | ||
} |