[native] Enable Flow types in Reanimated worklets
Summary:
When using Flow types in reanimated worklets it looks like the types are not stripped.
https://linear.app/comm/issue/ENG-623/investigate-why-reanimated-23-is-failing-to-strip-flow-types
We’re using @babel/preset-flow which stripes the flow types. However, presets are run after plugins (https://babeljs.io/docs/plugins#plugin-ordering). That means reanimated plugin is getting the code with types.
In reanimated plugin there is a code that strips typescript types: https://github.com/software-mansion/react-native-reanimated/blob/2.17.0/plugin.js#L361-L374 so it works with ts. However it doesn’t strip Flow types. So if I add @babel/preset-flow to the code I linked it fixes the issue.
To make it nicer I made it configurable so if anyone wants to add some other plugins or presets they can do so in reanimated plugin’s options. So now after the patch we can add @babel/preset-flow in reanimated plugin options.
I’m going to make a PR with this change to Reanimated’s repo later - it’s a simple change. Made a linear issue: https://linear.app/comm/issue/ENG-10007/make-a-pr-to-reanimated-repository-to-fix-flow-types-in-worklets
Also a note to teammebers: after merging this PR they’ll need to reinstall node modules and clear metro cache. Otherwise the app will crash.
Depends on D14112
Test Plan: Verify the app doesn't crash after adding flow types in a worklet.
Reviewers: ashoat, tomek
Reviewed By: ashoat
Differential Revision: https://phab.comm.dev/D14113