react-native-draggable-flatlist遇_isReanimatedSharedValue为null错误求助
以下是针对该报错的几种排查和解决方法:
1. 确认Reanimated 3.x的配置是否完整
Reanimated v3需要额外的babel配置,检查你的babel.config.js是否添加了对应的插件,且该插件必须放在数组最后:
module.exports = { presets: ['module:metro-react-native-babel-preset'], plugins: [ // 其他插件 'react-native-reanimated/plugin', // 必须放在最后 ], };
配置完成后,必须重启Metro服务器并清除缓存:
npx react-native start --reset-cache
2. 调整版本兼容
react-native-draggable-flatlist v4可能尚未完全适配Reanimated 3.0,可尝试降级Reanimated到2.x稳定版本:
npm install react-native-reanimated@2.14.4 # 或使用yarn yarn add react-native-reanimated@2.14.4
安装完成后同样需要重置Metro缓存。
3. 确保GestureHandlerRootView包裹根组件
将GestureHandlerRootView移至应用的根组件层级,而非仅在当前组件内使用。示例:
// App.tsx import { GestureHandlerRootView } from 'react-native-gesture-handler'; import DragAndDrop from './DragAndDrop'; export default function App() { return ( <GestureHandlerRootView style={{ flex: 1 }}> <DragAndDrop /> </GestureHandlerRootView> ); }
当前组件内的GestureHandlerRootView可以移除,避免重复包裹。
4. 检查data数组的有效性
确保mySteps数组中的每个item都包含有效的id和name字段,不存在null或undefined的元素,避免组件渲染时出现异常。
内容的提问来源于stack exchange,提问作者Christophe Salou
相关产品推荐
相关产品推荐

