Quantcast
Channel: Active questions tagged react-native+android - Stack Overflow
Viewing all articles
Browse latest Browse all 30345

Detect selecting current selectedValue with React-Native Picker

$
0
0

I'm using React-Native's Picker component. Say I have the following:

export class someComponent extends Component {
    constructor(props) {
        super(props);
        this.state = {
            someVal: 1
        };
    }

    onNewValueSelected = (newVal) => {
        Alert.alert('You selected the value: ' + newVal)
        this.setState({someVal: newVal});
    }

    render() {


        return (
            <View style={styles.container}>
                <Picker
                    selectedValue={this.state.someVal}
                    prompt="Select Some Value"
                    onValueChange={this.onNewValueSelected}
                    mode='dropdown'>
                    <Picker.Item label='one' value={1} />
                    <Picker.Item label='two' value={2} />
                    <Picker.Item label='three' value={3} />
                </Picker>
            </View>
        );
    }

}

How would I detect that the currently selected value is selected in the modal? Say when this component first mounts the user selects 1. How would i know that they selected 1? onValueChange does not fire when the selectedValue is selected (at least on Android). I also don't see any way of creating a workaround for this component since I don't know a way of detecting when the Picker's modal or dropdown is opened and dismissed.

Maybe I just need to build a custom button and modal to handle this? Any help is appreciated. Thanks!


Viewing all articles
Browse latest Browse all 30345

Trending Articles