react-native - 如何避免键盘在本机反应中推动整个布局?
问题描述
我正在制作一个反应原生的应用程序。每当我打开键盘时,我的整个布局都会向上移动,找不到解决方案。我已经尝试过使用键盘避免视图、键盘滚动视图和将 softwareKeyboardLayoutMode 调整为“Pan”。如果我使用这些然后滚动不起作用。下面是我的代码
import React, { useState } from "react";
import { View, Text, Image, Alert, TouchableOpacity } from "react-native";
...//(irrelevant code removed)//...
return (
<View style={common.containerStyle}>
<Image
style={common.LogoImageStyle}
source={require("../../assets/splash.png")}
/>
<Text style={common.textHeadingStyle}>SIGN UP</Text>
<ScrollView>
<TextInputComponent
label="Full Name"
placeholderTextColor={colors.placeHolderColor}
onChangeText={(val) => fullNameTextChange(val)}
onEndEditing={(e) => handleValidUser(e.nativeEvent.text)}
/>
{data.isValidUser ? null : (
<Animatable.View animation="fadeInLeft" duration={500}>
<Text style={common.errorMsg}>User must be 4 characters long</Text>
</Animatable.View>
)}
<TextInputComponent
label="Email"
placeholder="email@address.com"
placeholderTextColor={colors.placeHolderColor}
onChangeText={(val) => emailTextChange(val)}
onEndEditing={(e) => handleValidEmail(e.nativeEvent.text)}
/>
{data.isValidEmail ? null : (
<Animatable.View animation="fadeInLeft" duration={500}>
<Text style={common.errorMsg}>Email must be 5 characters long</Text>
</Animatable.View>
)}
<TextInputComponent
label="Password"
placeholder="********"
placeholderTextColor={colors.placeHolderColor}
onChangeText={(val) => passwordTextChange(val)}
secureTextEntry={true}
onEndEditing={(e) => handleValidPassword(e.nativeEvent.text)}
/>
{data.isValidPassword ? null : (
<Animatable.View animation="fadeInLeft" duration={500}>
<Text style={common.errorMsg}>
Password must be 5 characters long
</Text>
</Animatable.View>
)}
<TextInputComponent
label="Mobile #"
placeholder="03001234567"
placeholderTextColor={colors.placeHolderColor}
onChangeText={(val) => mobileTextChange(val)}
onEndEditing={(e) => handleValidMobile(e.nativeEvent.text)}
keyboardType="numeric"
/>
{data.isValidMobile ? null : (
<Animatable.View animation="fadeInLeft" duration={500}>
<Text style={common.errorMsg}>
Mobile must be 5 characters long
</Text>
</Animatable.View>
)}
</ScrollView>
<ButtonComponent
label="SIGN UP"
onPress={() => {
signUpHandle(data.email, data.password, data.fullName, data.mobile);
}}
/>
<View style={common.createAccountViewStyle}>
<View style={common.flexRow}>
<Text style={LoginStyle.noAccountText}>Already have an account?</Text>
<TouchableOpacity
onPress={() => {
navigation.pop();
}}
>
<Text style={LoginStyle.createAccountStyle}>LOGIN</Text>
</TouchableOpacity>
</View>
</View>
</View>
);
};
export default SignUp;
屏幕截图登录屏幕:[打开键盘前的图像]:[打开键盘后的图像]
我希望登录按钮固定在底部。其他屏幕也有同样的问题。请指导。
解决方案
推荐阅读
- angular - 找不到名称'angular.module'
- c# - 如果服务以不同的用户身份运行,CompileAssemblyFromSource 会引发异常
- windows - 什么是图像库(在 windows PE 文件中)
- javascript - html美化json忽略换行符
- sql-server - 将现有 MSSQL 服务器数据库连接到 django 项目时出现问题。
- dart - 重置子部件的状态
- python - 返回具有多个实例的嵌套 JSON 项
- excel - .FindNext() 与 xlPrevious
- python - Python 是否提供对假设作为前提条件的支持?
- android - Gradle 构建失败 - Unity