Skip to content

Commit

Permalink
Convert StyleAnimatedNode.java->.kt (facebook#45761)
Browse files Browse the repository at this point in the history
Summary:
Pull Request resolved: facebook#45761

# Changelog:
[Internal] -

As in the title.

Differential Revision: D60342089
  • Loading branch information
rshest authored and facebook-github-bot committed Jul 29, 2024
1 parent ef78652 commit c77b0dc
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 70 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/*
* 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.JavaOnlyMap
import com.facebook.react.bridge.ReadableMap

/**
* Native counterpart of style animated node (see AnimatedStyle class in AnimatedImplementation.js)
*/
internal class StyleAnimatedNode(
config: ReadableMap,
private val nativeAnimatedNodesManager: NativeAnimatedNodesManager
) : AnimatedNode() {
private val propMapping: MutableMap<String, Int>

init {
val style = config.getMap("style")
val iter = style?.keySetIterator()
propMapping = HashMap()
while (iter != null && iter.hasNextKey()) {
val propKey = iter.nextKey()
val nodeIndex = style.getInt(propKey)
propMapping[propKey] = nodeIndex
}
}

public fun collectViewUpdates(propsMap: JavaOnlyMap) {
for ((key, value) in propMapping) {
val node = nativeAnimatedNodesManager.getNodeById(value)
requireNotNull(node) { "Mapped style node does not exist" }
if (node is TransformAnimatedNode) {
node.collectViewUpdates(propsMap)
} else if (node is ValueAnimatedNode) {
val animatedObject = node.getAnimatedObject()
if (animatedObject is Int) {
propsMap.putInt(key, animatedObject)
} else if (animatedObject is String) {
propsMap.putString(key, animatedObject)
} else {
propsMap.putDouble(key, node.getValue())
}
} else if (node is ColorAnimatedNode) {
propsMap.putInt(key, node.color)
} else if (node is ObjectAnimatedNode) {
node.collectViewUpdates(key, propsMap)
} else {
throw IllegalArgumentException(
"Unsupported type of node used in property node ${node.javaClass}")
}
}
}

override fun prettyPrint(): String = "StyleAnimatedNode[$tag] mPropMapping: $propMapping"
}

0 comments on commit c77b0dc

Please sign in to comment.