Keyboard blocking textinput with Scrollview and KeyboardAvoidingView in react native

青春壹個敷衍的年華 提交于 2019-12-13 04:28:02

问题


I am using RN 0.55.4 + Expo

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

This is my current code

 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>
    )

This is the style

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
  }
})

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?


回答1:


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

<KeyboardAvoidingView behavior="padding">

Refering to react-native documentation :

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.

A working example on iOS and Android :

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



回答2:


It also happened to me... ScrollView and FlatList can work it out by setting a dynamic height depending on your data to FlatList. eg:

<ScrollView>
  <FlatList style={{height: dataArr.length * YourInputHeight}}
  ...
  />
</ScrollView>


来源:https://stackoverflow.com/questions/52253830/keyboard-blocking-textinput-with-scrollview-and-keyboardavoidingview-in-react-na

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!