javascript - react-native-reanimated 2:无法使用“worklet”关键字创建函数(未定义不是函数)
问题描述
我刚刚学习v2,但是在使用“worklet”关键字react-native-reanimated
创建函数时遇到了问题。
我react-native-reanimated
在一个 React Native裸项目上使用npx react-native init myApp
.
我已遵循所有react-native-reanimated
v2 安装说明,包括:
- 配置 babel.config.js
module.exports = {
presets: ['module:metro-react-native-babel-preset'],
plugins: [
'react-native-reanimated/plugin'
]
};
- 启用爱马仕,设置为true
- 配置
MainApplication.java
文件 - 清理构建
- 使用重置缓存
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
出现这样的错误:
如果你明白,请告诉我。谢谢 :)
解决方案
哦,我觉得自己像个愚蠢的人...
我只需要导入react-native-reanimated
并App.js
完成所有操作.. :)
import 'react-native-reanimated'
看起来 react-native-reanimated v2 文档没有提到将react-native-reanimated
on 导入到我们项目的顶部......
推荐阅读
- python - 在 numpy 中结合两个条件(按列)
- google-api - 如何将 GCP 中连接的打印机报告为在线打印机
- c# - c# SELECT with FOR JSON
- postgresql - 有没有办法在多个表中拆分数据?
- c# - 如何从 SQL Server 读取大文件?
- jquery - 需要在给定代码中平滑滚动单页网站
- mysql - Mysql Show Create Trigger - 触发器名称输出
- c# - 捆绑语言的 UWP APPXBundle 问题
- c# - IServiceCollection does not contain a defintion for AddHttpClient
- excel - 通过 vba 将特定的 excel 范围导出为 jpeg