本机基址选择器无法正常工作Android-不会触发函数onValueChange
我正在为我的本机基址选择器无法正常工作Android-不会触发函数onValueChange,android,react-native,picker,native-base,Android,React Native,Picker,Native Base,我正在为我的react Native应用程序使用Native Base的Picker组件。在IOS上一切正常,而在安卓方面,我无法触发我在onValueChange上添加的功能 以前有没有人面对过这个问题 你是怎么修好的?我在这里呆了差不多一天 这是我的密码 <Picker style={{ width: 200, height: 40}} iosHeader="Branch"
react Native
应用程序使用Native Base
的Picker
组件。在IOS上一切正常,而在安卓方面,我无法触发我在onValueChange
上添加的功能
以前有没有人面对过这个问题
你是怎么修好的?我在这里呆了差不多一天
这是我的密码
<Picker style={{ width: 200, height: 40}}
iosHeader="Branch"
Header="Branch"
mode="dropdown"
textStyle={{color: 'white'}}
placeholder="Branch"
headerBackButtonText="Geri"
selectedValue={this.state.selectedBranch}
onValueChange={(value)=>this.onBranchSelected(value)}
>
{this.state.branches.map((branches, i)=>{
return(
<Picker.Item label={branches.address_line} value={branches.id} key={i}/>
);
}
)}
</Picker>
this.onBranchSelected(值)}
>
{this.state.branchs.map((branchs,i)=>{
返回(
);
}
)}
它不会在Android上调用BranchSelected上的函数
。这是选择器的已知问题。该问题正在尝试使用.map
。我自己也无法让map与Picker
一起工作。我唯一能找到的是一个名为react native smart picker
的npm
包,我可以使用.map
。这是有局限性的
仅供参考,我还尝试了其他引导框架,这是vanillareact native
的一个问题
这是链接。。
这是我的github报告。。。
这是我实现它的代码
<ScrollView>
<View style={{ flex: 1, marginTop: 20 }}>
{this.state.makes.length > 1 ?
<ScrollView>
<SmartPicker
expanded={this.state.expanded}
selectedValue={this.state.selectedMake}
label='Select Make'
onValueChange={this.handleChange.bind(this)}>
{
this.state.makes.map((ele) => {
return (<Picker.Item label={ele} value={ele}/>);
})
}
<Picker.Item label='Select Make' value='Toyota'/>
</SmartPicker>
<Button block onPress={() => this.props.vehicleMake(this.state.selectedMake)}>
<Text>Done</Text>
</Button>
</ScrollView> : <Spinner/>
}
</View>
</ScrollView>
{this.state.makes.length>1?
{
this.state.makes.map((ele)=>{
返回();
})
}
this.props.vehicleMake(this.state.selectedMake)}>
多恩
:
}
更新以显示我如何处理无可扩展按钮
<Content>
<Text>Vehicle Stats:</Text>
<Text>Year: {this.state.vehicleYear}</Text>
<Text>Make: {this.state.vehicleMake}</Text>
<Text>Model: {this.state.vehicleModel}</Text>
{this.state.vehicleYear === "" ? <VehicleYearPicker vehicleYear={this.yearPicked}/> : undefined}
{this.state.vehicleYear !== "" && this.state.vehicleMake === "" ?
<VehicleMakePicker pickedYear={this.state.vehicleYear} vehicleMake={this.makePicked}/> : undefined}
{this.state.vehicleModel === "" && this.state.vehicleMake !== "" ?
<VehicleModelPicker homeState={this.state} vehicleModel={this.modelPicked}/> : undefined}
</Content>
车辆统计:
年份:{this.state.vehicleYear}
Make:{this.state.vehicleMake}
模型:{this.state.vehicleModel}
{this.state.vehicleYear==“”?:未定义}
{this.state.vehicleYear!==“”&this.state.vehicleYear==“”?
:未定义}
{this.state.vehicleModel===”“&&this.state.vehicleMake!==”“?
:未定义}
我尝试了你的代码,效果很好
粘贴我的代码
import React, { Component } from "react";
import { Platform } from "react-native";
import { Container, Header, Title, Content, Button, Icon, Text, Right, Body, Left, Picker, Form } from "native-base";
export default class PickerExample extends Component {
constructor(props) {
super(props);
this.state = {
branches: [
{ address_line: 'address 1', id: 1 },
{ address_line: 'address 2', id: 2 },
{ address_line: 'address 3', id: 3 },
{ address_line: 'address 4', id: 4 },
{ address_line: 'address 5', id: 5 }],
selected1: 1
};
}
onBranchSelected(value) {
this.setState({
selectedBranch: value
});
}
render() {
return (
<Container>
<Header>
<Left>
<Button transparent>
<Icon name="arrow-back" />
</Button>
</Left>
<Body>
<Title>Picker</Title>
</Body>
<Right />
</Header>
<Content>
<Form>
<Picker
style={{ width: 200, height: 40 }}
iosHeader="Branch"
Header="Branch"
mode="dropdown"
textStyle={{ color: 'grey' }}
placeholder='Select branch'
headerBackButtonText='Geri'
selectedValue={this.state.selectedBranch}
onValueChange={(value) => this.onBranchSelected(value)}
>
{this.state.branches.map((branches, i) => {
return (
<Picker.Item label={branches.address_line} value={branches.id} key={i} />
);
}
)}
</Picker>
</Form>
</Content>
</Container>
);
}
}
谢谢你,伙计。在阅读了您的评论之后,我还实现了react native smart picker。但我想这部分也有一些问题。扩展道具不工作,我无法打开Android端的选择器。你是如何解决这些问题的?我实际上在github上打开了关于可扩展选择器的问题。。。这周我要试着把它修好。根据上面的代码,我的应用程序中的选择器适用于android。我所做的是,当用户单击“完成”按钮时,它会触发一个位于其父组件中的函数,该函数隐藏刚刚单击按钮的组件,并显示下一个组件。
"native-base": "2.3.5",
"react": "16.0.0",
"react-native": "0.50.0",