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 AnimatedNode.java to Kotlin (facebook#45601)
Summary: Pull Request resolved: facebook#45601 AnimatedNode.java -> AnimatedNode.kt changelog: [internal] internal Reviewed By: tdn120 Differential Revision: D60076481
- Loading branch information
1 parent
cb6ea49
commit 9802ef8
Showing
3 changed files
with
91 additions
and
78 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
78 changes: 0 additions & 78 deletions
78
...ges/react-native/ReactAndroid/src/main/java/com/facebook/react/animated/AnimatedNode.java
This file was deleted.
Oops, something went wrong.
74 changes: 74 additions & 0 deletions
74
packages/react-native/ReactAndroid/src/main/java/com/facebook/react/animated/AnimatedNode.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,74 @@ | ||
/* | ||
* 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 java.util.ArrayList | ||
|
||
/** Base class for all Animated.js library node types that can be created on the "native" side. */ | ||
public abstract class AnimatedNode { | ||
|
||
public companion object { | ||
public const val INITIAL_BFS_COLOR: Int = 0 | ||
public const val DEFAULT_ANIMATED_NODE_CHILD_COUNT: Int = 1 | ||
} | ||
|
||
// TODO: T196787278 Reduce the visibility of these fields to package once we have | ||
// converted the whole module to Kotlin | ||
|
||
@JvmField | ||
internal var mChildren: MutableList<AnimatedNode>? = | ||
null /* lazy-initialized when a child is added */ | ||
@JvmField internal var mActiveIncomingNodes: Int = 0 | ||
@JvmField internal var mBFSColor: Int = INITIAL_BFS_COLOR | ||
@JvmField internal var mTag: Int = -1 | ||
|
||
public fun addChild(child: AnimatedNode): Unit { | ||
val children = | ||
mChildren | ||
?: ArrayList<AnimatedNode>(DEFAULT_ANIMATED_NODE_CHILD_COUNT).also { mChildren = it } | ||
|
||
children.add(child) | ||
child.onAttachedToNode(this) | ||
} | ||
|
||
public fun removeChild(child: AnimatedNode): Unit { | ||
val children = mChildren ?: return | ||
child.onDetachedFromNode(this) | ||
children.remove(child) | ||
} | ||
|
||
/** | ||
* Subclasses may want to override this method in order to store a reference to the parent of a | ||
* given node that can then be used to calculate current node's value in {@link #update}. In that | ||
* case it is important to also override {@link #onDetachedFromNode} to clear that reference once | ||
* current node gets detached. | ||
*/ | ||
public open fun onAttachedToNode(parent: AnimatedNode): Unit = Unit | ||
|
||
/** See {@link #onAttachedToNode} */ | ||
public open fun onDetachedFromNode(parent: AnimatedNode): Unit = Unit | ||
|
||
/** | ||
* This method will be run on each node at most once every repetition of the animation loop. It | ||
* will be executed on a node only when all the node's parent has already been updated. Therefore | ||
* it can be used to calculate node's value. | ||
*/ | ||
public open fun update(): Unit = Unit | ||
|
||
/** | ||
* Pretty-printer for the AnimatedNode. Only called in production pre-crash for debug diagnostics. | ||
*/ | ||
public abstract fun prettyPrint(): String | ||
|
||
public fun prettyPrintWithChildren(): String { | ||
val children = StringBuilder() | ||
mChildren?.forEach { child -> children.append(" ${child.mTag}") } | ||
|
||
return prettyPrint() + if (children.isNotEmpty()) " children: $children" else "" | ||
} | ||
} |