Javascript KeyboardAvoidgView在我的代码中不起作用-反应本机
在我的代码中,我捕获了用户的一些细节。有许多输入字段和下拉列表。 没有,一切正常,所有的值都在填充,能够改变值并获取所有数据。 但我正在实现“KeyboardAvoidingView”以避免键盘与我的屏幕重叠。 就像当我点击belwo时,输入字段键盘就来了,但它与字段重叠。虽然它应该自动向上移动。我看到了一些关于“键盘AvoidingView”的东西,我告诉了alos,但它不起作用。请告诉我哪里出了问题。我已经在这里粘贴了我的整个UI代码Javascript KeyboardAvoidgView在我的代码中不起作用-反应本机,javascript,reactjs,react-native,ecmascript-6,tpkeyboardavoiding,Javascript,Reactjs,React Native,Ecmascript 6,Tpkeyboardavoiding,在我的代码中,我捕获了用户的一些细节。有许多输入字段和下拉列表。 没有,一切正常,所有的值都在填充,能够改变值并获取所有数据。 但我正在实现“KeyboardAvoidingView”以避免键盘与我的屏幕重叠。 就像当我点击belwo时,输入字段键盘就来了,但它与字段重叠。虽然它应该自动向上移动。我看到了一些关于“键盘AvoidingView”的东西,我告诉了alos,但它不起作用。请告诉我哪里出了问题。我已经在这里粘贴了我的整个UI代码 import React, { Component }
import React, { Component } from 'react';
import { Item, Input } from 'native-base';
import { View, Dimensions, ScrollView,KeyboardAvoidingView } from 'react-native';
import _ from 'lodash';
import { RegularText, SmallText } from '../ui/text';
import { widthPercentageToDP as wp, heightPercentageToDP as hp } from 'react-native-responsive-screen';
import { CustomButton } from '../ui/buttons';
import parentStyle from '../../themes/parent.style';
import DatePicker from '../ui/datePicker';
import { getToday, formatDate, addSubtractDate, getDate } from '../../dateFormat';
import SelectField from '../ui/selectField';
import StagedHeader from '../ui/stagedHeader';
import Modal from "react-native-modal";
import LottieView from 'lottie-react-native';
const minDate = '01/01/1970';
const format = 'DD/MM/YYYY';
const currentDate = formatDate(addSubtractDate(getToday(), 'substract', 'year', 18));
const deviceHeight = Dimensions.get('window').height;
const deviceWidth = Dimensions.get('window').width;
class PersonalDetails extends Component {
constructor(props) {
super(props);
let category = [];
let subCategory = [];
let nationality = [];
let defaultNationality = 0;
let defaultCategory = 0;
let defaultSubCategory = 0;
props.categoryArray.map((cat, index) => {
const value = cat.code;
const label = cat.name;
category.push({ value, label });
if (cat.default === 'true') {
defaultCategory = index;
cat.subCategory.map((sub, index) => {
const value = sub.code;
const label = sub.name;
if (sub.default === 'true') {
defaultSubCategory = index;
}
subCategory.push({ value, label });
})
}
})
props.nationalityArray.map((nat, index) => {
const value = nat.code;
const label = nat.name;
nationality.push({ value, label });
});
this.state = {
dateOfBirth: currentDate,
firstName: props.firstName || '',
lastName: props.lastName || '',
customerCategoryOptions: category,
customerSubCategoryOptions: subCategory,
customerCategory: category[defaultCategory].value,
customerSubCategory: subCategory[defaultSubCategory].value,
uniqueIdNo: '',
nationalityOptions: nationality,
nationality: nationality[defaultNationality].value,
riskCategory: props.riskCategory
}
this.fetchRiskCategory(category[defaultCategory].value, subCategory[defaultSubCategory].value);
}
fetchRiskCategory = async (customerCategory, customerSubCategory) => {
await this.props.fetchRiskCategory(customerCategory, customerSubCategory);
this.setState({
riskCategory: this.props.riskCategory
})
}
nextStep = async () => {
const { firstName, lastName, dateOfBirth, customerCategory, customerSubCategory, uniqueIdNo, nationality, riskCategory } = this.state;
const dob = dateOfBirth.split('/');
const personalDetails = {
firstName: firstName,
lastName: lastName,
dateOfBirth: getDate(`${dob[2]}-${dob[1]}-${dob[0]}`),
customerCategory: customerCategory,
customerSubCategory: customerSubCategory,
uniqueIdNo: uniqueIdNo,
nationality: nationality,
riskCategory: riskCategory
};
this.props.nextStep(personalDetails, this);
};
onChangeText = async (text, identifier) => {
if (identifier === 'FN') {
this.setState({
firstName: text
})
} else if (identifier === 'LN') {
this.setState({
lastName: text
})
} else if (identifier === 'UIN') {
this.setState({
uniqueIdNo: text
})
}
}
onPickerChange = async (key, value, identifier) => {
let { categoryArray } = this.props;
let defaultSubCategory = 0;
let subCategory = [];
if (identifier === 'CAT') {
categoryArray.map((cat, index) => {
if (cat.code === value) {
cat.subCategory.map((sub, index) => {
const value = sub.code;
const label = sub.name;
if (sub.default === 'true') {
defaultSubCategory = index;
}
subCategory.push({ value, label });
})
}
})
this.setState({
customerSubCategoryOptions: subCategory,
customerSubCategory: subCategory[defaultSubCategory].value,
customerCategory: value
});
await this.fetchRiskCategory(value, subCategory[defaultSubCategory].value);
} else if (identifier === 'SCAT') {
this.setState({
customerSubCategory: value
});
await this.fetchRiskCategory(this.state.customerCategory, value);
} else if (identifier === 'NAT') {
this.setState({
nationality: value
});
}
}
onDateChange = async (value) => {
this.setState({
dateOfBirth: value
});
}
render() {
const { navigation, appliedTheme, appliedMode, isLoading } = this.props;
const { firstName, lastName, customerCategory, customerSubCategory, nationality, uniqueIdNo,
nationalityOptions, customerCategoryOptions, customerSubCategoryOptions, riskCategory } = this.state;
let signatureHeadingColor = parentStyle[appliedTheme] ? parentStyle[appliedTheme][appliedMode].signatureHeadingColor : null
if (navigation.length === 0) {
return (
<View>
<NoDataFound imageType='record' />
</View>
);
}
return (
<View style={{ backgroundColor: '#FFFFFF', height: '100%' }}>
<Modal isVisible={isLoading} coverScreen={true}>
<View style={{ height: deviceHeight, width: deviceWidth }}>
<LottieView source={require('../animations/login_authentication.json')} autoPlay loop />
</View>
</Modal>
<StagedHeader navigation={navigation} subtitle={'Personal Details'}
backgroundColor={'#F3F4F9'} subTitleColor={'#67809F'} backButtonColor={'#67809F'}
totalSteps={2} currentStep={1} stepsColor={signatureHeadingColor} />
<KeyboardAvoidingView>
<ScrollView showsVerticalScrollIndicator={false}>
<View style={{ paddingLeft: 15, paddingTop: 10 }}>
<RegularText text={'PERSONAL INFO'} textColor='#989898' fontWeight='bold' style={{ fontSize: hp('2%') }} />
</View>
<View style={{ padding: 15 }}>
<View style={{ marginTop: 15 }}>
<View style={{
flexDirection: 'row', backgroundColor: '#fff'
}}>
<SmallText textColor="#4A494A" text={`First Name`} />
</View>
<Item style={{ borderColor: '#00fff', borderBottomWidth: 0.6 }}>
<Input
value={firstName}
keyboardType='default'
onChangeText={(text) => this.onChangeText(text, 'FN')}
/>
</Item>
</View>
<View style={{ marginTop: 15 }}>
<View style={{
flexDirection: 'row', backgroundColor: '#fff'
}}>
<SmallText textColor="#4A494A" text={`Last Name`} />
</View>
<Item style={{ borderColor: '#00fff', borderBottomWidth: 0.6 }}>
<Input
value={lastName}
keyboardType='default'
onChangeText={(text) => this.onChangeText(text, 'LN')}
/>
</Item>
</View>
<View style={{ marginTop: 15 }}>
<SelectField
label="Customer Category"
options={customerCategoryOptions}
value={customerCategory}
onChange={(key, value) => this.onPickerChange(key, value, 'CAT')}
that={this}
setIcon={true}
textColor='#4A494A'
/>
</View>
<View style={{ width: '100%', height: '.1%', backgroundColor: 'black' }}></View>
<View style={{ marginTop: 15 }}>
<SelectField
label="Sub Category"
options={customerSubCategoryOptions}
value={customerSubCategory}
onChange={(key, value) => this.onPickerChange(key, value, 'SCAT')}
that={this}
setIcon={true}
textColor='#4A494A'
/>
</View>
<View style={{ width: '100%', height: '.1%', backgroundColor: 'black' }}></View>
{riskCategory !== '' && <View style={{ marginTop: 15 }}>
<View style={{
flexDirection: 'row', backgroundColor: '#fff'
}}>
<SmallText textColor="#4A494A" text={`Risk Category`} />
</View>
<Item style={{ borderColor: '#00fff', borderBottomWidth: 0.6 }}>
<Input editable={false}
value={riskCategory}
keyboardType='default'
/>
</Item>
</View>}
<View style={{ marginTop: 15 }}>
<View style={{
flexDirection: 'row', backgroundColor: '#fff'
}}>
<SmallText textColor="#4A494A" text={`Unique Identification Number`} />
</View>
<Item style={{ borderColor: '#00fff', borderBottomWidth: 0.6 }}>
<Input
value={uniqueIdNo}
onChangeText={(text) => this.onChangeText(text, 'UIN')}
/>
</Item>
</View>
<View style={{ marginTop: 15 }}>
<SelectField
label="Nationality"
options={nationalityOptions}
value={nationality}
node="Gender"
onChange={(key, value) => this.onPickerChange(key, value, 'NAT')}
that={this}
setIcon={true}
textColor='#4A494A'
/>
</View>
<View style={{ width: '100%', height: '.1%', backgroundColor: 'black' }}></View>
<View style={{ marginTop: 15,marginBottom:40 }}>
<View style={{
flexDirection: 'row', backgroundColor: '#fff'
}}>
<SmallText textColor="#4A494A" text={`Date of Birth`} />
</View>
<Item style={{ borderColor: '#00fff', borderBottomWidth: 0.6 }}>
<DatePicker
minDate={minDate}
maxDate={currentDate}
currentDate={this.state.dateOfBirth}
format={format}
width={deviceWidth}
onChange={(dateOfBirth) => this.onDateChange(dateOfBirth)}
marginLeft={0}
/>
</Item>
</View>
</View>
</ScrollView>
</KeyboardAvoidingView>
<View style={{ alignSelf: 'center', paddingTop: 20, position: 'absolute', bottom: 10 }}>
<CustomButton backgroundColor={parentStyle[appliedTheme] ? parentStyle[appliedTheme][appliedMode].primaryButtonColor : null}
width={deviceWidth - 30} label={'Proceed'} height={60}
disabled={!this.state.firstName || !this.state.lastName || !this.state.uniqueIdNo }
onPress={() => this.nextStep()} labelFontSize={hp('2.5%')}>
</CustomButton>
</View>
</View>
);
}
}
export default PersonalDetails;
import React,{Component}来自'React';
从“本机基”导入{Item,Input};
从“react native”导入{View,Dimensions,ScrollView,KeyboardAvoidingView};
从“lodash”进口;
从“../ui/text”导入{RegularText,SmallText};
从“react native responsive screen”导入{widthPercentageToDP作为wp,heightPercentageToDP作为hp};
从“../ui/buttons”导入{CustomButton};
从“../../themes/parent.style”导入parentStyle;
从“../ui/DatePicker”导入日期选择器;
从“../../dateFormat”导入{getToday,formatDate,addSubtractDate,getDate};
从“../ui/SelectField”导入SelectField;
从“../ui/StagedHeader”导入StagedHeader;
从“反应本机模态”导入模态;
从“lottie react native”导入LottieView;
const minDate='01/01/1970';
常量格式='DD/MM/YYYY';
const currentDate=formatDate(addSubtractDate(getToday(),'substract','year',18));
const deviceHeight=维度.get('window').height;
const deviceWidth=Dimensions.get('window').width;
类PersonalDetails扩展组件{
建造师(道具){
超级(道具);
设类别=[];
设子类别=[];
让国籍=[];
默认国籍=0;
设defaultCategory=0;
设defaultSubCategory=0;
props.categoryArray.map((类别,索引)=>{
常量值=类别代码;
常量标签=cat.name;
push({value,label});
如果(cat.default=='true'){
默认类别=索引;
类别子类别映射((子类别,索引)=>{
常量值=子代码;
常量标签=子名称;
如果(sub.default=='true'){
defaultSubCategory=索引;
}
push({value,label});
})
}
})
props.nationalityArray.map((nat,索引)=>{
常量值=nat.code;
常量标签=nat.name;
国籍.推送({value,label});
});
此.state={
出生日期:当前日期,
firstName:props.firstName | |“”,
lastName:props.lastName | |“”,
CustomerCategory选项:类别,
CustomerSubcategory选项:子类别,
customerCategory:类别[defaultCategory]。值,
customerSubCategory:子类别[defaultSubCategory]。值,
唯一编号:“”,
国籍选择:国籍,
国籍:国籍[默认国籍]。值,
riskCategory:props.riskCategory
}
this.fetchRiskCategory(类别[defaultCategory].value,子类别[defaultSubCategory].value);
}
fetchRiskCategory=async(customerCategory,customerSubCategory)=>{
等待这个.props.fetchRiskCategory(customerCategory,customerSubCategory);
这是我的国家({
风险类别:this.props.riskCategory
})
}
nextStep=async()=>{
const{firstName,lastName,dateof birth,customerCategory,customerSubCategory,uniqueIdNo,national,riskCategory}=this.state;
const dob=出生日期分割('/');
const personalDetails={
名字:名字,
lastName:lastName,
dateOfBirth:getDate(`${dob[2]}-${dob[1]}-${dob[0]}`),
customerCategory:customerCategory,
customerSubCategory:customerSubCategory,
uniqueIdNo:uniqueIdNo,
国籍:国籍,,
风险类别:风险类别
};
this.props.nextStep(personalDetails,this);
};
onChangeText=async(文本,标识符)=>{
如果(标识符=='FN'){
这是我的国家({
名字:text
})
}else if(标识符=='LN'){
这是我的国家({
姓氏:text
})
}else if(标识符=='UIN'){
这是我的国家({
唯一编号:文本
})
}
}
onPickerChange=async(键、值、标识符)=>{
设{categoryArray}=this.props;
设defaultSubCategory=0;
设子类别=[];
如果(标识符=='CAT'){
categoryArray.map((目录,索引)=>{
如果(类别代码===值){
类别子类别映射((子类别,索引)=>{
常量值=子代码;
常量标签=子名称;
如果(sub.default=='true'){
defaultSubCategory=索引;
}
push({value,label});
})
}
})
这是我的国家({
客户子类别选项:子类别
<KeyboardAvoidingView behavior={Platform.OS == 'ios' ? 'padding' : null} >
</KeyboardAvoidingView>
const keyboardVerticalOffset = Platform.OS === 'ios' ?hp('8%') : hp('8%');
retuen(
<KeyboardAvoidingView behavior={'position'} keyboardVerticalOffset={keyboardVerticalOffset} >
/////
</KeyboardAvoidingView>