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.
'[skip ci] [RN][Android] TransformAnimatedNode Java->Kotlin (facebook…
…#45765) Summary: Pull Request resolved: facebook#45765 # Changelog: [Internal] - As in the title. Differential Revision: D60347833
- Loading branch information
1 parent
f7cf222
commit b19ae7d
Showing
2 changed files
with
85 additions
and
93 deletions.
There are no files selected for viewing
93 changes: 0 additions & 93 deletions
93
...-native/ReactAndroid/src/main/java/com/facebook/react/animated/TransformAnimatedNode.java
This file was deleted.
Oops, something went wrong.
85 changes: 85 additions & 0 deletions
85
...ct-native/ReactAndroid/src/main/java/com/facebook/react/animated/TransformAnimatedNode.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,85 @@ | ||
/* | ||
* 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 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 | ||
} | ||
|
||
private val transformConfigs: MutableList<TransformConfig> | ||
|
||
init { | ||
val transforms = config.getArray("transforms") | ||
val size = transforms?.size() ?: 0 | ||
transformConfigs = ArrayList(size) | ||
if (transforms != null) { | ||
for (i in 0 until size) { | ||
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") | ||
transformConfigs.add(transformConfig) | ||
} else { | ||
val transformConfig = StaticTransformConfig() | ||
transformConfig.property = property | ||
transformConfig.value = transformConfigMap.getDouble("value") | ||
transformConfigs.add(transformConfig) | ||
} | ||
} | ||
} | ||
} | ||
|
||
public fun collectViewUpdates(propsMap: JavaOnlyMap) { | ||
val transforms: MutableList<JavaOnlyMap?> = ArrayList(transformConfigs.size) | ||
for (transformConfig in transformConfigs) { | ||
val value = | ||
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 | ||
} | ||
transforms.add(JavaOnlyMap.of(transformConfig.property, value)) | ||
} | ||
propsMap.putArray("transform", JavaOnlyArray.from(transforms)) | ||
} | ||
|
||
override fun prettyPrint(): String = | ||
"TransformAnimatedNode[$tag]: transformConfigs: $transformConfigs" | ||
} |