mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Fix unsafe downcasting in ShadowTree::emitLayoutEvents (#44058)
Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/44058 ## Changelog: [Internal] - This was revealed when running an ASAN build on MacOS - we were doing an unsafe downcast from `LayoutableShadowNode->ViewShadowNode` inside `ShadowTree::emitLayoutEvents`. Which, even though incidentally worked, is generally unsafe, as we may get e.g. `ImageShadowNode` there, which doesn't inherit from `ViewShadowNode`. That downcast to `ViewShadowNode` wasn't even required, to begin with, as all the needed information can be already extracted from the `LayoutableShadowNode` itself. Reviewed By: christophpurrer, javache Differential Revision: D56062334 fbshipit-source-id: 08d5b3f5e0c57dc51b051d23506c7933581fea29
This commit is contained in:
committed by
Facebook GitHub Bot
parent
5aea518d88
commit
72a78d674c
@@ -575,15 +575,14 @@ void ShadowTree::emitLayoutEvents(
|
||||
|
||||
for (const auto* layoutableNode : affectedLayoutableNodes) {
|
||||
// Only instances of `ViewShadowNode` (and subclasses) are supported.
|
||||
const auto& viewShadowNode =
|
||||
static_cast<const ViewShadowNode&>(*layoutableNode);
|
||||
const auto& viewEventEmitter =
|
||||
static_cast<const ViewEventEmitter&>(*viewShadowNode.getEventEmitter());
|
||||
|
||||
const auto& viewEventEmitter = static_cast<const BaseViewEventEmitter&>(
|
||||
*layoutableNode->getEventEmitter());
|
||||
|
||||
// Checking if the `onLayout` event was requested for the particular Shadow
|
||||
// Node.
|
||||
const auto& viewProps =
|
||||
static_cast<const ViewProps&>(*viewShadowNode.getProps());
|
||||
static_cast<const BaseViewProps&>(*layoutableNode->getProps());
|
||||
if (!viewProps.onLayout) {
|
||||
continue;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user