Javascript 键盘“AvoidingView”;填充“;工作不正常

Javascript 键盘“AvoidingView”;填充“;工作不正常,javascript,node.js,react-native,Javascript,Node.js,React Native,我的键盘有问题AvoidingView我有3个文本输入,当我想在最后一个上写东西时,这个被我的键盘隐藏了 export default class App extends React.Component { render() { return ( <LinearGradient colors={['#72afd3', '#37ecba']} style={styles.container}> <KeyboardAvoidingView b

我的键盘有问题AvoidingView我有3个文本输入,当我想在最后一个上写东西时,这个被我的键盘隐藏了

export default class App extends React.Component {
  render() {
    return (
      <LinearGradient colors={['#72afd3', '#37ecba']} style={styles.container}>
        <KeyboardAvoidingView behavior='padding' enabled>
          <TextInput placeholder='Hello World'/>
          <View style={{height: 200}}/>
          <TextInput placeholder='Hello World'/>
          <View style={{height: 200}}/>
          <TextInput placeholder='Hello World'/>
        </KeyboardAvoidingView>
      </LinearGradient>
    );
  }
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    justifyContent: 'center',
    alignItems: 'center'
  }
})
导出默认类App扩展React.Component{
render(){
返回(
);
}
}
const styles=StyleSheet.create({
容器:{
弹性:1,
为内容辩护:“中心”,
对齐项目:“中心”
}
})
我正在使用

这可能会奏效:

import { KeyboardAwareScrollView } from 'react-native-keyboard-aware-scroll-view';

<KeyboardAwareScrollView enableOnAndroid extraScrollHeight={pixels[50]}>
   <LinearGradient colors={['#72afd3', '#37ecba']} style={styles.container}>
          <TextInput placeholder='Hello World'/>
          <View style={{height: 200}}/>
          <TextInput placeholder='Hello World'/>
          <View style={{height: 200}}/>
          <TextInput placeholder='Hello World'/>
    </LinearGradient>
</KeyboardAwareScrollView>
从“react native KeyboardAwareScrollView”导入{KeyboardAwareScrollView};

通常,在Android上,如果不提供行为道具,您所期望的结果会更好。而在iOS上,填充可能是正确的答案。见

我通常会这样写:

<KeyboardAvoidingView behavior={Platform.OS === "ios" ? "padding" : undefined}>
    // ...
</KeyboardAvoidingView>

// ...

使用
键盘垂直偏移量
,这样
文本输入就不会隐藏在键盘后面

<KeyboardAvoidingView
   style={{ flex: 1 }}
   behavior={(Platform.OS === 'ios') ? "padding" : null} enabled
   keyboardVerticalOffset={Platform.select({ios: 80, android: 500})}>

我用了@Emma的答案,但用
键盘垂直偏移量固定了偏移量。我用了一个以下的

<KeyboardAvoidingView
        style={styles.keyboardAvoidContainer}
        enabled
        behavior={"padding"} // you can change that by using Platform
        keyboardVerticalOffset={Platform.select({ ios: 60, android: 78 })}
      >


我将ios的垂直偏移量设为60,并进行了测试,因为它完全安装在几个模拟器上,其中包括
iPhoneX、iPhone8和iPhone6
。然后在Android Nexus Emulator中,它的值为78

你在安卓上看到这个问题了吗?是的,我用安卓手机来测试你是否在使用expo,这可能会有所帮助。我遇到了一个类似的问题,状态栏干扰了布局。我通过在app.json文件中指定状态栏设置修复了它。你可以在这里阅读如何做到这一点。我已经试过这个了,在这种情况下,它在安拉不起作用,可能你的内容总体上是相当高的高度。您可能需要使用scrollview解决方案。类似于Yossi使用
react native keyboard aware scroll view
或wix解决方案
react native keyboard aware scroll view
的回答。
<KeyboardAvoidingView
        style={styles.keyboardAvoidContainer}
        enabled
        behavior={"padding"} // you can change that by using Platform
        keyboardVerticalOffset={Platform.select({ ios: 60, android: 78 })}
      >