Skip to content

refactor: don't use private reanimated API#1209

Merged
kirillzyusko merged 4 commits intomainfrom
feat/do-not-use-private-reanimated-api
Nov 21, 2025
Merged

refactor: don't use private reanimated API#1209
kirillzyusko merged 4 commits intomainfrom
feat/do-not-use-private-reanimated-api

Conversation

@kirillzyusko
Copy link
Copy Markdown
Owner

@kirillzyusko kirillzyusko commented Nov 19, 2025

📜 Description

Added a support for Expo snack.

💡 Motivation and Context

In this PR I re-worked the approach how I attach worklet handlers to KeyboardControllerView. Prior to #538 we simply broadcasted events for stored worklet handlers inside a global object. But this approach had downsides, such as slow flow of execution, so I re-worked it in #538 and instantly introduced issues like: #551 and #555

While I managed somehow to fix it, the new approach wasn't ideal:

  • we still used internal API that was relying on FS structure;
  • this is highly internal API that can be changed anytime and will not assure that lib works across all reanimated versions;
  • in Expo Go I see strange errors, but I tend to think they are derived from the same issue - my code can not lookup a module and we get a crash 🤷‍♂️

I kept the idea to re-work this piece of code and in this PR I'm doing it. I can not use public API only, but the new approach is actually smarter. The new idea is that we still use registerEvent

Should fix errors like:

image

Actually correct solution for: #555

In future I'll be able to add interactive code samples into documentation, so people can run demos straight in the browser.

📢 Changelog

JS

  • remove event-handler files;
  • remove event-mapping file;
  • use useEvent/useHandler hook for useKeyboardHandler and useFocusedInputHandler hooks;
  • use registerForEvents/unregisterFromEvents methods from WorkletEventHandler (instance returned by useEvent hook);

I also had to use never types, or cast to my types using as unknown as, since I anyway access reanimated internals. But it's safer to use internals in this way, than before 🤞

🤔 How Has This Been Tested?

Tested manually on:

  • iPhone 16 Pro (new arch, iOS 26.0);
  • e2e tests;

📸 Screenshots (if appropriate):

image

📝 Checklist

  • CI successfully passed
  • I added new mocks and corresponding unit-tests if library API was changed

@kirillzyusko kirillzyusko self-assigned this Nov 19, 2025
@kirillzyusko kirillzyusko added the refactor You changed the code but it didn't affect functionality label Nov 19, 2025
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Nov 19, 2025

📊 Package size report

Current size Target Size Difference
224205 bytes 225067 bytes -862 bytes 📉

@kirillzyusko kirillzyusko force-pushed the feat/do-not-use-private-reanimated-api branch from 2650061 to f419fb5 Compare November 19, 2025 16:30
@kirillzyusko kirillzyusko marked this pull request as ready for review November 21, 2025 09:51
@kirillzyusko kirillzyusko merged commit 29ad9e8 into main Nov 21, 2025
14 checks passed
@kirillzyusko kirillzyusko deleted the feat/do-not-use-private-reanimated-api branch November 21, 2025 10:26
kirillzyusko added a commit that referenced this pull request Nov 21, 2025
## 📜 Description

Remove a note that library is not compatible with Expo Go.

## 💡 Motivation and Context

Technically support has landed for `1.17.5` in
expo/expo#37942 and starting from SDK 54 Expo Go
officially supports `1.18.5`.

However in Expo snacks there was a crash. I fixed it here:
#1209
and these changes will be included in `1.20.0`. So I decided to update
documentation page in order not to mislead developers.

Starting from version `1.20.x` this package will be fully supported by
Expo and I'm planning to use snacks and make documentation even more
interactive 😎

## 📢 Changelog

<!-- High level overview of important changes -->
<!-- For example: fixed status bar manipulation; added new types
declarations; -->
<!-- If your changes don't affect one of platform/language below - then
remove this platform/language -->

### Docs

- remove a message that lib is not compatible with Expo Go.

## 🤔 How Has This Been Tested?

Tested via preview.

## 📸 Screenshots (if appropriate):

<img width="1000" height="529" alt="image"
src="https://github.com/user-attachments/assets/912cc4aa-07ab-45cf-9a59-97c3f41b965f"
/>

## 📝 Checklist

- [x] CI successfully passed
- [x] I added new mocks and corresponding unit-tests if library API was
changed
kirillzyusko added a commit that referenced this pull request Dec 3, 2025
## 📜 Description

Fixed `The final argument passed to %s changed size between renders. The
order and size of this array must remain constant.` warning.

## 💡 Motivation and Context

This warning happens inside `useSmoothKeyboardHandler` and started to
happen after
#1209
The main difference from these changes is that we started to use
`useHandler`/`useEvent` hooks, while in the past we simply used direct
worklet registration.

Turns out `useAnimatedReaction` modifies array of dependencies:

```tsx
if (dependencies === undefined) {
    dependencies = [
      ...Object.values(prepare.__closure ?? {}),
      ...Object.values(react.__closure ?? {}),
      prepare.__workletHash,
      react.__workletHash,
    ];
  } else {
    dependencies.push(prepare.__workletHash, react.__workletHash);
  }
```

Then `useHandler` (used in `useKeyboardHandler`) uses
`buildDependencies` which also modifies the array of dependencies:

```ts
dependencies.push(buildWorkletsHash(handlersList));
```

So if we use deps like:

```ts
const useMyCustomHook = (deps) => {
  useAnimatedReaction(() => {}, deps);
  
  useKeyboardHandler({}, deps);
}
```

Then we'll get this warning because we mutate deps two times.

To fix this issue I decided to make a shallow copy of `deps` for
`useAnimatedReaction` hook. It fixes the problem 🤞

Closes
#1228

## 📢 Changelog

<!-- High level overview of important changes -->
<!-- For example: fixed status bar manipulation; added new types
declarations; -->
<!-- If your changes don't affect one of platform/language below - then
remove this platform/language -->

### JS

- create shallow array copy for `useAnimatedReaction` in
`useSmoothKeyboardHandler`;

## 🤔 How Has This Been Tested?

Tested manually on iPhone 16 Pro.

## 📸 Screenshots (if appropriate):

|Before|After|
|-------|-----|
|<video
src="https://github.com/user-attachments/assets/a82b9e6d-adb9-4530-9f2c-2b50ec954386">|<video
src="https://github.com/user-attachments/assets/e8fe2cac-bb8c-47eb-89ac-b8d34d01591f">|

## 📝 Checklist

- [x] CI successfully passed
- [x] I added new mocks and corresponding unit-tests if library API was
changed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

refactor You changed the code but it didn't affect functionality

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant