Animated: Generalize ReactElement Check in AnimatedObject (#46273)

Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/46273

The implementation of `AnimatedObject` should recurse through its structure and consistently treat `ReactElement` objects as opaque.

It wasn't consistent. This makes it consistent.

Changelog:
[General][Fixed] - Fixed undefined behavior in certain scenarios when `ReactElement` objects are supplied to Animated components

Reviewed By: javache

Differential Revision: D62012006

fbshipit-source-id: e6c3ac472945af8070735f1df856ff88b30a5624
This commit is contained in:
Tim Yung
2024-08-30 11:17:04 -07:00
committed by Facebook GitHub Bot
parent 7d7f94cc98
commit 56937d646c
@@ -23,7 +23,8 @@ function isPlainObject(value: any): boolean {
return (
value !== null &&
typeof value === 'object' &&
Object.getPrototypeOf(value).isPrototypeOf(Object)
Object.getPrototypeOf(value).isPrototypeOf(Object) &&
!React.isValidElement(value)
);
}
@@ -81,10 +82,6 @@ export function hasAnimatedNode(value: any, depth: number = 0): boolean {
}
}
} else if (isPlainObject(value)) {
// Don't consider React elements
if (React.isValidElement(value)) {
return false;
}
for (const key in value) {
if (hasAnimatedNode(value[key], depth + 1)) {
return true;