Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,6 @@ internal class ColorAnimatedNode(
private var nativeColor: ReadableMap? = null
private var nativeColorApplied = false

init {
onUpdateConfig(config)
}

val color: Int
get() {
tryApplyNativeColor()
Expand All @@ -45,6 +41,17 @@ internal class ColorAnimatedNode(
return normalize(r, g, b, a)
}

private val context: Context?
get() {
// There are cases where the activity may not exist (such as for VRShell panel apps). In this
// case we will search for a view associated with a PropsAnimatedNode to get the context.
return reactApplicationContext.currentActivity ?: getContextHelper(this)
}

init {
onUpdateConfig(config)
}

override fun onUpdateConfig(config: ReadableMap?) {
if (config != null) {
rNodeId = config.getInt("r")
Expand Down Expand Up @@ -84,13 +91,6 @@ internal class ColorAnimatedNode(
nativeColorApplied = true
}

private val context: Context?
get() {
// There are cases where the activity may not exist (such as for VRShell panel apps). In this
// case we will search for a view associated with a PropsAnimatedNode to get the context.
return reactApplicationContext.currentActivity ?: getContextHelper(this)
}

companion object {
private fun getContextHelper(node: AnimatedNode): Context? {
// Search children depth-first until we get to a PropsAnimatedNode, from which we can
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,17 @@ internal class DiffClampAnimatedNode(
private val maxValue: Double
private var lastValue: Double = 0.0

private val inputNodeValue: Double
get() {
val animatedNode = nativeAnimatedNodesManager.getNodeById(inputNodeTag)
if (animatedNode == null || animatedNode !is ValueAnimatedNode) {
throw JSApplicationCausedNativeException(
"Illegal node ID set as an input for Animated.DiffClamp node"
)
}
return animatedNode.getValue()
}

init {
inputNodeTag = config.getInt("input")
minValue = config.getDouble("min")
Expand All @@ -35,17 +46,6 @@ internal class DiffClampAnimatedNode(
nodeValue = min(max(nodeValue + diff, minValue), maxValue)
}

private val inputNodeValue: Double
get() {
val animatedNode = nativeAnimatedNodesManager.getNodeById(inputNodeTag)
if (animatedNode == null || animatedNode !is ValueAnimatedNode) {
throw JSApplicationCausedNativeException(
"Illegal node ID set as an input for Animated.DiffClamp node"
)
}
return animatedNode.getValue()
}

override fun prettyPrint(): String =
"DiffClampAnimatedNode[$tag]: InputNodeTag: $inputNodeTag min: $minValue " +
"max: $maxValue lastValue: $lastValue super: ${super.prettyPrint()}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ public class NativeAnimatedNodesManager(
)
if (node !is ValueAnimatedNode) {
throw JSApplicationIllegalArgumentException(
("startAnimatingNode: Animated node [${animatedNodeTag}] should be of type ${ValueAnimatedNode::class.java.name}")
("startAnimatingNode: Animated node [${animatedNodeTag}] should be of type ValueAnimatedNode")
)
}

Expand Down Expand Up @@ -389,7 +389,7 @@ public class NativeAnimatedNodesManager(
)
if (node !is PropsAnimatedNode) {
throw JSApplicationIllegalArgumentException(
("connectAnimatedNodeToView: Animated node connected to view [${viewTag}] should be of type ${PropsAnimatedNode::class.java.name}")
("connectAnimatedNodeToView: Animated node connected to view [${viewTag}] should be of type PropsAnimatedNode")
)
}
checkNotNull(reactApplicationContext) {
Expand Down Expand Up @@ -420,7 +420,7 @@ public class NativeAnimatedNodesManager(
)
if (node !is PropsAnimatedNode) {
throw JSApplicationIllegalArgumentException(
("disconnectAnimatedNodeFromView: Animated node connected to view [${viewTag}] should be of type ${PropsAnimatedNode::class.java.name}")
("disconnectAnimatedNodeFromView: Animated node connected to view [${viewTag}] should be of type PropsAnimatedNode")
)
}
node.disconnectFromView(viewTag)
Expand Down Expand Up @@ -463,7 +463,7 @@ public class NativeAnimatedNodesManager(
// default values since it will never actually update the view.
if (node !is PropsAnimatedNode) {
throw JSApplicationIllegalArgumentException(
"Animated node connected to view [?] should be of type ${PropsAnimatedNode::class.java.name}"
"Animated node connected to view [?] should be of type PropsAnimatedNode"
)
}
node.restoreDefaultValues()
Expand All @@ -483,7 +483,7 @@ public class NativeAnimatedNodesManager(
)
if (node !is ValueAnimatedNode) {
throw JSApplicationIllegalArgumentException(
("addAnimatedEventToView: Animated node on view [${viewTag}] connected to event handler (${eventHandlerName}) should be of type ${ValueAnimatedNode::class.java.name}")
("addAnimatedEventToView: Animated node on view [${viewTag}] connected to event handler (${eventHandlerName}) should be of type ValueAnimatedNode")
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ internal class PropsAnimatedNode(
private val propMap = JavaOnlyMap()
private var connectedViewUIManager: UIManager? = null

val connectedView: View?
// resolveView throws an [IllegalViewOperationException] when the view doesn't exist
// (this can happen if the surface is being deallocated).
get() = runCatching { connectedViewUIManager?.resolveView(connectedViewTag) }.getOrNull()

init {
val props = config.getMap("props")
val iter = props?.keySetIterator()
Expand Down Expand Up @@ -112,11 +117,6 @@ internal class PropsAnimatedNode(
connectedViewUIManager?.synchronouslyUpdateViewOnUIThread(connectedViewTag, propMap)
}

val connectedView: View?
// resolveView throws an [IllegalViewOperationException] when the view doesn't exist
// (this can happen if the surface is being deallocated).
get() = runCatching { connectedViewUIManager?.resolveView(connectedViewTag) }.getOrNull()

override fun prettyPrint(): String =
"PropsAnimatedNode[$tag] connectedViewTag: $connectedViewTag " +
"propNodeMapping: $propNodeMapping propMap: $propMap"
Expand Down
Loading