-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Better reanimated shadow tree commit detection (#4949)
## Summary Proposed solution is more bullet proof solution for detecting whether currently committed shadow tree comes from reanimated. Here are the main issues with current implementation: - if there's another commit hook that is executed before `reanimated` one, then `propsRegistry_->isLastReanimatedRoot(newRootShadowNode)` may not work if the commit hook creates a copy of committed tree - when `stateReconciliation` is enabled via commit options then new tree root is created and again above detection does not work. It uses concept of `thread_local` c++ variable which has instance for each thread and RAII to ensure that the appropriate flag is set to `true` on entering commit section and reset to `false` after commit from reanimated on UI thread. ## Test plan - enable state reconciliation for commit from `reanimated` and check whether the code goes into `isReanimatedCommit` `if` body in `ReanimatedCommitHook` or - create a custom commit hook and register it before `ReanimatedCommitHook` and perform same check as above
- Loading branch information
1 parent
8101d9f
commit e33d517
Showing
5 changed files
with
56 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
#ifdef RCT_NEW_ARCH_ENABLED | ||
|
||
#include "ReanimatedCommitMarker.h" | ||
|
||
#include <react/debug/react_native_assert.h> | ||
|
||
namespace reanimated { | ||
|
||
thread_local bool ReanimatedCommitMarker::reanimatedCommitFlag_{false}; | ||
|
||
ReanimatedCommitMarker::ReanimatedCommitMarker() { | ||
react_native_assert(reanimatedCommitFlag_ != true); | ||
reanimatedCommitFlag_ = true; | ||
} | ||
|
||
ReanimatedCommitMarker::~ReanimatedCommitMarker() { | ||
reanimatedCommitFlag_ = false; | ||
} | ||
|
||
bool ReanimatedCommitMarker::isReanimatedCommit() { | ||
return reanimatedCommitFlag_; | ||
} | ||
|
||
} // namespace reanimated | ||
|
||
#endif // RCT_NEW_ARCH_ENABLED |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#pragma once | ||
#ifdef RCT_NEW_ARCH_ENABLED | ||
|
||
namespace reanimated { | ||
|
||
// This class is used to mark shadow tree commit as coming from Reanimated. | ||
// During the life of this object, isReanimatedCommit() will return true, false | ||
// otherwise. isReanimatedCommit() value change is restricted to the thread that | ||
// created the object. | ||
class ReanimatedCommitMarker { | ||
public: | ||
ReanimatedCommitMarker(); | ||
~ReanimatedCommitMarker(); | ||
|
||
static bool isReanimatedCommit(); | ||
|
||
private: | ||
static thread_local bool reanimatedCommitFlag_; | ||
}; | ||
|
||
} // namespace reanimated | ||
|
||
#endif // RCT_NEW_ARCH_ENABLED |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters