【问题标题】:React Native TextInput shrinks when selected, how can I stop it?选择时 React Native TextInput 缩小,我该如何停止它?
【发布时间】:2021-05-25 10:49:23
【问题描述】:

我是 React Native 的新手,我目前正在开发一个应用程序,在登录屏幕上,当我选择电子邮件或密码字段时,键盘出现并且整个屏幕正在缩小,我该如何防止这种情况发生?

在选择 TextInput 之前:

选择TextInput后:

这里是渲染函数和样式:

render() {
        return (

            <View style={styles.container}>

                <View style={styles.image} >

                    <LoginBubble />

                </View>

                <Text style={styles.appName}>App Name</Text>

                <Text style={styles.lipsum} >Lorem ipsum dolor sit amet, consectetur adipiscing elit.</Text>

                <View style={styles.input}>


                    <View style={styles.icon}>
                        <EmailIcon />
                    </View>


                    <TextInput
                        style={styles.emailInput}
                        placeholder="Email"
                        onChangeText={(text) => this.setState({ email: text })}
                        onSubmitEditing={Keyboard.dismiss}
                        autoCapitalize="none"
                        placeholderTextColor="#29374E"
                    />

                </View>

                <View style={styles.input}>

                    <View style={styles.icon}>
                        <PasswordIcon />
                    </View>

                    <TextInput
                        style={styles.passwordInput}
                        placeholder="Password"
                        secureTextEntry={true}
                        onChangeText={(text) => this.setState({ password: text })}
                        onSubmitEditing={Keyboard.dismiss}
                        autoCapitalize="none"
                        placeholderTextColor="#29374E"
                    />

                </View>

                <TouchableOpacity
                    style={styles.loginButton}
                >

                    <Text style={styles.loginButtonText} >Login</Text>

                </TouchableOpacity>

                <TouchableOpacity>

                    <Text style={styles.help}>Need help?</Text>

                </TouchableOpacity>

            </View>
        );
    }
}

const styles = StyleSheet.create(
    {
        container:
        {
            justifyContent: "center",
            flex: 1,
            backgroundColor: "white",
            marginTop: getStatusBarHeight()
        },
        image:
        {
            justifyContent: "center",
            alignItems: "center",
            marginTop: "-5%"
        },
        appName:
        {
            fontSize: 36,
            color: "#29374E",
            alignSelf: "center",
            fontWeight: "700",
            marginTop: "2%",
            //fontFamily: "Inter-SemiBoldItalic"
        },
        lipsum:
        {
            color: "#AABCD0",
            alignSelf: "center",
            width: "60%",
            marginBottom: "7%",
            textAlign: "center"
        },
        input:
        {
            borderColor: "#DEE8F3",
            borderWidth: 1,
            marginTop: 10,
            fontSize: 16,
            borderRadius: 32,
            height: "8%",
            marginHorizontal: 16,
            //fontFamily: "Arboria-Book",
            flexDirection: "row",
            justifyContent: "flex-start",
            alignItems: "center",
        },
        icon:
        {
            padding: 16
        },
        emailInput:
        {
            //marginLeft: "5%",
            width: "86%",
            fontSize: 16,
        },
        passwordInput:
        {
            marginLeft: "1%",
            width: "86%",
            fontSize: 16
        },
        loginButton:
        {
            backgroundColor: "#2276D8",
            borderRadius: 41,
            height: "8%",
            justifyContent: "center",
            marginTop: 10,
            marginHorizontal: 16
        },
        loginButtonText:
        {
            fontSize: 18,
            color: "white",
            alignSelf: "center",
        },
        help:
        {
            fontSize: 16,
            color: "#2276D8",
            alignSelf: 'center',
            marginTop: "10%"
        }
    }
);

export default LoginScreen;

【问题讨论】:

  • 请做最小可重现代码。

标签: reactjs react-native keyboard textinput shrink


【解决方案1】:
【解决方案2】:

在 android\app\src\main\AndroidManifest.xml 中

chnage -> android:windowSoftInputMode="adjustResize" 到 "adjustPan"

【讨论】:

    猜你喜欢
    • 2021-11-01
    • 2021-05-29
    • 1970-01-01
    • 2018-11-17
    • 1970-01-01
    • 2023-03-16
    • 2023-01-19
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多