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. Reviewed By: cortinico Differential Revision: D60347833
- Loading branch information
1 parent
6ea843e
commit e677867
Showing
2 changed files
with
87 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.
87 changes: 87 additions & 0 deletions
87
...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,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 | ||
} | ||
} |