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.
Convert StyleAnimatedNode.java->.kt (facebook#45761)
Summary: Pull Request resolved: facebook#45761 # Changelog: [Internal] - As in the title. Differential Revision: D60342089
- Loading branch information
1 parent
ef78652
commit c77b0dc
Showing
2 changed files
with
60 additions
and
70 deletions.
There are no files selected for viewing
70 changes: 0 additions & 70 deletions
70
...eact-native/ReactAndroid/src/main/java/com/facebook/react/animated/StyleAnimatedNode.java
This file was deleted.
Oops, something went wrong.
60 changes: 60 additions & 0 deletions
60
.../react-native/ReactAndroid/src/main/java/com/facebook/react/animated/StyleAnimatedNode.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,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" | ||
} |