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

@gorhom/bottom-sheet 聚焦输入框时不随键盘上移问题求助

@gorhom/bottom-sheet BottomSheetModal 键盘适配问题解决

问题描述

使用@gorhom/bottom-sheet的BottomSheetModal组件时,已配置keyboardBehavior='extend'、android_keyboardInputMode='adjustResize',且在AndroidManifest中设置android:windowSoftInputMode="adjustPan|adjustResize",但聚焦BottomSheetTextInput输入框时,底部弹窗并未随键盘上移。

问题表现:
底部弹窗未随键盘上移

相关代码:

...

const snapPoints = useMemo(() => ['25%', '25%', '60%'], []);
const {animatedHandleHeight, animatedContentHeight} = useBottomSheetDynamicSnapPoints(snapPoints);

<BottomSheetModal
  ref={bottomSheetModalRef}
  index={1}
  snapPoints={snapPoints}
  enableOverDrag={true}
  keyboardBehavior='extend'
  android_keyboardInputMode='adjustResize'
  handleHeight={animatedHandleHeight}
  contentHeight={animatedContentHeight}>
  <View style={[styles.contentContainer]}>
      <BottomSheetTextInput
        style={styles.input}
        onChangeText={val => setValue(val)}
        keyboardType="phone-pad"
      />
    ...
  </View>
</BottomSheetModal>
)

解决方案

  • 修改AndroidManifest的android:windowSoftInputMode为adjustResize,不要同时设置adjustPan和adjustResize,两者共存时部分设备会优先使用adjustPan,导致弹窗无法感知键盘高度变化。
  • 移除useBottomSheetDynamicSnapPoints,改用固定snapPoints测试。动态高度计算逻辑可能与键盘适配存在冲突,若必须使用动态高度,需确保contentHeight的计算完整包含输入框所在区域的高度。
  • 升级@gorhom/bottom-sheet到最新稳定版本,旧版本存在键盘适配相关bug。
  • 检查BottomSheetModal的父容器样式,避免设置固定高度、overflow:hidden等会阻断布局调整的属性。
  • 若BottomSheetTextInput嵌套在ScrollView中,确认ScrollView的keyboardShouldPersistTaps等属性设置正确,避免干扰弹窗的键盘响应逻辑。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.09 05:10:50