-
-
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.
Modify reanimated props updates (#6330)
## Summary This PR changes the way `performOperations` and `ReanimatedCommitHook` are synchronized. The current implementations faces 2 problems: 1. Updates that come through `performOperations` after `pleaseSkipReanimatedCommit` is called in the commit hook will be deferred until the next commit. Usually it's fine since the next commit will be triggered by the next animation frame. But if there was a singular update scheduled through Reanimated, we might not see the change for a long time. This issue is more thoroughly explained in [this issue](#6245). 2. In `ReanimatedCommitMarker` there is an assumption that there can be at most one commit happening on a given thread (i.e. there can't be nested commits). This isn't true, since there can be an event listener that commits some changes in a reaction to a native mount/unmount (which is a part of the commit function). [This exact scenario was observed in the New Expensify App with `react-native-keyboard-controller`](Expensify/App#44437 (comment)). At first I thought this is a mistake, but [this PR in RN](facebook/react-native@5f0435f) seems to allow for scenarios like that. Applied fixes: ad 1. Now instead of resetting the skip flag in reanimated after a transaction is mounted (via MountHook), we reset the flag whenever a non-empty batch is read in `performOperations`. This ensures that we don't make an unnecessary commit, but never skip any updates. ad 2. Now we mark reanimated commits through `ReanimatedCommitShadowNode`. This is a class derived from ShadowNode that allows us to modify the root nodes traits_ (and add our custom trait). This ensures that even if the root node gets cloned it will retain the information. We couldn't derive from `RootShadowNode` since it is a final class. ## Test plan
- Loading branch information
1 parent
a9dc639
commit 071e513
Showing
9 changed files
with
63 additions
and
139 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
26 changes: 0 additions & 26 deletions
26
packages/react-native-reanimated/Common/cpp/Fabric/ReanimatedCommitMarker.cpp
This file was deleted.
Oops, something went wrong.
23 changes: 0 additions & 23 deletions
23
packages/react-native-reanimated/Common/cpp/Fabric/ReanimatedCommitMarker.h
This file was deleted.
Oops, something went wrong.
30 changes: 30 additions & 0 deletions
30
packages/react-native-reanimated/Common/cpp/Fabric/ReanimatedCommitShadowNode.h
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,30 @@ | ||
#pragma once | ||
#ifdef RCT_NEW_ARCH_ENABLED | ||
|
||
namespace reanimated { | ||
|
||
// We use this trait to mark that a commit was created by Reanimated. | ||
// Traits are copied when nodes are cloned, so this information | ||
// won't be lost unless someone explicitly overrides it. | ||
// We need this information to skip unnecessary updates in | ||
// the commit hook. | ||
// Currently RN traits go up to 10, so hopefully | ||
// the arbitrarily chosen number 27 will be safe :) | ||
constexpr ShadowNodeTraits::Trait ReanimatedCommitTrait{1 << 27}; | ||
|
||
class ReanimatedCommitShadowNode : public ShadowNode { | ||
public: | ||
inline void setReanimatedCommitTrait() { | ||
traits_.set(ReanimatedCommitTrait); | ||
} | ||
inline void unsetReanimatedCommitTrait() { | ||
traits_.unset(ReanimatedCommitTrait); | ||
} | ||
inline bool hasReanimatedCommitTrait() { | ||
return traits_.check(ReanimatedCommitTrait); | ||
} | ||
}; | ||
|
||
} // namespace reanimated | ||
|
||
#endif // RCT_NEW_ARCH_ENABLED |
31 changes: 0 additions & 31 deletions
31
packages/react-native-reanimated/Common/cpp/Fabric/ReanimatedMountHook.cpp
This file was deleted.
Oops, something went wrong.
33 changes: 0 additions & 33 deletions
33
packages/react-native-reanimated/Common/cpp/Fabric/ReanimatedMountHook.h
This file was deleted.
Oops, something went wrong.
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