React native 反应本机选择器确认按钮

React native 反应本机选择器确认按钮,react-native,React Native,我在这里提问是因为我已经研究了这个问题,似乎找不到解决办法。我使用的是React本机选取器,但默认情况下,此选取器在右上角没有“确认”按钮,用户在选择项目时可以按下。我对本地和移动开发非常陌生,所以如果这是一个简单的问题,我很抱歉,但我很困惑。有人知道实现此按钮的解决方案吗 import React, { Component } from 'react'; import { Picker, View, Text } from 'react-native'; class ProposalPick

我在这里提问是因为我已经研究了这个问题,似乎找不到解决办法。我使用的是React本机选取器,但默认情况下,此选取器在右上角没有“确认”按钮,用户在选择项目时可以按下。我对本地和移动开发非常陌生,所以如果这是一个简单的问题,我很抱歉,但我很困惑。有人知道实现此按钮的解决方案吗

import React, { Component } from 'react';
import { Picker, View, Text } from 'react-native';

class ProposalPicker extends Component {
    state={proposal: ''}
    updateProposal = (proposal) => {
        this.setState({ proposal: proposal })
    }
    render() {
        return (

                <Picker selectedValue = {this.state.proposal} 
                        onValueChange = {this.updateProposal}
                        itemStyle={{ backgroundColor: 'grey' }}

                >

                    <Picker.Item label = "Test" value = "TestValue" />
                    <Picker.Item label = "Test" value = "TestValue" />
                    <Picker.Item label = "Test" value = "TestValue" />
                    <Picker.Item label = "Test" value = "TestValue" />
                    <Picker.Item label = "Test" value = "TestValue" />
                    <Picker.Item label = "Test" value = "TestValue" />
                    <Picker.Item label = "Test" value = "TestValue" />
                    <Picker.Item label = "Test" value = "TestValue" />

                </Picker>
                //<Text>{this.state.proposal}</Text>

        )
    }
}

const styles = {
    proposalPickerStyle: {
        backgroundColor: 'lightgrey'
    }
}

export default ProposalPicker;
import React,{Component}来自'React';
从“react native”导入{Picker,View,Text};
类ProposalPicker扩展组件{
状态={建议:'}
updateProposal=(提案)=>{
this.setState({proposal:proposal})
}
render(){
返回(
//{this.state.proposal}
)
}
}
常量样式={
建议投标书样式:{
背景颜色:“浅灰色”
}
}
导出默认提议器;
添加新功能

handleConfirmClick(){
 //perform confirm action
}
然后在选择器下方添加一个新按钮

<button onClick={this.handleConfirmClick.bind(this)} >Confirm</button>
编辑2除非您希望此组件有自己的生命周期,否则最好将
选择器
、确认
按钮
和您的
onChangeHandler
放在父组件中,而不是添加新功能

handleConfirmClick(){
 //perform confirm action
}
然后在选择器下方添加一个新按钮

<button onClick={this.handleConfirmClick.bind(this)} >Confirm</button>
编辑2除非您希望此组件有自己的生命周期,否则最好将
选择器
、确认
按钮
和您的
onChangeHandler
放在父组件中