这是我的 babel 文件
我的代码:
import React, { useRef, useState } from 'react'
import { View, useWindowDimensions, Button } from 'react-native'
import Animated, { runOnUI } from 'react-native-reanimated';
export default function Login() {
const { width, height } = useWindowDimensions();
// const value = useSharedValue(0);
function someWorklet(greeting: any) {
'worklet';
console.log("Hey I'm running on the UI thread");
}
return (
<View style={{ flex: 1, justifyContent: 'flex-end', alignItems: 'center' }}>
<Button title="click me" onPress={() => runOnUI(someWorklet)('Howdy')} />
</View>
);
}
我安装的包是"react-native-reanimated": "^2.1.0"
我遵循了他们的安装过程:React Native Reanimated 安装指南。
错误是:
Reanimated 2创建worklet失败,可能是你忘记添加Reanimated的babel插件了?