javascript - react native 键盘避免使用 native 基础的 View

标签 javascript react-native

我在屏幕中使用 native 基础,我正在尝试添加,但它无法正常工作,因为键盘仍然隐藏文本输入

  render() {
    return (
      <Container>
          <Header style={styles.header}>
            <Left style={styles.left}>
              <TouchableOpacity
                style={styles.backArrow}
                onPress={() => this.props.navigation.navigate("Welcome")}
              >
                <FontAwesome
                  name={I18nManager.isRTL ? "angle-right" : "angle-left"}
                  size={30}
                  color="#6f6f6f"
                />
              </TouchableOpacity>
            </Left>
            <Body style={styles.body} />
            <Right style={styles.right} />
          </Header>
          <View style={styles.signuplogosec}>
            <Image source={Logo} style={styles.signuplogostyle} />
          </View>
          <KeyboardAvoidingView behavior="padding" enabled>
          <Form style={styles.form}>
          
            <Item rounded style={styles.inputStyle}>
              <Input
                //placeholderTextColor="#ffffff"
                textAlign={I18nManager.isRTL ? "right" : "left"}
                placeholder="First Name"
                onChangeText={(first_name) => { this.setState({ first_name }) }}
                style={styles.inputmain}
              />
            </Item>
            <Item rounded style={[styles.inputStyle,, { marginTop: 10 }]}>
              <Input
                //placeholderTextColor="#ffffff"
                textAlign={I18nManager.isRTL ? "right" : "left"}
                placeholder="Last Name"
                style={styles.inputmain}
                onChangeText={(last_name) => { this.setState({ last_name }) }}
              />
            </Item>
            <Item rounded style={[styles.inputStyle,, { marginTop: 10 }]}>
              <Input
                //placeholderTextColor="#ffffff"
                textAlign={I18nManager.isRTL ? "right" : "left"}
                placeholder="Email"
                style={styles.inputmain}
                autoCapitalize='none'
                onChangeText={(email) => { this.setState({ email }) }}
              />
            </Item>
            <Item rounded style={[styles.inputStyle, { marginTop: 10 }]}>
              <Input
                //placeholderTextColor="#ffffff"
                placeholder="Password"
                secureTextEntry={true}
                textAlign={I18nManager.isRTL ? "right" : "left"}
                style={styles.inputmain}
                onChangeText={(password) => { this.setState({ password }) }}
              />
            </Item>
            <Item rounded style={[styles.inputStyle, { marginTop: 10 }]}>
              <Input
                //placeholderTextColor="#ffffff"
                placeholder="Confirm Password"
                secureTextEntry={true}
                textAlign={I18nManager.isRTL ? "right" : "left"}
                style={styles.inputmain}
                onChangeText={(confirm_password) => { this.setState({ confirm_password }) }}
              />
            </Item>
            <TouchableOpacity
              info
              style={styles.signInbtn}
              onPress={this.signIn}
            >
              <Text autoCapitalize="words" style={styles.buttongetstarted}>
                Sign Up
              </Text>
            </TouchableOpacity>
          </Form>
          </KeyboardAvoidingView>
          <View style={styles.signupbottomView}>
            <TouchableOpacity
              style={styles.fbButton}
              onPress={() => alert("Facebook button Clicked")}
            >
              <View iconRight style={styles.fbview}>
                <Ionicons name="logo-linkedin" size={30} color="white" />
                <Text autoCapitalize="words" style={styles.fbButtonText}>
                  Sign Up with LinkedIn
                </Text>
              </View>
            </TouchableOpacity>
            <TouchableOpacity 
              style={styles.signupbottomText}
              onPress={()=>{this.props.navigation.navigate('SignIn')}}>
              <Text style={styles.bottomText01}>
                Do you have an account?{" "}
                <Text style={styles.bottomText02}>Sign In</Text>
              </Text>
            </TouchableOpacity>
          </View>
        
      </Container>
    );
  }
}
export default SignUpScreen;

我尝试在表单标签内添加不同的 View ,但它仍然不起作用,我尝试创建不同的表单标签但失败了。

我的要求很简单,我想在 Native 基础组件中使用 KeyboardAvoidingView,我在某些地方错了,但我不知道在哪里

最佳答案

只需使用with从react-native导入KeyboardAvoidingView 行为='位置'

import React, {Component} from 'react';
import {StyleSheet, TextInput, View, KeyboardAvoidingView} from 'react-native';

export default class App extends Component {
    render() {
        return (
            <View>
                <KeyboardAvoidingView behavior='position'>
                    <TextInput>Sample</TextInput>
                    <TextInput>Sample</TextInput>
                    <TextInput>Sample</TextInput>
                    <TextInput>Sample</TextInput>
                    <TextInput>Sample</TextInput>
                    <TextInput>Sample</TextInput>
                    <TextInput>Sample</TextInput>
                </KeyboardAvoidingView>
            </View>
        );
    }
}

const styles = StyleSheet.create({
    container: {
        flex: 1,
        backgroundColor: '#f5f5f5',
    }

关于javascript - react native 键盘避免使用 native 基础的 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52437361/

相关文章:

javascript - chop 没有宽度的省略号

javascript - href 在greatmokey 中不起作用

reactjs - 为 React Native TextInput 创建 ref 时的 TypeScript 问题

react-native - 错误 : Error: No views in hierarchy found matching: (with tag value: is "email" and view has effective visibility=VISIBLE)

android - 通过 adb tcpip 调试 React Native

javascript - 在谷歌地图上添加标记左键单击。试图修改一个例子

javascript - 监听 DOM 元素何时移动

asp.net - 将 ContentPlaceHolder 放在 &lt;script&gt; 标记中时出现问题

android - React Native Android 应用白屏无法启动

reactjs - 如何更改 react 导航中的后退按钮路线