温馨提示:本文翻译自stackoverflow.com,查看原文请点击:javascript - React Native KeyboardAvoidingView covers last text input
javascript react-native

javascript - React Native KeyboardAvoidingView涵盖了最后的文本输入

发布于 2020-03-27 15:40:43

我正在使用行为设置为padding的React Native的键盘回避视图(在Android上测试)。

我的屏幕上有多个TextInputs。当我单击最终的TextInput时,键盘将其覆盖。现在,由于从KeyboardAvoidingView中添加了填充,我可以向下滚动,但是将其自动聚焦是理想的。

<Content>
  <KeyboardAvoidingView behavior='padding'>
    <TextInput placeholder='Example 1' />
    <TextInput placeholder='Example 2' />
    <TextInput placeholder='Example 3' />
    <TextInput placeholder='Example 4' />
    <TextInput placeholder='Example 5' />
    <TextInput placeholder='Example 6' />
    <TextInput placeholder='Example 7' />
  </KeyboardAvoidingView>
</Content>

查看更多

查看更多

提问者
Molly Harper
被浏览
189
farmcommand2 2018-01-03 06:54

有一个名为keyboardVerticalOffset的道具,您可以将其传递给KeyboardAvoidingView,它将更改键盘经过textInput的移动量。我的代码示例:

const keyboardVerticalOffset = Platform.OS === 'ios' ? 40 : 0

    return (
      <KeyboardAvoidingView behavior='position' keyboardVerticalOffset={keyboardVerticalOffset}>
        <ListView .../>
      <KeyboardAvoidingView/>
    )