refactor: replace makeMutable with createShareable - #4406
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughSummary by CodeRabbit
WalkthroughThe wrapper loads Worklets independently from Reanimated and conditionally installs UI runtime bindings. Event handlers lazily create shareable update maps when the required runtime capabilities are available. ChangesWorklets event handler integration
Sequence Diagram(s)sequenceDiagram
participant EventHandler
participant Worklets
participant UIRuntime
EventHandler->>Worklets: create shareable update map
Worklets->>UIRuntime: initialize map on UI runtime
UIRuntime-->>EventHandler: return shareable map
Possibly related PRs
Suggested reviewers: 🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Pull request overview
This PR updates the Reanimated integration in the v3 gesture-handler codepath to use react-native-worklets shareables (createShareable) instead of Reanimated’s makeMutable, and exposes Worklets alongside Reanimated from the shared wrapper.
Changes:
- Switch the per-handler “last update event” map from
Reanimated.makeMutabletoWorklets.createShareable. - Extend the Reanimated wrapper to optionally load/export
react-native-workletsand pass its UI runtime holder during runtime-bindings installation.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| packages/react-native-gesture-handler/src/v3/hooks/callbacks/useReanimatedEventHandler.ts | Replaces makeMutable map creation with Worklets shareable map and updates related types/comments. |
| packages/react-native-gesture-handler/src/handlers/gestures/reanimatedWrapper.ts | Adds optional Worklets loading/export and adjusts UI runtime bindings installation setup. |
Suppressed comments (1)
packages/react-native-gesture-handler/src/v3/hooks/callbacks/useReanimatedEventHandler.ts:112
- This comment is inaccurate with the current logic:
updateEventMapbecomesundefinedwhen Worklets is absent, butReanimated?.useEvent(...)can still register the callback if Reanimated is present. Either adjust the comment, or (preferably) restore the Reanimated fallback soupdateEventMapis onlyundefinedwhen neither runtime provider is available.
// Undefined only when Worklets is absent — and then this callback is
// never registered (`Reanimated?.useEvent` below short-circuits).
if (updateEventMap === undefined) {
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In
`@packages/react-native-gesture-handler/src/handlers/gestures/reanimatedWrapper.ts`:
- Around line 35-45: The Jest expectation for installUIRuntimeBindings is
failing because runtime binding initialization is invoked more than once. Update
the WorkletsPackage integration in reanimatedWrapper.ts (around lines 35-45) and
the related useReanimatedEventHandler.ts integration (around lines 7-10) so the
binding installation is performed only once, while preserving the existing
shareable-host and event-handler behavior; verify yarn test passes.
In
`@packages/react-native-gesture-handler/src/v3/hooks/callbacks/useReanimatedEventHandler.ts`:
- Around line 31-40: Update the shareable-state fallback in the hook using
Reanimated’s makeMutable API when Worklets.createShareable or UIRuntimeId is
unavailable, so Reanimated.useEvent can still register and execute gesture
callbacks. Revise the comment near the Reanimated.useEvent registration to
reflect that missing Worklets APIs do not short-circuit registration.
🪄 Autofix
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 386e69e8-e8d3-4d28-8b66-673390aca58e
📒 Files selected for processing (2)
packages/react-native-gesture-handler/src/handlers/gestures/reanimatedWrapper.tspackages/react-native-gesture-handler/src/v3/hooks/callbacks/useReanimatedEventHandler.ts
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In
`@packages/react-native-gesture-handler/src/handlers/gestures/installUIRuntimeBindings.ts`:
- Around line 5-9: Guard the Worklets dependency before invoking
installUIRuntimeBindings: pass Worklets?.getUIRuntimeHolder or initialize the
unsupported-setup contract as an empty object so the installer receives
undefined instead of dereferencing an unavailable module. Add a test covering
the missing react-native-worklets case and confirming graceful installation
without throwing.
In
`@packages/react-native-gesture-handler/src/v3/hooks/callbacks/lastUpdateEventMap.ts`:
- Around line 9-14: Update the capability guard in the last-update event map
factory so missing Worklets.createShareable or Worklets.UIRuntimeId does not
immediately return undefined when Reanimated is available; preserve and use the
existing Reanimated-backed shared-map fallback for those cases, while retaining
the undefined result only when neither supported implementation is available.
🪄 Autofix
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 92f6f036-b303-4287-a016-f228bf9dae5a
📒 Files selected for processing (6)
packages/react-native-gesture-handler/src/handlers/gestures/installUIRuntimeBindings.tspackages/react-native-gesture-handler/src/handlers/gestures/installUIRuntimeBindings.web.tspackages/react-native-gesture-handler/src/handlers/gestures/reanimatedWrapper.tspackages/react-native-gesture-handler/src/v3/hooks/callbacks/lastUpdateEventMap.tspackages/react-native-gesture-handler/src/v3/hooks/callbacks/lastUpdateEventMap.web.tspackages/react-native-gesture-handler/src/v3/hooks/callbacks/useReanimatedEventHandler.ts
🚧 Files skipped from review as they are similar to previous changes (2)
- packages/react-native-gesture-handler/src/v3/hooks/callbacks/useReanimatedEventHandler.ts
- packages/react-native-gesture-handler/src/handlers/gestures/reanimatedWrapper.ts
Description
Replaces
makeMutablewithcreateShareable.Test plan
🚀