mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
8d0b5af1fc
Summary: I've noticed that `UIManagerCommitHooks` are applied after calling `layoutIfNeeded`, meaning that if a commit hook makes some changes to the tree, it needs to calculate the layout again, effectively making the first calculation redundant. This PR swaps the order of these two operations and moves `shadowTreeWillCommit` call before `layoutIfNeeded`. Thanks to this change, commit hooks don't need to manually trigger layout calculations as well as can potentially operate on unsealed nodes which can make it more efficient in some cases. Finally, this PR eliminates a crash on `emitLayoutEvents(affectedLayoutableNodes);` when commit hook actually modifies the tree and thus de-allocates old shadow nodes. cc sammy-SC ## Changelog [GENERAL] [CHANGED] - Run commit hooks before layout calculation Pull Request resolved: https://github.com/facebook/react-native/pull/36216 Test Plan: The only `UIManagerCommitHook` I could find in the OSS repo is [`TimelineController`](https://github.com/facebook/react-native/blob/8bd3edec88148d0ab1f225d2119435681fbbba33/ReactCommon/react/renderer/timeline/TimelineController.h#L26). Reviewed By: cipolleschi Differential Revision: D43569407 Pulled By: sammy-SC fbshipit-source-id: 9ab1de0954cac2eb00346be7af8c9b3572bd2c88