Skip to content

Commit

Permalink
Migrate AnimatedNode.java to Kotlin
Browse files Browse the repository at this point in the history
Summary: AnimatedNode.java  -> AnimatedNode.kt

Differential Revision: D60076481
  • Loading branch information
arushikesarwani94 authored and facebook-github-bot committed Jul 23, 2024
1 parent 9e64d09 commit 7dfe8c5
Show file tree
Hide file tree
Showing 3 changed files with 95 additions and 78 deletions.
21 changes: 21 additions & 0 deletions packages/react-native/ReactAndroid/api/ReactAndroid.api
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,27 @@ public abstract interface class com/facebook/react/ViewManagerOnDemandReactPacka
public abstract fun getViewManagerNames (Lcom/facebook/react/bridge/ReactApplicationContext;)Ljava/util/Collection;
}

public abstract class com/facebook/react/animated/AnimatedNode {
public static final field Companion Lcom/facebook/react/animated/AnimatedNode$Companion;
public static final field DEFAULT_ANIMATED_NODE_CHILD_COUNT I
public static final field INITIAL_BFS_COLOR I
public field mActiveIncomingNodes I
public field mBFSColor I
public field mChildren Ljava/util/List;
public field mTag I
public fun <init> ()V
public final fun addChild (Lcom/facebook/react/animated/AnimatedNode;)V
public fun onAttachedToNode (Lcom/facebook/react/animated/AnimatedNode;)V
public fun onDetachedFromNode (Lcom/facebook/react/animated/AnimatedNode;)V
public abstract fun prettyPrint ()Ljava/lang/String;
public final fun prettyPrintWithChildren ()Ljava/lang/String;
public final fun removeChild (Lcom/facebook/react/animated/AnimatedNode;)V
public fun update ()V
}

public final class com/facebook/react/animated/AnimatedNode$Companion {
}

public class com/facebook/react/animated/NativeAnimatedModule : com/facebook/fbreact/specs/NativeAnimatedModuleSpec, com/facebook/react/bridge/LifecycleEventListener, com/facebook/react/bridge/UIManagerListener {
public static final field ANIMATED_MODULE_DEBUG Z
public fun <init> (Lcom/facebook/react/bridge/ReactApplicationContext;)V
Expand Down

This file was deleted.

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
}

@JvmField
public var mChildren: MutableList<AnimatedNode>? =
null /* lazy-initialized when a child is added */
@JvmField public var mActiveIncomingNodes: Int = 0
@JvmField public var mBFSColor: Int = INITIAL_BFS_COLOR
@JvmField public var mTag: Int = -1

public fun addChild(child: AnimatedNode): Unit {
if (mChildren == null) {
mChildren = ArrayList(DEFAULT_ANIMATED_NODE_CHILD_COUNT)
}
requireNotNull(mChildren).add(child)
child.onAttachedToNode(this)
}

public fun removeChild(child: AnimatedNode): Unit {
if (mChildren == null) {
return
}
child.onDetachedFromNode(this)
requireNotNull(mChildren).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 {
var children: String = ""
if (!mChildren.isNullOrEmpty()) {
mChildren?.forEach { child -> children += " ${child.mTag}" }
}

return prettyPrint() + if (children.isNotEmpty()) " children: $children" else ""
}
}

0 comments on commit 7dfe8c5

Please sign in to comment.