繁体   English   中英

react-native-reanimated 2:无法使用“worklet”关键字创建函数(未定义不是函数)

[英]react-native-reanimated 2: cannot make a function with 'worklet' keyword (undefined is not a function)

我只是在学习react-native-reanimated v2,但是在使用“worklet”关键字创建函数时遇到了问题。

我使用npx react-native init myApp在 React Native裸项目上安装了react-native-reanimated v2。
我遵循了所有react-native-reanimated v2 安装说明,包括:

  • 配置 babel.config.js

 module.exports = { presets: ['module:metro-react-native-babel-preset'], plugins: [ 'react-native-reanimated/plugin' ] };

  • 启用hermes,设置为true
  • 配置MainApplication.java文件
  • 清理构建
  • 使用yarn start --reset-cache重置yarn start --reset-cache

我尝试制作一个简单的“worklet”函数,如下所示:

 import React from 'react'; import { View, Button } from 'react-native'; const App = () => { const someWorklet = () => { 'worklet'; console.log('this run on UI thread'); }; return ( <View > <Button title="Press" onPress={() => { }} /> </View> ); }; export default App;

正如你在上面看到的,它只是App.js上的一个简单代码,但如果我把'worklet'关键字,它总是undefined is not a function错误:


错误信息



如果你明白,请告诉我。 谢谢 :)

呵呵,感觉自己是个傻子……
我只需要在App.js导入react-native-reanimated App.js可以了。:)

import 'react-native-reanimated'

看起来 react-native-reanimated v2 文档没有提到将react-native-reanimated导入到我们项目的顶部...

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM