You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Expo 51.0.39中Gorhom Bottom Sheet Modal无法显示的解决求助

解决方案

1. 移除冲突依赖

你同时安装了@gorhom/bottom-sheet和reanimated-bottom-sheet,这两个是功能重叠的库,会引发依赖冲突,直接卸载其中一个:

npm uninstall reanimated-bottom-sheet
# 或使用yarn
yarn remove reanimated-bottom-sheet

2. 修复Reanimated插件配置

@gorhom/bottom-sheet v5依赖Reanimated的babel插件,必须确保配置正确:

  • 修改babel.config.js,将Reanimated插件放在最后:
    module.exports = function(api) {
      api.cache(true);
      return {
        presets: ['babel-preset-expo'],
        plugins: [
          'react-native-reanimated/plugin',
        ],
      };
    };
    
  • 强制重启Metro服务(不重启插件不会生效):
    npx expo start --clear
    

3. 解决MapView层级遮挡问题

MapView的原生视图层级可能高于Bottom Sheet,导致弹窗被覆盖,给Bottom Sheet设置更高的层级:

<BottomSheet 
  snapPoints={snapPoints} 
  index={2}
  backdropComponent={backdrop}
  ref={bottomRef}
  onClose={()=>snapToIndex(0)}
  style={{ zIndex: 1000 }}
>
  {/* 内部导航器代码 */}
</BottomSheet>

同时检查MapView是否设置了过高的zIndex,如果有,调整为低于Bottom Sheet的值。

4. 验证Bottom Sheet基础配置

  • 确认snapPoints是有效的百分比/数值数组,比如:
    const snapPoints = useMemo(() => ['25%', '50%', '90%'], []);
    
  • 检查bottomRef和snapToIndex的绑定是否正确:
    const bottomRef = useRef(null);
    const snapToIndex = (index) => bottomRef.current?.snapToIndex(index);
    

5. 调整导航器布局

将Stack Navigator放在Bottom Sheet内部时,需要确保导航器视图不影响弹窗布局,给导航器添加flex样式:

<stack.Navigator 
  screenOptions={{ 
    headerShown: false,
    contentStyle: { flex: 1 }
  }} 
  initialRouteName="destination"
>
  {/* 屏幕组件 */}
</stack.Navigator>

6. 确认Expo版本兼容性

@gorhom/bottom-sheet v5要求Expo SDK 49及以上,你的Reanimated版本(3.10.1)对应Expo SDK 50+,请确保你的Expo SDK版本符合要求。

内容的提问来源于stack exchange,提问作者miracle godwin

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.13 10:23:20