Skip to content

Commit 30fd0c4

Browse files
zeyapmeta-codesync[bot]
authored andcommitted
Log error when unsupported type is passed to interpolation outputRange (#55209)
Summary: Pull Request resolved: #55209 ## Changelog: [Android] [Changed] - Log error when unsupported type is passed to interpolation outputRange Add error logging when unsupported value types (like PlatformColor) are passed to interpolation outputRange. This prevents a ClassCastException crash by detecting non-Number types and logging an error instead. Reviewed By: javache Differential Revision: D90863942 fbshipit-source-id: d6a3b2dbde859ae86a1bc4a5dfcc33a9ee369dd1
1 parent 95bac85 commit 30fd0c4

1 file changed

Lines changed: 12 additions & 0 deletions

File tree

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/animated/InterpolationAnimatedNode.kt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
package com.facebook.react.animated
99

1010
import androidx.core.graphics.ColorUtils
11+
import com.facebook.common.logging.FLog
1112
import com.facebook.react.bridge.JSApplicationIllegalArgumentException
1213
import com.facebook.react.bridge.ReadableArray
1314
import com.facebook.react.bridge.ReadableMap
@@ -44,6 +45,15 @@ internal class InterpolationAnimatedNode(config: ReadableMap) : ValueAnimatedNod
4445
outputType = OutputType.String
4546
outputRange = fromStringPattern(output)
4647
pattern = output.getString(0)
48+
} else if (output != null && output.size() > 0 && output.getType(0) != ReadableType.Number) {
49+
FLog.e(
50+
TAG,
51+
"Unsupported value type in interpolation outputRange: expected Number but got " +
52+
"${output.getType(0)}. This may indicate PlatformColor or other unsupported " +
53+
"values are being used. Interpolation will not work correctly.",
54+
)
55+
outputType = OutputType.Number
56+
outputRange = DoubleArray(output.size())
4757
} else {
4858
outputType = OutputType.Number
4959
outputRange = fromDoubleArray(output)
@@ -101,6 +111,8 @@ internal class InterpolationAnimatedNode(config: ReadableMap) : ValueAnimatedNod
101111
"InterpolationAnimatedNode[$tag] super: ${super.prettyPrint()}"
102112

103113
companion object {
114+
private const val TAG = "InterpolationAnimatedNode"
115+
104116
const val EXTRAPOLATE_TYPE_IDENTITY: String = "identity"
105117
const val EXTRAPOLATE_TYPE_CLAMP: String = "clamp"
106118
const val EXTRAPOLATE_TYPE_EXTEND: String = "extend"

0 commit comments

Comments
 (0)