Skip to content

Commit

Permalink
'[skip ci] [RN][Android] TransformAnimatedNode Java->Kotlin (#45765)
Browse files Browse the repository at this point in the history
Summary:
Pull Request resolved: #45765

# Changelog:
[Internal] -

As in the title.

Reviewed By: cortinico

Differential Revision: D60347833
  • Loading branch information
rshest authored and facebook-github-bot committed Jul 30, 2024
1 parent 6ea843e commit e677867
Show file tree
Hide file tree
Showing 2 changed files with 87 additions and 93 deletions.

This file was deleted.

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

/**
* Native counterpart of transform animated node (see AnimatedTransform class in
* AnimatedImplementation.js)
*/
internal class TransformAnimatedNode(
config: ReadableMap,
private val nativeAnimatedNodesManager: NativeAnimatedNodesManager
) : AnimatedNode() {
private val transformConfigs: MutableList<TransformConfig>

init {
val transforms = config.getArray("transforms")
transformConfigs =
if (transforms == null) mutableListOf()
else
MutableList<TransformConfig>(transforms.size()) { i ->
val transformConfigMap = transforms.getMap(i)
val property = transformConfigMap.getString("property")
val type = transformConfigMap.getString("type")
if (type == "animated") {
val transformConfig = AnimatedTransformConfig()
transformConfig.property = property
transformConfig.nodeTag = transformConfigMap.getInt("nodeTag")
transformConfig
} else {
val transformConfig = StaticTransformConfig()
transformConfig.property = property
transformConfig.value = transformConfigMap.getDouble("value")
transformConfig
}
}
}

public fun collectViewUpdates(propsMap: JavaOnlyMap) {
val transforms =
MutableList<JavaOnlyMap>(transformConfigs.size) { i ->
val transformConfig = transformConfigs[i]
val transform =
if (transformConfig is AnimatedTransformConfig) {
val nodeTag = transformConfig.nodeTag
val node = nativeAnimatedNodesManager.getNodeById(nodeTag)
if (node == null) {
throw IllegalArgumentException("Mapped style node does not exist")
} else if (node is ValueAnimatedNode) {
node.getValue()
} else {
throw IllegalArgumentException(
"Unsupported type of node used as a transform child " +
"node " +
node.javaClass)
}
} else {
(transformConfig as StaticTransformConfig).value
}
JavaOnlyMap.of(transformConfig.property, transform)
}
propsMap.putArray("transform", JavaOnlyArray.from(transforms))
}

override fun prettyPrint(): String =
"TransformAnimatedNode[$tag]: transformConfigs: $transformConfigs"

private open inner class TransformConfig {
var property: String? = null
}

private inner class AnimatedTransformConfig : TransformConfig() {
var nodeTag = 0
}

private inner class StaticTransformConfig : TransformConfig() {
var value = 0.0
}
}

0 comments on commit e677867

Please sign in to comment.