【问题标题】:Avoid header being pushed by KeyboardAvoidingView避免标题被 KeyboardAvoidingView 推送
【发布时间】:2018-05-29 02:56:48
【问题描述】:

我在堆栈导航器中有一个容器组件,顶部是标题,一个包含消息的滚动视图和一个输入元素

当我聚焦输入时,整个窗口被推上去,同时隐藏了标题

如何避免这种行为?

这是我正在使用的组件:

class Chat extends Component {
  static navigationOptions = ({navigation}) => {
    return {
      headerTitle: (
        <Header
          user={navigation.getParam('chat').partecipants[0]}
          headerClick={() => navigation.getParam('openProfile')()}
        />
      )
    }
  }

.....

  render() {
    ...
    return (
  <KeyboardAvoidingView
      style={{flex: 1}}
      behavior={'padding'}
      >
      <ScrollView>
        {messages}
      </ScrollView>
      <Input sendMessage={(m) => this.props.sendMessage(chat, m)}/>
    </KeyboardAvoidingView>

    )
  }
}

【问题讨论】:

    标签: react-native keyboard


    【解决方案1】:

    当 StatusBar 设置为隐藏时,KeyboardAvoidingView 似乎存在一个错误 https://github.com/facebook/react-native/issues/12980

    删除隐藏标志它的行为正常

    【讨论】:

      【解决方案2】:

      在 androidmanifest.xml 中 改变 --- android:windowSoftInputMode="adjustResize" --- 至 --- android:windowSoftInputMode="adjustPan" ---

      【讨论】:

      • 我试过了,没用。它似乎与状态栏错误有关
      【解决方案3】:

      使用 KeyboardAwareScrollView 它允许在键盘上方指定 extraHeight 属性

      【讨论】:

        猜你喜欢
        • 2019-05-07
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-05-31
        • 1970-01-01
        • 2019-08-05
        • 2023-04-01
        • 2018-03-27
        相关资源
        最近更新 更多