-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unify decorating RN runtime #4773
Merged
Merged
Conversation
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
piaskowyk
approved these changes
Jul 19, 2023
github-merge-queue bot
pushed a commit
that referenced
this pull request
Aug 26, 2023
<!-- Thanks for submitting a pull request! We appreciate you spending the time to work on these changes. Please follow the template so that the reviewers can easily understand what the code changes affect. --> ## Summary This PR implements and exposes a new API for creating worklet runtimes as well as running and scheduling worklets both from JS and C++ code. The motivation of this PR was to allow for easier integration of other third-party libraries with Reanimated worklets. The following changes were required but they were merged as separate PRs for the ease of code review: * #4608 * #4612 * #4621 * #4722 * #4723 * #4731 * #4765 * #4768 * #4773 * #4775 * #4779 * #4780 * #4785 * #4800 * #4869 * #4871 * #4929 ## Changes 1. Removed `RuntimeManager` and `JSRuntimeHelper` in favor of `WorkletRuntime` class - `WorkletRuntime` is runtime-agnostic (supports JSC/Hermes/V8), has built-in debugging support on Hermes (via Chrome DevTools Protocol), is a `jsi::HostObject` so it can be passed between JS/C++, offers method for calling worklets via callGuardDEV - Refactored all usages of UI runtime in `NativeReanimatedModule`, `AnimatedSensorModule`, `EventHandlerRegistry` - Added `WorkletRuntimeRegistry` to keep track of whether worklet runtime is still alive - Added `WorkletRuntimeCollector` that is a host object that unregisters worklet runtime in its destructor (i.e. when runtime is terminated) - Added possibility to customize name of runtime created by `ReanimatedRuntime::make` for debugging purposes 1. Added `createWorkletRuntime` function along with `runOnRuntime`, `runOnRuntimeSync` and `backgroundTask` - Added `WorkletRuntimeExample.tsx` to test out the changes 1. Removed `RuntimeDecorator` class in favor of having separate classes in order to decouple code - Moved `RuntimeDecorator::decorateRuntime` to `RNRuntimeDecorator::decorate` that injects JSI bindings specific for React Native runtime (e.g. `_WORKLET_RUNTIME`) - Moved `RuntimeDecorator::decorateUIRuntime` to `UIRuntimeDecorator::decorate` that injects UI-specific JSI bindings (e.g. `_updateProps`) - Added `WorkletRuntimeDecorator::decorate` that injects worklet-specific JSI bindings (e.g. `evalWithSourceMap` or `_makeShareableClone`) 1. Removed `CoreFunction` class and `NativeReanimatedModule::installCoreFunctions` method in favor of passing `valueUnpacker` code as a string (this is possible because of the empty closure) and installing `callGuardDEV` from a worklet 1. Refactored shareables so that they support other runtimes than only RN and UI runtime 1. Refactored `NativeReanimatedModule` constructor and members - Eliminated `LayoutAnimationsManager::setJSLogger` method in favor of passing `JSLogger` in its constructor - Moved Paper- and Fabric- only fields to `#ifdef`s - Added missing trailing underscores in member names for the purpose of consistency - Added `const` keyword wherever possible 1. Moved `jsi::Scope` from `UIScheduler::scheduleOnUI` to `NativeReanimatedModule::scheduleOnUI` in order to decouple `RuntimeManager` and `UIScheduler` and also because some UI jobs may not need runtime access ## Future plans - Split C++ headers into public and private - Create UI runtime using `createWorkletRuntime` from JS instead of from C++ - Pass `valueUnpacker` code via argument of `ReanimatedModule.installTurboModule` method of instead of calling `NativeReanimatedModule.installValueUnpacker` - Implement `createWorkletRuntime` on web? ## Test plan 💣
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
This PR moves duplicated logic of decorating RN runtime from
NativeProxy.cpp
andREAModule.mm
intoRuntimeDecorator::decorateRNRuntime
. I've also tried to move__reanimatedModuleProxy
(NativeReanimatedModule
) there but there were some problems with circular headers which I couldn't solve easily so I'm leaving this for the next PR.Test plan