键盘在React Native中使用Scrollview和KeyboardAvoidingView阻止文本输入 [英] Keyboard blocking textinput with Scrollview and KeyboardAvoidingView in react native

查看:1274
本文介绍了键盘在React Native中使用Scrollview和KeyboardAvoidingView阻止文本输入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用RN 0.55.4 + Expo

I am using RN 0.55.4 + Expo

我尝试对表单使用KeyboardAvoidingView,但是无论是否包含KeyboardAvoidingView,它都不会更改任何内容,但仍会阻止我的表单.我在用 tcomb形式

I tried to use KeyboardAvoidingView to my form but it doesnt change anything with or without KeyboardAvoidingView, its still blocking my form. I am using tcomb-form

这是我当前的代码

 return (
      <View style={styles.container}>

        <KeyboardAvoidingView>
        <ScrollView>

          <View>
            <Header/>

            <View style={styles.inputs}>
              <LoginForm
                formType={formType}
                form={this.props.auth.form}
                value={this.state.value}
                onChange={self.onChange.bind(self)}/>
              {passwordCheckbox}
            </View>

            <FormButton/>

            <View >
              <View style={styles.forgotContainer}>
                {leftMessage}
                {rightMessage}
              </View>
            </View>
          </View>

        </ScrollView>
        </KeyboardAvoidingView>

      </View>
    )

这是样式

var styles = StyleSheet.create({
  container: {
    flexDirection: 'column',
    flex: 1
  },
  inputs: {
    marginTop: 10,
    marginBottom: 10,
    marginLeft: 10,
    marginRight: 10
  },
  forgotContainer: {
    flexDirection: 'row',
    justifyContent: 'space-between',
    marginTop: 10,
    marginLeft: 10,
    marginRight: 10
  }
})

这是显示 我还尝试了 https://github.com/APSL/react-native -keyboard-aware-scroll-view 库,但结果仍然相同,键盘阻止了视图/窗体. 有人知道怎么了吗?

This is the display I also tried https://github.com/APSL/react-native-keyboard-aware-scroll-view library but still same result, keyboard is blocking the view / form. Anyone know whats wrong?

推荐答案

对于iOS,您应该将KeyboardAvoidingView的"behavior"参数设置为"padding":

For iOS you should set the "behavior" parameter of the KeyboardAvoidingView to "padding" :

<KeyboardAvoidingView behavior="padding">

请参阅反应本机文档:

注意:Android和iOS都与此道具交互不同. 如果完全不提供行为支持,Android可能会表现得更好,而 iOS相反​​.

Note: Android and iOS both interact with this prop differently. Android may behave better when given no behavior prop at all, whereas iOS is the opposite.

iOS和Android上的工作示例:

A working example on iOS and Android :

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

这篇关于键盘在React Native中使用Scrollview和KeyboardAvoidingView阻止文本输入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆