Skip to content

Commit cf5040b

Browse files
zeyapfacebook-github-bot
authored andcommitted
fix array type parsing in DynamicEventPayload::extractValue (#53689)
Summary: Pull Request resolved: #53689 ## Changelog: [General] [Fixed] - fix array type parsing in DynamicEventPayload::extractValue When unwrapping event mapping like `e.nativeEvent.touches[0].locationX` e.g. for Animated.event like below, ``` onTouchMove={Animated.event( [ { nativeEvent: { touches: { 0: {locationX: animatedValue}, }, }, }, ], {useNativeDriver: true}, )} ``` here it'll throw exception `terminating due to uncaught exception of type folly::TypeError: TypeError: expected dynamic type 'object', but had type 'array'` when getting into folly dynamic array, because array index in the event path is string instead of integer Reviewed By: rozele Differential Revision: D82050538 fbshipit-source-id: ed25c8917b90190c995d1fcd6d60af207e72e270
1 parent 019a553 commit cf5040b

1 file changed

Lines changed: 3 additions & 3 deletions

File tree

packages/react-native/ReactCommon/react/renderer/core/DynamicEventPayload.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@ std::optional<double> DynamicEventPayload::extractValue(
2727
auto dynamic = payload_;
2828
for (auto& key : path) {
2929
auto type = dynamic.type();
30-
if ((type == folly::dynamic::Type::OBJECT ||
31-
type == folly::dynamic::Type::ARRAY) &&
32-
!dynamic.empty()) {
30+
if (type == folly::dynamic::Type::OBJECT && !dynamic.empty()) {
3331
dynamic = folly::dynamic(dynamic[key]);
32+
} else if (type == folly::dynamic::Type::ARRAY && !dynamic.empty()) {
33+
dynamic = folly::dynamic(dynamic[std::stoi(key)]);
3434
}
3535
}
3636
if (dynamic.type() == folly::dynamic::Type::DOUBLE) {

0 commit comments

Comments
 (0)